You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
3.3 KiB
148 lines
3.3 KiB
18 years ago
|
# 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 {} {
|
||
15 years ago
|
global current_branch use_ttk NS
|
||
18 years ago
|
|
||
15 years ago
|
make_dialog top w
|
||
|
wm withdraw $w
|
||
18 years ago
|
wm title $top [append "[appname] ([reponame]): " [mc "Delete Branch"]]
|
||
18 years ago
|
if {$top ne {.}} {
|
||
|
wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
|
||
|
}
|
||
|
|
||
15 years ago
|
${NS}::label $w.header -text [mc "Delete Local Branch"] \
|
||
|
-font font_uibold -anchor center
|
||
18 years ago
|
pack $w.header -side top -fill x
|
||
|
|
||
15 years ago
|
${NS}::frame $w.buttons
|
||
18 years ago
|
set w_delete $w.buttons.delete
|
||
15 years ago
|
${NS}::button $w_delete \
|
||
18 years ago
|
-text [mc Delete] \
|
||
18 years ago
|
-default active \
|
||
|
-state disabled \
|
||
|
-command [cb _delete]
|
||
|
pack $w_delete -side right
|
||
15 years ago
|
${NS}::button $w.buttons.cancel \
|
||
18 years ago
|
-text [mc Cancel] \
|
||
18 years ago
|
-command [list destroy $w]
|
||
|
pack $w.buttons.cancel -side right -padx 5
|
||
|
pack $w.buttons -side bottom -fill x -pady 10 -padx 10
|
||
|
|
||
15 years ago
|
${NS}::labelframe $w.list -text [mc "Local Branches"]
|
||
18 years ago
|
set w_heads $w.list.l
|
||
15 years ago
|
slistbox $w_heads \
|
||
18 years ago
|
-height 10 \
|
||
|
-width 70 \
|
||
|
-selectmode extended \
|
||
15 years ago
|
-exportselection false
|
||
18 years ago
|
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 \
|
||
18 years ago
|
[mc "Delete Only If Merged Into"] \
|
||
18 years ago
|
]
|
||
16 years ago
|
$w_check none [mc "Always (Do not perform merge checks)"]
|
||
18 years ago
|
pack $w.check -anchor nw -fill x -pady 5 -padx 5
|
||
|
|
||
18 years ago
|
foreach h [load_all_heads] {
|
||
18 years ago
|
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
|
||
15 years ago
|
wm deiconify $w
|
||
18 years ago
|
tkwait window $w
|
||
|
}
|
||
|
|
||
|
method _select {} {
|
||
|
if {[$w_heads curselection] eq {}} {
|
||
|
$w_delete configure -state disabled
|
||
|
} else {
|
||
|
$w_delete configure -state normal
|
||
|
}
|
||
|
}
|
||
|
|
||
|
method _delete {} {
|
||
18 years ago
|
if {[catch {set check_cmt [$w_check commit_or_die]}]} {
|
||
18 years ago
|
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 {}} {
|
||
18 years ago
|
set msg "[mc "The following branches are not completely merged into %s:" [$w_check get]]
|
||
18 years ago
|
|
||
|
- [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 {}} {
|
||
16 years ago
|
set msg [mc "Recovering deleted branches is difficult.\n\nDelete the selected branches?"]
|
||
18 years ago
|
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]
|
||
17 years ago
|
if {[catch {git branch -D $b} err]} {
|
||
18 years ago
|
append failed " - $b: $err\n"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if {$failed ne {}} {
|
||
|
tk_messageBox \
|
||
|
-icon error \
|
||
|
-type ok \
|
||
|
-title [wm title $w] \
|
||
|
-parent $w \
|
||
18 years ago
|
-message [mc "Failed to delete branches:\n%s" $failed]
|
||
18 years ago
|
}
|
||
|
|
||
|
destroy $w
|
||
|
}
|
||
|
|
||
|
}
|