@@ -11,9 +11,10 @@ import (
1111)
1212
1313var cleanupCmd = & cobra.Command {
14- Use : "cleanup" ,
15- Short : "Delete orphaned branches" ,
16- Long : `Delete branches that don't have an associated workspace (orphaned branches).` ,
14+ Use : "cleanup" ,
15+ Short : "Delete orphaned branches" ,
16+ Long : `Delete branches that don't have an associated workspace (orphaned branches).` ,
17+ Example : ` workspace branch cleanup` ,
1718 Run : func (_ * cobra.Command , _ []string ) {
1819 cleanupBranches ()
1920 },
@@ -28,25 +29,29 @@ func cleanupBranches() {
2829
2930 plan , err := svc .PlanCleanup ()
3031 if err != nil {
31- commands .PrintError ( fmt . Sprintf ( "Failed to plan cleanup: %v" , err ) )
32+ commands .PrintErrorf ( "Failed to plan cleanup: %v" , err )
3233 return
3334 }
3435
3536 if len (plan .OrphanedBranches ) == 0 {
3637 if plan .SkippedIgnored > 0 {
37- commands .PrintSuccess ( fmt . Sprintf ( "No orphaned branches found! (%d ignored branches skipped)" , plan .SkippedIgnored ) )
38+ commands .PrintSuccessf ( "No orphaned branches found! (%d ignored branches skipped)" , plan .SkippedIgnored )
3839 } else {
3940 commands .PrintSuccess ("No orphaned branches found!" )
4041 }
4142 return
4243 }
4344
44- commands .PrintWarning ( fmt . Sprintf ( "Found %d orphaned branch(es):" , len (plan .OrphanedBranches ) ))
45+ commands .PrintWarningf ( "Found %d orphaned branch(es):" , len (plan .OrphanedBranches ))
4546 if plan .SkippedIgnored > 0 {
46- commands .PrintInfo ( fmt . Sprintf ( "(%d ignored branches skipped)" , plan .SkippedIgnored ) )
47+ commands .PrintInfof ( "(%d ignored branches skipped)" , plan .SkippedIgnored )
4748 }
4849 for _ , ob := range plan .OrphanedBranches {
49- fmt .Printf (" - %s: %s\n " , ob .RepoName , ob .BranchName )
50+ if ob .HasUnpushed {
51+ fmt .Printf (" - %s: %s %s\n " , ob .RepoName , ob .BranchName , commands .ColorWarning (fmt .Sprintf ("(%d unpushed)" , ob .UnpushedCount )))
52+ } else {
53+ fmt .Printf (" - %s: %s\n " , ob .RepoName , ob .BranchName )
54+ }
5055 }
5156
5257 if ! commands .PromptYesNo ("\n Do you want to delete these branches? (y/n): " ) {
@@ -58,7 +63,7 @@ func cleanupBranches() {
5863
5964 result , err := svc .ExecuteCleanup (plan , skipBranches )
6065 if err != nil {
61- commands .PrintError ( fmt . Sprintf ( "Failed to execute cleanup: %v" , err ) )
66+ commands .PrintErrorf ( "Failed to execute cleanup: %v" , err )
6267 return
6368 }
6469
@@ -70,9 +75,9 @@ func promptForUnpushedBranches(plan *branch.CleanupPlan) []string {
7075
7176 for _ , ob := range plan .OrphanedBranches {
7277 if ob .HasUnpushed {
73- commands .PrintWarning ( fmt . Sprintf ( "Branch '%s' in %s has %d unpushed commit(s)" , ob .BranchName , ob .RepoName , ob .UnpushedCount ) )
78+ commands .PrintWarningf ( "Branch '%s' in %s has %d unpushed commit(s)" , ob .BranchName , ob .RepoName , ob .UnpushedCount )
7479 if ! commands .PromptYesNo ("Delete anyway? (y/n): " ) {
75- commands .PrintInfo ( fmt . Sprintf ( "Skipping branch '%s'" , ob .BranchName ) )
80+ commands .PrintInfof ( "Skipping branch '%s'" , ob .BranchName )
7681 skipBranches = append (skipBranches , fmt .Sprintf ("%s:%s" , ob .RepoName , ob .BranchName ))
7782 }
7883 }
@@ -85,17 +90,17 @@ func displayCleanupResult(result *branch.CleanupResult) {
8590 fmt .Printf ("\n " )
8691
8792 for _ , d := range result .Deleted {
88- commands .PrintSuccess ( fmt . Sprintf ( "Deleted %s in %s" , d .BranchName , d .RepoName ) )
93+ commands .PrintSuccessf ( "Deleted %s in %s" , d .BranchName , d .RepoName )
8994 }
9095
9196 for _ , f := range result .Failed {
92- commands .PrintError ( fmt . Sprintf ( "Failed to delete %s in %s: %v" , f .BranchName , f .RepoName , f .Error ) )
97+ commands .PrintErrorf ( "Failed to delete %s in %s: %v" , f .BranchName , f .RepoName , f .Error )
9398 }
9499
95100 if len (result .Deleted ) > 0 {
96- commands .PrintSuccess ( fmt . Sprintf ( "Deleted %d branch(es)" , len (result .Deleted ) ))
101+ commands .PrintSuccessf ( "Deleted %d branch(es)" , len (result .Deleted ))
97102 }
98103 if len (result .Failed ) > 0 {
99- commands .PrintWarning ( fmt . Sprintf ( "Failed to delete %d branch(es)" , len (result .Failed ) ))
104+ commands .PrintWarningf ( "Failed to delete %d branch(es)" , len (result .Failed ))
100105 }
101106}
0 commit comments