@matheusbsbs / matheus-bagliano / commits / 15e1374927
Fork 0

git-gui: Improve the merge check interface for branch deletion.

Just like how we split out the local and remote branches into two different pick lists for branch creation, we should do the same thing for branch deletion. This means that there are really 3 modes of operation here: * delete only if merged into designated local branch; * delete only if merged into designated tracking (remote) branch; * delete no matter what So we now use radio buttons to select between these operations. We still default to checking for merge into the current branch, as that is probably the most commonly used behavior. It also is what core Git's command line tools do. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jan 21, 2007 at 14:14 UTC 15e1374927b1dc42a575235c63852d444cf9c1ab
1 file changed +54 -19
git-gui.sh
+54 -19
@@ -1867,16 +1867,34 @@ proc do_create_branch {} {
1867
1868 proc do_delete_branch_action {w} {
1869 global all_heads
1870 - global delete_branch_checkhead delete_branch_head
1870 + global delete_branch_checktype delete_branch_head delete_branch_trackinghead
1871 +
1872 + set check_rev {}
1873 + switch -- $delete_branch_checktype {
1874 + head {set check_rev $delete_branch_head}
1875 + tracking {set check_rev $delete_branch_trackinghead}
1876 + always {set check_rev {:none}}
1877 + }
1878 + if {$check_rev eq {:none}} {
1879 + set check_cmt {}
1880 + } elseif {[catch {set check_cmt [exec git rev-parse --verify "${check_rev}^0"]}]} {
1881 + tk_messageBox \
1882 + -icon error \
1883 + -type ok \
1884 + -title [wm title $w] \
1885 + -parent $w \
1886 + -message "Invalid check revision: $check_rev"
1887 + return
1888 + }
1889
1890 set to_delete [list]
1891 set not_merged [list]
1892 foreach i [$w.list.l curselection] {
1893 set b [$w.list.l get $i]
1894 if {[catch {set o [exec git rev-parse --verify $b]}]} continue
1877 - if {$delete_branch_checkhead} {
1878 - if {$b eq $delete_branch_head} continue
1879 - if {[catch {set m [exec git merge-base $o $delete_branch_head]}]} continue
1895 + if {$check_cmt ne {}} {
1896 + if {$b eq $check_rev} continue
1897 + if {[catch {set m [exec git merge-base $o $check_cmt]}]} continue
1898 if {$o ne $m} {
1899 lappend not_merged $b
1900 continue
@@ -1885,7 +1903,7 @@ proc do_delete_branch_action {w} {
1903 lappend to_delete [list $b $o]
1904 }
1905 if {$not_merged ne {}} {
1888 - set msg "The following branches are not completely merged into $delete_branch_head:
1906 + set msg "The following branches are not completely merged into $check_rev:
1907
1908 - [join $not_merged "\n - "]"
1909 tk_messageBox \
@@ -1896,7 +1914,7 @@ proc do_delete_branch_action {w} {
1914 -message $msg
1915 }
1916 if {$to_delete eq {}} return
1899 - if {!$delete_branch_checkhead} {
1917 + if {$delete_branch_checktype eq {always}} {
1918 set msg {Recovering deleted branches is difficult.
1919
1920 Delete the selected branches?}
@@ -1940,10 +1958,11 @@ Delete the selected branches?}
1958
1959 proc do_delete_branch {} {
1960 global all_heads tracking_branches current_branch
1943 - global delete_branch_checkhead delete_branch_head
1961 + global delete_branch_checktype delete_branch_head delete_branch_trackinghead
1962
1945 - set delete_branch_checkhead 1
1963 + set delete_branch_checktype head
1964 set delete_branch_head $current_branch
1965 + set delete_branch_trackinghead {}
1966
1967 set w .branch_editor
1968 toplevel $w
@@ -1985,21 +2004,37 @@ proc do_delete_branch {} {
2004 regsub ^refs/(heads|remotes)/ $b {} b
2005 lappend all_trackings $b
2006 }
2007 + set all_trackings [lsort -unique $all_trackings]
2008 + if {$all_trackings ne {} && $delete_branch_trackinghead eq {}} {
2009 + set delete_branch_trackinghead [lindex $all_trackings 0]
2010 + }
2011
2012 labelframe $w.validate \
1990 - -text {Only Delete If} \
2013 + -text {Delete Only If} \
2014 + -font font_ui
2015 + radiobutton $w.validate.head_r \
2016 + -text {Merged Into Local Branch:} \
2017 + -value head \
2018 + -variable delete_branch_checktype \
2019 + -font font_ui
2020 + eval tk_optionMenu $w.validate.head_m delete_branch_head $all_heads
2021 + grid $w.validate.head_r $w.validate.head_m -sticky w
2022 + radiobutton $w.validate.tracking_r \
2023 + -text {Merged Into Tracking Branch:} \
2024 + -value tracking \
2025 + -variable delete_branch_checktype \
2026 -font font_ui
1992 - frame $w.validate.head
1993 - checkbutton $w.validate.head.r \
1994 - -text {Already Merged Into:} \
1995 - -variable delete_branch_checkhead \
2027 + eval tk_optionMenu $w.validate.tracking_m \
2028 + delete_branch_trackinghead \
2029 + $all_trackings
2030 + grid $w.validate.tracking_r $w.validate.tracking_m -sticky w
2031 + radiobutton $w.validate.always_r \
2032 + -text {Always (Do not perform merge checks)} \
2033 + -value always \
2034 + -variable delete_branch_checktype \
2035 -font font_ui
1997 - eval tk_optionMenu $w.validate.head.m delete_branch_head \
1998 - $all_heads \
1999 - [lsort -unique $all_trackings]
2000 - pack $w.validate.head.r -side left
2001 - pack $w.validate.head.m -side left
2002 - pack $w.validate.head -padx 5 -fill x -expand 1
2036 + grid $w.validate.always_r -columnspan 2 -sticky w
2037 + grid columnconfigure $w.validate 1 -weight 1
2038 pack $w.validate -anchor nw -fill x -pady 5 -padx 5
2039
2040 bind $w <Visibility> "grab $w; focus $w"