feat: look for repos in the usual folders, not just ~/git (#57)
Without roots in the config, repos are found under whichever of ~/git, ~/repo, ~/repos, ~/projects, ~/code, ~/source and ~/src exist. Missing ones cost a stat each. A root that's a symlink to another is scanned once, and a repo under two roots keeps the first one's name. Reviewed-on: #57 Co-authored-by: Karl-Einar Bergstrøm <karl-einarb@outlook.com>
This commit was merged in pull request #57.
This commit is contained in:
1 parent
87141cb53b
commit
47ef86293d
5 files changed
+48
-11
No files matched your search
@@ -336,6 +336,30 @@ func TestRoots(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRootsDeduped(t *testing.T) {
|
||||
root, _ := filepath.EvalSymlinks(t.TempDir())
|
||||
os.Rename(gitRepo(t, map[string]string{"secrets/a.yaml": sopsYAML}), filepath.Join(root, "infra"))
|
||||
os.MkdirAll(filepath.Join(root, "acme"), 0o755)
|
||||
os.Rename(gitRepo(t, map[string]string{"prod.env": sopsEnv}), filepath.Join(root, "acme", "billing"))
|
||||
|
||||
// ~/src → ~/git, and a root reaching one repo at another depth.
|
||||
links := t.TempDir()
|
||||
alias := filepath.Join(links, "src")
|
||||
os.Symlink(root, alias)
|
||||
missing := filepath.Join(links, "nope")
|
||||
acme := filepath.Join(root, "acme")
|
||||
|
||||
srcs, err := New(Settings{Dir: links, Roots: []string{missing, root, alias, acme}}).Sources(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := names(srcs, func(s provider.Source) string { return s.Name })
|
||||
slices.Sort(got)
|
||||
if !slices.Equal(got, []string{"acme/billing", "infra"}) {
|
||||
t.Errorf("repos: %v, want each once, named from the first root", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStarredReposAlongside(t *testing.T) {
|
||||
here := gitRepo(t, map[string]string{"secrets/a.yaml": sopsYAML})
|
||||
starred := gitRepo(t, map[string]string{"prod.env": sopsEnv})
|
||||
|
||||
Reference in new issue
Block a user