Skip to content

Commit

Permalink
fix #486, 'av tidy' not respecting branches not off trunk (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
tulioz authored Dec 12, 2024
1 parent c3929be commit ac3fc63
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
17 changes: 14 additions & 3 deletions cmd/av/tidy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ does not delete Git branches.
}

var ss []string
if len(deleted) > 0 {

hasDeleted := false
for _, d := range deleted {
if d {
hasDeleted = true
break
}
}

if hasDeleted {
ss = append(
ss,
colors.SuccessStyle.Render(
Expand All @@ -49,8 +58,10 @@ does not delete Git branches.
ss = append(ss, "")
ss = append(ss, " Following branches no longer exist in the repository:")
ss = append(ss, "")
for name := range deleted {
ss = append(ss, " * "+name)
for name, d := range deleted {
if d {
ss = append(ss, " * "+name)
}
}
if len(orphaned) > 0 {
ss = append(ss, "")
Expand Down
8 changes: 6 additions & 2 deletions internal/actions/tidy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func TidyDB(repo *git.Repo, db meta.DB) (map[string]bool, map[string]bool, error
if _, err := repo.Git("show-ref", "refs/heads/"+name); err != nil {
// Ref doesn't exist. Should be removed.
deleted[name] = true
} else {
deleted[name] = false
}
}
orphaned := make(map[string]bool)
Expand All @@ -29,8 +31,10 @@ func TidyDB(repo *git.Repo, db meta.DB) (map[string]bool, map[string]bool, error
}
}

for name := range deleted {
tx.DeleteBranch(name)
for name, d := range deleted {
if d {
tx.DeleteBranch(name)
}
}
for name := range orphaned {
tx.DeleteBranch(name)
Expand Down

0 comments on commit ac3fc63

Please sign in to comment.