1 # git-gui branch rename support
2 # Copyright (C) 2007 Shawn Pearce
10 constructor dialog {} {
14 wm title $top [append "[appname] ([reponame]): " [mc "Rename Branch"]]
16 wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
19 set oldname $current_branch
20 set newname [get_config gui.newbranchtemplate]
22 label $w.header -text [mc "Rename Branch"] -font font_uibold
23 pack $w.header -side top -fill x
26 button $w.buttons.rename -text [mc Rename] \
29 pack $w.buttons.rename -side right
30 button $w.buttons.cancel -text [mc Cancel] \
31 -command [list destroy $w]
32 pack $w.buttons.cancel -side right -padx 5
33 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
36 label $w.rename.oldname_l -text [mc "Branch:"]
37 eval tk_optionMenu $w.rename.oldname_m @oldname [load_all_heads]
39 label $w.rename.newname_l -text [mc "New Name:"]
40 entry $w.rename.newname_t \
44 -textvariable @newname \
47 if {%d == 1 && [regexp {[~^:?*\[\0- ]} %S]} {return 0}
51 grid $w.rename.oldname_l $w.rename.oldname_m -sticky w -padx {0 5}
52 grid $w.rename.newname_l $w.rename.newname_t -sticky we -padx {0 5}
53 grid columnconfigure $w.rename 1 -weight 1
54 pack $w.rename -anchor nw -fill x -pady 5 -padx 5
56 bind $w <Key-Return> [cb _rename]
57 bind $w <Key-Escape> [list destroy $w]
58 bind $w <Visibility> "
60 $w.rename.newname_t icursor end
61 focus $w.rename.newname_t
73 -title [wm title $w] \
75 -message [mc "Please select a branch to rename."]
76 focus $w.rename.oldname_m
80 || $newname eq [get_config gui.newbranchtemplate]} {
84 -title [wm title $w] \
86 -message [mc "Please supply a branch name."]
87 focus $w.rename.newname_t
90 if {![catch {git show-ref --verify -- "refs/heads/$newname"}]} {
94 -title [wm title $w] \
96 -message [mc "Branch '%s' already exists." $newname]
97 focus $w.rename.newname_t
100 if {[catch {git check-ref-format "heads/$newname"}]} {
104 -title [wm title $w] \
106 -message [mc "'%s' is not an acceptable branch name." $newname]
107 focus $w.rename.newname_t
111 if {[catch {git branch -m $oldname $newname} err]} {
115 -title [wm title $w] \
117 -message [append [mc "Failed to rename '%s'." $oldname] "\n\n$err"]
121 if {$current_branch eq $oldname} {
122 set current_branch $newname