mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
fix(uninstall): keep repos installed into a tracked repo's legacy group (#900)
Uninstalling the _team checkout matched every tracked entry grouped as "team", so a repo installed with --into team (team/_b) lost its record and audit acceptances too. Since #880 keeps declarations that have no checkout on this machine, reconcile could no longer restore that record, and the next push removed it on every machine; only trash restore of _team brought it back. #880 already excluded _-prefixed repo directories from the legacy match for unlink and declaration-only removal. Move that guard into inLegacyRepoGroup so checkout uninstall and its trash copy follow the same rule. Fixes #898
This commit is contained in:
@@ -314,7 +314,7 @@ func (s *MetadataStore) extract(relPath string, matches func(string, *MetadataEn
|
||||
for key, entry := range s.Entries {
|
||||
if entry != nil && matches(key, entry, relPath) {
|
||||
e := *entry
|
||||
if !inLegacyRepoGroup(entry, relPath) { // its Group is not its path
|
||||
if !inLegacyRepoGroup(key, entry, relPath) { // its Group is not its path
|
||||
key = KeyToRelPath(key, entry)
|
||||
}
|
||||
out.Entries[key] = &e
|
||||
@@ -468,12 +468,11 @@ func (s *MetadataStore) forgetName(rel string, matches func(string, *MetadataEnt
|
||||
return before != len(s.Entries)+len(s.AuditAccepted)+len(s.TargetOverrides)
|
||||
}
|
||||
|
||||
// unlinkedWith limits declaration/unlink legacy group cleanup to members, preserving
|
||||
// independent prefixed repo declarations such as team/_repo outside _team.
|
||||
// unlinkedWith reports whether forgetting a declaration or unlinking name
|
||||
// removes the entry at key.
|
||||
func unlinkedWith(key string, entry *MetadataEntry, name string) bool {
|
||||
full := filepath.ToSlash(KeyToRelPath(key, entry))
|
||||
return full == name || strings.HasPrefix(full, name+"/") ||
|
||||
(inLegacyRepoGroup(entry, name) && !utils.IsTrackedRepoDir(path.Base(full)))
|
||||
return full == name || strings.HasPrefix(full, name+"/") || inLegacyRepoGroup(key, entry, name)
|
||||
}
|
||||
|
||||
// removedWith reports whether uninstalling name removes the entry at key.
|
||||
@@ -481,15 +480,17 @@ func removedWith(key string, entry *MetadataEntry, name string) bool {
|
||||
full := KeyToRelPath(key, entry)
|
||||
return full == name ||
|
||||
strings.HasPrefix(key, name+"/") || strings.HasPrefix(full, name+"/") ||
|
||||
inLegacyRepoGroup(entry, name)
|
||||
inLegacyRepoGroup(key, entry, name)
|
||||
}
|
||||
|
||||
// inLegacyRepoGroup matches entries written when a top-level tracked repo
|
||||
// "_team" grouped its skills as "team". Untracked entries and nested repos are
|
||||
// left out: a plain group or a sibling repo may share that name.
|
||||
func inLegacyRepoGroup(entry *MetadataEntry, repo string) bool {
|
||||
// left out: a plain group or a sibling repo may share that name. So is a repo
|
||||
// installed into the group, such as team/_b, which is independent of _team.
|
||||
func inLegacyRepoGroup(key string, entry *MetadataEntry, repo string) bool {
|
||||
return entry != nil && entry.Tracked && entry.Group != "" &&
|
||||
!strings.Contains(repo, "/") && repo == "_"+entry.Group
|
||||
!strings.Contains(repo, "/") && repo == "_"+entry.Group &&
|
||||
!utils.IsTrackedRepoDir(path.Base(filepath.ToSlash(KeyToRelPath(key, entry))))
|
||||
}
|
||||
|
||||
// WriteMetaToStore writes a SkillMeta to the centralized .metadata.json store.
|
||||
|
||||
@@ -50,6 +50,16 @@ func TestRemoveByNames(t *testing.T) {
|
||||
entries: map[string]*MetadataEntry{"team/a": {Group: "team", Tracked: true}},
|
||||
remove: []string{"_team"},
|
||||
},
|
||||
{
|
||||
name: "repo installed into the legacy group stays",
|
||||
entries: map[string]*MetadataEntry{
|
||||
"_team": {Tracked: true},
|
||||
"team/a": {Group: "team", Tracked: true},
|
||||
"team/_b": {Group: "team", Tracked: true},
|
||||
},
|
||||
remove: []string{"_team"},
|
||||
kept: []string{"team/_b"},
|
||||
},
|
||||
{
|
||||
name: "untracked group that shares the repo's name stays",
|
||||
entries: map[string]*MetadataEntry{"team/a": {Group: "team"}},
|
||||
|
||||
Reference in New Issue
Block a user