1 # git-gui branch rename support
 
   2 # Copyright (C) 2007 Shawn Pearce
 
  10 constructor dialog {} {
 
  11         global current_branch use_ttk NS
 
  15         wm title $top [mc "%s (%s): Rename Branch" [appname] [reponame]]
 
  17                 wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
 
  20         set oldname $current_branch
 
  21         set newname [get_config gui.newbranchtemplate]
 
  23         ${NS}::label $w.header -text [mc "Rename Branch"]\
 
  24                 -font font_uibold -anchor center
 
  25         pack $w.header -side top -fill x
 
  27         ${NS}::frame $w.buttons
 
  28         ${NS}::button $w.buttons.rename -text [mc Rename] \
 
  31         pack $w.buttons.rename -side right
 
  32         ${NS}::button $w.buttons.cancel -text [mc 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         ${NS}::frame $w.rename
 
  38         ${NS}::label $w.rename.oldname_l -text [mc "Branch:"]
 
  40                 ttk::combobox $w.rename.oldname_m -textvariable @oldname \
 
  41                         -values [load_all_heads] -state readonly
 
  43                 eval tk_optionMenu $w.rename.oldname_m @oldname [load_all_heads]
 
  46         ${NS}::label $w.rename.newname_l -text [mc "New Name:"]
 
  47         ${NS}::entry $w.rename.newname_t \
 
  49                 -textvariable @newname \
 
  52                         if {%d == 1 && [regexp {[~^:?*\[\0- ]} %S]} {return 0}
 
  56         grid $w.rename.oldname_l $w.rename.oldname_m -sticky we -padx {0 5}
 
  57         grid $w.rename.newname_l $w.rename.newname_t -sticky we -padx {0 5}
 
  58         grid columnconfigure $w.rename 1 -weight 1
 
  59         pack $w.rename -anchor nw -fill x -pady 5 -padx 5
 
  61         bind $w <Key-Return> [cb _rename]
 
  62         bind $w <Key-Escape> [list destroy $w]
 
  63         bind $w <Visibility> "
 
  65                 $w.rename.newname_t icursor end
 
  66                 focus $w.rename.newname_t
 
  79                         -title [wm title $w] \
 
  81                         -message [mc "Please select a branch to rename."]
 
  82                 focus $w.rename.oldname_m
 
  86                 || $newname eq [get_config gui.newbranchtemplate]} {
 
  90                         -title [wm title $w] \
 
  92                         -message [mc "Please supply a branch name."]
 
  93                 focus $w.rename.newname_t
 
  96         if {![catch {git show-ref --verify -- "refs/heads/$newname"}]} {
 
 100                         -title [wm title $w] \
 
 102                         -message [mc "Branch '%s' already exists." $newname]
 
 103                 focus $w.rename.newname_t
 
 106         if {[catch {git check-ref-format "heads/$newname"}]} {
 
 110                         -title [wm title $w] \
 
 112                         -message [mc "'%s' is not an acceptable branch name." $newname]
 
 113                 focus $w.rename.newname_t
 
 117         if {[catch {git branch -m $oldname $newname} err]} {
 
 121                         -title [wm title $w] \
 
 123                         -message [strcat [mc "Failed to rename '%s'." $oldname] "\n\n$err"]
 
 127         if {$current_branch eq $oldname} {
 
 128                 set current_branch $newname