Code

git-gui: Improve the branch delete confirmation dialogs.
authorShawn O. Pearce <spearce@spearce.org>
Sun, 21 Jan 2007 09:51:45 +0000 (04:51 -0500)
committerShawn O. Pearce <spearce@spearce.org>
Sun, 21 Jan 2007 09:51:45 +0000 (04:51 -0500)
If the user is deleting a branch which is fully merged into the
selected test branch we should not confirm the delete with them,
the fact that the branch is fully merged means we can recover the
branch and no work will be lost.

If a branch is not fully merged, we should warn the user about which
branch(es) that is and continue deleting those which are fully merged.

We should only delete a branch if the user disables the merge check,
and in that case we should confirm with the user that a delete should
occur as this may cause them to lose changes.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
git-gui.sh

index e4676bf7950ab86452a435cdf26710ea7e32b3c7..c9143973d756df9b0fb16642be71c09b89aac4ff 100755 (executable)
@@ -1811,43 +1811,43 @@ proc do_delete_branch_action {w} {
        global delete_branch_checkhead delete_branch_head
 
        set to_delete [list]
-       set msg {Are you sure you want to delete the following branches?
-
-}
+       set not_merged [list]
        foreach i [$w.list.l curselection] {
                set b [$w.list.l get $i]
                if {[catch {set o [exec git rev-parse --verify $b]}]} continue
                if {$delete_branch_checkhead} {
                        if {[catch {set m [exec git merge-base $o $delete_branch_head]}]} continue
-                       if {$o ne $m} continue
+                       if {$o ne $m} {
+                               lappend not_merged $b
+                               continue
+                       }
                }
                lappend to_delete [list $b $o]
-               append msg " - $b\n"
        }
-       if {$to_delete eq {}} {
+       if {$not_merged ne {}} {
+               set msg "The following branches are not completely merged into $delete_branch_head:
+
+ - [join $not_merged "\n - "]"
                tk_messageBox \
                        -icon info \
                        -type ok \
                        -title [wm title $w] \
                        -parent $w \
-                       -message {No branches are able to be deleted.
-
-This is likely because you did not select any branches,
-or all selected branches are not completely merged.
-}
-               return
+                       -message $msg
        }
-       append msg {
-It can be difficult to recover deleted branches.
+       if {$to_delete eq {}} return
+       if {!$delete_branch_checkhead} {
+               set msg {Recovering deleted branches is difficult.
 
-Delete the above branches?}
-       if {[tk_messageBox \
-               -icon warning \
-               -type yesno \
-               -title [wm title $w] \
-               -parent $w \
-               -message $msg] ne yes} {
-               return
+Delete the selected branches?}
+               if {[tk_messageBox \
+                       -icon warning \
+                       -type yesno \
+                       -title [wm title $w] \
+                       -parent $w \
+                       -message $msg] ne yes} {
+                       return
+               }
        }
 
        set failed {}