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 current_branch use_ttk NS
 
  16         wm title $top [mc "%s (%s): Delete Branch" [appname] [reponame]]
 
  18                 wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
 
  21         ${NS}::label $w.header -text [mc "Delete Local Branch"] \
 
  22                 -font font_uibold -anchor center
 
  23         pack $w.header -side top -fill x
 
  25         ${NS}::frame $w.buttons
 
  26         set w_delete $w.buttons.delete
 
  27         ${NS}::button $w_delete \
 
  32         pack $w_delete -side right
 
  33         ${NS}::button $w.buttons.cancel \
 
  35                 -command [list destroy $w]
 
  36         pack $w.buttons.cancel -side right -padx 5
 
  37         pack $w.buttons -side bottom -fill x -pady 10 -padx 10
 
  39         ${NS}::labelframe $w.list -text [mc "Local Branches"]
 
  44                 -selectmode extended \
 
  45                 -exportselection false
 
  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                 [mc "Delete Only If Merged Into"] \
 
  53         $w_check none [mc "Always (Do not perform merge checks)"]
 
  54         pack $w.check -anchor nw -fill x -pady 5 -padx 5
 
  56         foreach h [load_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
 
  74         if {[$w_heads curselection] eq {}} {
 
  75                 $w_delete configure -state disabled
 
  77                 $w_delete configure -state normal
 
  82         if {[catch {set check_cmt [$w_check commit_or_die]}]} {
 
  88         foreach i [$w_heads curselection] {
 
  89                 set b [$w_heads get $i]
 
  91                         set o [git rev-parse --verify "refs/heads/$b"]
 
  93                 if {$check_cmt ne {}} {
 
  94                         if {[catch {set m [git merge-base $o $check_cmt]}]} continue
 
 100                 lappend to_delete [list $b $o]
 
 102         if {$not_merged ne {}} {
 
 103                 set msg "[mc "The following branches are not completely merged into %s:" [$w_check get]]
 
 105  - [join $not_merged "\n - "]"
 
 109                         -title [wm title $w] \
 
 113         if {$to_delete eq {}} return
 
 114         if {$check_cmt eq {}} {
 
 115                 set msg [mc "Recovering deleted branches is difficult.\n\nDelete the selected branches?"]
 
 119                         -title [wm title $w] \
 
 121                         -message $msg] ne yes} {
 
 127         foreach i $to_delete {
 
 130                 if {[catch {git branch -D $b} err]} {
 
 131                         append failed [mc " - %s:" $b] " $err\n"
 
 139                         -title [wm title $w] \
 
 141                         -message [mc "Failed to delete branches:\n%s" $failed]