1 # git-gui branch delete support
2 # Copyright (C) 2007 Shawn Pearce
6 field w
; # widget path
7 field w_heads
; # listbox of local head names
8 field w_check
; # revision picker for merge test
9 field w_delete
; # delete button
11 constructor dialog
{} {
12 global all_heads current_branch
15 wm title
$top "[appname] ([reponame]): Delete Branch"
17 wm geometry
$top "+[winfo rootx .]+[winfo rooty .]"
20 label $w.header
-text {Delete Local Branch
} -font font_uibold
21 pack $w.header
-side top
-fill x
24 set w_delete
$w.buttons.delete
30 pack $w_delete -side right
31 button $w.buttons.cancel
\
33 -command [list destroy $w]
34 pack $w.buttons.cancel
-side right
-padx 5
35 pack $w.buttons
-side bottom
-fill x
-pady 10 -padx 10
37 labelframe $w.
list -text {Local Branches
}
42 -selectmode extended
\
43 -yscrollcommand [list $w.
list.sby
set]
44 scrollbar $w.
list.sby
-command [list $w.
list.l yview
]
45 pack $w.
list.sby
-side right
-fill y
46 pack $w.
list.l
-side left
-fill both
-expand 1
47 pack $w.
list -fill both
-expand 1 -pady 5 -padx 5
49 set w_check
[choose_rev
::new \
51 {Delete Only If Merged Into
} \
53 $w_check none
{Always
(Do not perform merge test.
)}
54 pack $w.check
-anchor nw
-fill x
-pady 5 -padx 5
56 foreach h
$all_heads {
57 if {$h ne
$current_branch} {
58 $w_heads insert end
$h
62 bind $w_heads <<ListboxSelect
>> [cb _select
]
63 bind $w <Visibility
> "
67 bind $w <Key-Escape
> [list destroy $w]
68 bind $w <Key-Return
> [cb _delete
]\;break
73 if {[$w_heads curselection
] eq
{}} {
74 $w_delete configure
-state disabled
76 $w_delete configure
-state normal
83 if {[catch {set check_cmt
[$w_check get_commit
]} err
]} {
87 -title [wm title
$w] \
89 -message "Invalid revision: [$w_check get]"
95 foreach i
[$w_heads curselection
] {
96 set b
[$w_heads get
$i]
98 set o
[git rev-parse
--verify "refs/heads/$b"]
100 if {$check_cmt ne
{}} {
101 if {[catch {set m
[git merge-base
$o $check_cmt]}]} continue
103 lappend not_merged
$b
107 lappend to_delete
[list $b $o]
109 if {$not_merged ne
{}} {
110 set msg
"The following branches are not completely merged into [$w_check get]:
112 - [join $not_merged "\n - "]"
116 -title [wm title
$w] \
120 if {$to_delete eq
{}} return
121 if {$check_cmt eq
{}} {
122 set msg
{Recovering deleted branches is difficult.
124 Delete the selected branches?
}
128 -title [wm title
$w] \
130 -message $msg] ne yes
} {
136 foreach i
$to_delete {
139 if {[catch {git update-ref
-d "refs/heads/$b" $o} err
]} {
140 append failed
" - $b: $err\n"
142 set x
[lsearch -sorted -exact $all_heads $b]
144 set all_heads
[lreplace $all_heads $x $x]
153 -title [wm title
$w] \
155 -message "Failed to delete branches:\n$failed"
158 set all_heads
[lsort $all_heads]