mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
A repo installed with `--track --into org` lives at `org/_team`. Only POST /api/update accepted `org/team`; the dashboard stream and `update -p` prefixed the whole name (`_org/team`), and global `update` compared the full name with the basename, so each reported not found. Move the candidate rule (the name as typed, then `_` added to the last segment, never leaving the source root) into install.FindTrackedCheckout and the basename match into install.MatchTrackedRepos, and use them from the single update, the stream, project and global CLI update. A shorthand resolves to its own `org/_team`, never to a top-level `_team`; plain names and full paths keep their behavior.
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package install
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func fakeTrackedRepo(t *testing.T, root, rel string) {
|
|
t.Helper()
|
|
if err := os.MkdirAll(filepath.Join(root, filepath.FromSlash(rel), ".git"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestResolveTrackedRepo(t *testing.T) {
|
|
root := t.TempDir()
|
|
fakeTrackedRepo(t, root, "_team")
|
|
fakeTrackedRepo(t, root, "org/_team")
|
|
fakeTrackedRepo(t, root, "org/_solo")
|
|
fakeTrackedRepo(t, root, "a/_dup")
|
|
fakeTrackedRepo(t, root, "b/_dup")
|
|
outside := filepath.Join(filepath.Dir(root), filepath.Base(root)+"-outside", "_x")
|
|
if err := os.MkdirAll(filepath.Join(outside, ".git"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cases := []struct{ input, want string }{
|
|
{"team", "_team"},
|
|
{"_team", "_team"},
|
|
{"org/team", "org/_team"},
|
|
{"org/_team", "org/_team"},
|
|
{"solo", "org/_solo"},
|
|
{"team/", "_team"},
|
|
{"org/team/", "org/_team"},
|
|
{"./org/_team", "org/_team"},
|
|
{"../" + filepath.Base(root) + "-outside/x", ""},
|
|
{"ghost", ""},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.input, func(t *testing.T) {
|
|
got, path, err := ResolveTrackedRepo(root, c.input)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got != c.want {
|
|
t.Errorf("name = %q, want %q", got, c.want)
|
|
}
|
|
if wantPath := filepath.Join(root, filepath.FromSlash(c.want)); c.want != "" && path != wantPath {
|
|
t.Errorf("path = %q, want %q", path, wantPath)
|
|
}
|
|
})
|
|
}
|
|
|
|
if _, _, err := ResolveTrackedRepo(root, "dup"); err == nil {
|
|
t.Error("expected an ambiguity error for dup")
|
|
}
|
|
}
|