2007-07-04 05:33:59 +02:00
|
|
|
# git-gui branch delete support
|
|
|
|
# Copyright (C) 2007 Shawn Pearce
|
|
|
|
|
|
|
|
class branch_delete {
|
|
|
|
|
|
|
|
field w ; # widget path
|
|
|
|
field w_heads ; # listbox of local head names
|
|
|
|
field w_check ; # revision picker for merge test
|
|
|
|
field w_delete ; # delete button
|
|
|
|
|
|
|
|
constructor dialog {} {
|
2010-01-26 01:05:31 +01:00
|
|
|
global current_branch use_ttk NS
|
2007-07-04 05:33:59 +02:00
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
make_dialog top w
|
|
|
|
wm withdraw $w
|
2007-07-21 14:21:34 +02:00
|
|
|
wm title $top [append "[appname] ([reponame]): " [mc "Delete Branch"]]
|
2007-07-04 05:33:59 +02:00
|
|
|
if {$top ne {.}} {
|
|
|
|
wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
|
|
|
|
}
|
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::label $w.header -text [mc "Delete Local Branch"] \
|
|
|
|
-font font_uibold -anchor center
|
2007-07-04 05:33:59 +02:00
|
|
|
pack $w.header -side top -fill x
|
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::frame $w.buttons
|
2007-07-04 05:33:59 +02:00
|
|
|
set w_delete $w.buttons.delete
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::button $w_delete \
|
2007-07-21 14:21:34 +02:00
|
|
|
-text [mc Delete] \
|
2007-07-04 05:33:59 +02:00
|
|
|
-default active \
|
|
|
|
-state disabled \
|
|
|
|
-command [cb _delete]
|
|
|
|
pack $w_delete -side right
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::button $w.buttons.cancel \
|
2007-07-21 14:21:34 +02:00
|
|
|
-text [mc Cancel] \
|
2007-07-04 05:33:59 +02:00
|
|
|
-command [list destroy $w]
|
|
|
|
pack $w.buttons.cancel -side right -padx 5
|
|
|
|
pack $w.buttons -side bottom -fill x -pady 10 -padx 10
|
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::labelframe $w.list -text [mc "Local Branches"]
|
2007-07-04 05:33:59 +02:00
|
|
|
set w_heads $w.list.l
|
2010-01-26 01:05:31 +01:00
|
|
|
slistbox $w_heads \
|
2007-07-04 05:33:59 +02:00
|
|
|
-height 10 \
|
|
|
|
-width 70 \
|
|
|
|
-selectmode extended \
|
2010-01-26 01:05:31 +01:00
|
|
|
-exportselection false
|
2007-07-04 05:33:59 +02:00
|
|
|
pack $w.list.l -side left -fill both -expand 1
|
|
|
|
pack $w.list -fill both -expand 1 -pady 5 -padx 5
|
|
|
|
|
|
|
|
set w_check [choose_rev::new \
|
|
|
|
$w.check \
|
2007-07-21 14:21:34 +02:00
|
|
|
[mc "Delete Only If Merged Into"] \
|
2007-07-04 05:33:59 +02:00
|
|
|
]
|
2009-03-24 00:42:24 +01:00
|
|
|
$w_check none [mc "Always (Do not perform merge checks)"]
|
2007-07-04 05:33:59 +02:00
|
|
|
pack $w.check -anchor nw -fill x -pady 5 -padx 5
|
|
|
|
|
2007-07-09 00:40:56 +02:00
|
|
|
foreach h [load_all_heads] {
|
2007-07-04 05:33:59 +02:00
|
|
|
if {$h ne $current_branch} {
|
|
|
|
$w_heads insert end $h
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bind $w_heads <<ListboxSelect>> [cb _select]
|
|
|
|
bind $w <Visibility> "
|
|
|
|
grab $w
|
|
|
|
focus $w
|
|
|
|
"
|
|
|
|
bind $w <Key-Escape> [list destroy $w]
|
|
|
|
bind $w <Key-Return> [cb _delete]\;break
|
2010-01-26 01:05:31 +01:00
|
|
|
wm deiconify $w
|
2007-07-04 05:33:59 +02:00
|
|
|
tkwait window $w
|
|
|
|
}
|
|
|
|
|
|
|
|
method _select {} {
|
|
|
|
if {[$w_heads curselection] eq {}} {
|
|
|
|
$w_delete configure -state disabled
|
|
|
|
} else {
|
|
|
|
$w_delete configure -state normal
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
method _delete {} {
|
2007-07-04 22:38:13 +02:00
|
|
|
if {[catch {set check_cmt [$w_check commit_or_die]}]} {
|
2007-07-04 05:33:59 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
set to_delete [list]
|
|
|
|
set not_merged [list]
|
|
|
|
foreach i [$w_heads curselection] {
|
|
|
|
set b [$w_heads get $i]
|
|
|
|
if {[catch {
|
|
|
|
set o [git rev-parse --verify "refs/heads/$b"]
|
|
|
|
}]} continue
|
|
|
|
if {$check_cmt ne {}} {
|
|
|
|
if {[catch {set m [git merge-base $o $check_cmt]}]} continue
|
|
|
|
if {$o ne $m} {
|
|
|
|
lappend not_merged $b
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lappend to_delete [list $b $o]
|
|
|
|
}
|
|
|
|
if {$not_merged ne {}} {
|
2007-07-21 14:21:34 +02:00
|
|
|
set msg "[mc "The following branches are not completely merged into %s:" [$w_check get]]
|
2007-07-04 05:33:59 +02:00
|
|
|
|
|
|
|
- [join $not_merged "\n - "]"
|
|
|
|
tk_messageBox \
|
|
|
|
-icon info \
|
|
|
|
-type ok \
|
|
|
|
-title [wm title $w] \
|
|
|
|
-parent $w \
|
|
|
|
-message $msg
|
|
|
|
}
|
|
|
|
if {$to_delete eq {}} return
|
|
|
|
if {$check_cmt eq {}} {
|
2009-03-24 00:42:24 +01:00
|
|
|
set msg [mc "Recovering deleted branches is difficult.\n\nDelete the selected branches?"]
|
2007-07-04 05:33:59 +02:00
|
|
|
if {[tk_messageBox \
|
|
|
|
-icon warning \
|
|
|
|
-type yesno \
|
|
|
|
-title [wm title $w] \
|
|
|
|
-parent $w \
|
|
|
|
-message $msg] ne yes} {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set failed {}
|
|
|
|
foreach i $to_delete {
|
|
|
|
set b [lindex $i 0]
|
|
|
|
set o [lindex $i 1]
|
2008-05-09 02:29:42 +02:00
|
|
|
if {[catch {git branch -D $b} err]} {
|
2007-07-04 05:33:59 +02:00
|
|
|
append failed " - $b: $err\n"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$failed ne {}} {
|
|
|
|
tk_messageBox \
|
|
|
|
-icon error \
|
|
|
|
-type ok \
|
|
|
|
-title [wm title $w] \
|
|
|
|
-parent $w \
|
2007-07-21 14:21:34 +02:00
|
|
|
-message [mc "Failed to delete branches:\n%s" $failed]
|
2007-07-04 05:33:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
destroy $w
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|