diff --git a/internal/config/reconcile_core.go b/internal/config/reconcile_core.go index 644e305f7..e02e01edd 100644 --- a/internal/config/reconcile_core.go +++ b/internal/config/reconcile_core.go @@ -60,7 +60,10 @@ func reconcileSkillsWalk(sourcePath string, walk sourcewalk.Options, store *inst var source string tracked := install.IsTrackedCheckout(path) - existing := store.GetByPath(fullPath) + existing := store.Get(fullPath) + if !tracked { + existing = store.GetByPath(fullPath) + } if existing != nil && existing.Source != "" { source = existing.Source } else if tracked { diff --git a/internal/config/reconcile_test.go b/internal/config/reconcile_test.go index b5beb7588..e3aa94330 100644 --- a/internal/config/reconcile_test.go +++ b/internal/config/reconcile_test.go @@ -3,6 +3,7 @@ package config import ( "os" "path/filepath" + "reflect" "testing" "skillshare/internal/install" @@ -11,6 +12,41 @@ import ( "gopkg.in/yaml.v3" ) +func TestReconcileGlobalSkills_NestedTrackedRepoWithoutEntry(t *testing.T) { + root := t.TempDir() + sourceDir := filepath.Join(root, "skills") + t.Setenv("SKILLSHARE_CONFIG", filepath.Join(root, "config.yaml")) + remotes := map[string]string{} + for _, name := range []string{"_team", "org/_team"} { + repoRoot := filepath.Join(root, filepath.FromSlash(name)) + if err := os.MkdirAll(repoRoot, 0755); err != nil { + t.Fatal(err) + } + remote := testutil.SetupBareRemoteRepo(t, repoRoot) + testutil.SeedRemoteBranch(t, repoRoot, remote, "main", map[string]string{"README.md": name}) + testutil.RunGit(t, "", "clone", remote, filepath.Join(sourceDir, filepath.FromSlash(name))) + remotes[name] = remote + } + + top := install.MetadataEntry{Source: remotes["_team"], Tracked: true, Branch: "main", FileHashes: map[string]string{"README.md": "unchanged"}} + store := install.NewMetadataStore() + store.Set("_team", &top) + wantTop := top + cfg := &Config{Source: sourceDir} + for pass := 1; pass <= 2; pass++ { + if err := ReconcileGlobalSkills(cfg, store); err != nil { + t.Fatal(err) + } + store = install.LoadMetadataOrNew(sourceDir) + if got := store.Get("_team"); !reflect.DeepEqual(got, &wantTop) { + t.Errorf("pass %d: top-level entry = %+v, want %+v", pass, got, wantTop) + } + if got := store.Get("org/_team"); got == nil || got.Source != remotes["org/_team"] || !got.Tracked || got.Group != "org" || got.Branch != "main" { + t.Errorf("pass %d: nested entry = %+v, want source %q, tracked, group org, branch main", pass, got, remotes["org/_team"]) + } + } +} + func TestReconcileGlobalSkills_AddsNewSkill(t *testing.T) { root := t.TempDir() sourceDir := filepath.Join(root, "skills")