Skip to content

Commit

Permalink
Do not display the reason when the reason for deletion is clear (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
seachicken authored Jun 5, 2024
1 parent b067d9e commit dac8357
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func loadBranches(ctx context.Context, remote shared.Remote, defaultBranchName s
var branches []shared.Branch
if names, err := connection.GetBranchNames(ctx); err == nil {
branches = ToBranch(SplitLines(names))
branches = applyDefault(branches, defaultBranchName)
mergedNames, err := connection.GetMergedBranchNames(ctx, remote.Name, defaultBranchName)
if err != nil {
return nil, err
Expand Down Expand Up @@ -183,6 +184,17 @@ func extractMergedBranchNames(mergedNames []string) []string {
return result
}

func applyDefault(branches []shared.Branch, defaultBranchName string) []shared.Branch {
results := []shared.Branch{}
for _, branch := range branches {
if branch.Name == defaultBranchName {
branch.IsDefault = true
}
results = append(results, branch)
}
return results
}

func applyMerged(branches []shared.Branch, mergedNames []string) []shared.Branch {
results := []shared.Branch{}
for _, branch := range branches {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func printBranches(branches []shared.Branch) {
if branch.IsProtected {
reason = "protected"
}
if branch.HasTrackedChanges {
if !branch.IsDefault && len(branch.PullRequests) > 0 && branch.HasTrackedChanges {
reason = "uncommitted changes"
}
if reason == "" {
Expand Down
1 change: 1 addition & 0 deletions shared/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type (
Branch struct {
Head bool
Name string
IsDefault bool
IsMerged bool
IsProtected bool
HasTrackedChanges bool
Expand Down

0 comments on commit dac8357

Please sign in to comment.