2007-05-28 18:52:57 +02:00
|
|
|
# git-gui branch rename support
|
|
|
|
# Copyright (C) 2007 Shawn Pearce
|
|
|
|
|
|
|
|
class branch_rename {
|
|
|
|
|
|
|
|
field w
|
|
|
|
field oldname
|
|
|
|
field newname
|
|
|
|
|
|
|
|
constructor dialog {} {
|
2010-01-26 01:05:31 +01:00
|
|
|
global current_branch use_ttk NS
|
2007-05-28 18:52:57 +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 "Rename Branch"]]
|
2007-05-28 18:52:57 +02:00
|
|
|
if {$top ne {.}} {
|
|
|
|
wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
|
|
|
|
}
|
|
|
|
|
|
|
|
set oldname $current_branch
|
|
|
|
set newname [get_config gui.newbranchtemplate]
|
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::label $w.header -text [mc "Rename Branch"]\
|
|
|
|
-font font_uibold -anchor center
|
2007-05-28 18:52:57 +02:00
|
|
|
pack $w.header -side top -fill x
|
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::frame $w.buttons
|
|
|
|
${NS}::button $w.buttons.rename -text [mc Rename] \
|
2007-05-28 18:52:57 +02:00
|
|
|
-default active \
|
|
|
|
-command [cb _rename]
|
|
|
|
pack $w.buttons.rename -side right
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::button $w.buttons.cancel -text [mc Cancel] \
|
2007-05-28 18:52:57 +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}::frame $w.rename
|
|
|
|
${NS}::label $w.rename.oldname_l -text [mc "Branch:"]
|
|
|
|
if {$use_ttk} {
|
|
|
|
ttk::combobox $w.rename.oldname_m -textvariable @oldname \
|
|
|
|
-values [load_all_heads] -state readonly
|
|
|
|
} else {
|
|
|
|
eval tk_optionMenu $w.rename.oldname_m @oldname [load_all_heads]
|
|
|
|
}
|
2007-05-28 18:52:57 +02:00
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::label $w.rename.newname_l -text [mc "New Name:"]
|
|
|
|
${NS}::entry $w.rename.newname_t \
|
2007-05-28 18:52:57 +02:00
|
|
|
-width 40 \
|
|
|
|
-textvariable @newname \
|
|
|
|
-validate key \
|
|
|
|
-validatecommand {
|
|
|
|
if {%d == 1 && [regexp {[~^:?*\[\0- ]} %S]} {return 0}
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2010-10-08 00:00:33 +02:00
|
|
|
grid $w.rename.oldname_l $w.rename.oldname_m -sticky we -padx {0 5}
|
2007-05-28 18:52:57 +02:00
|
|
|
grid $w.rename.newname_l $w.rename.newname_t -sticky we -padx {0 5}
|
|
|
|
grid columnconfigure $w.rename 1 -weight 1
|
|
|
|
pack $w.rename -anchor nw -fill x -pady 5 -padx 5
|
|
|
|
|
|
|
|
bind $w <Key-Return> [cb _rename]
|
|
|
|
bind $w <Key-Escape> [list destroy $w]
|
|
|
|
bind $w <Visibility> "
|
|
|
|
grab $w
|
|
|
|
$w.rename.newname_t icursor end
|
|
|
|
focus $w.rename.newname_t
|
|
|
|
"
|
2010-01-26 01:05:31 +01:00
|
|
|
wm deiconify $w
|
2007-05-28 18:52:57 +02:00
|
|
|
tkwait window $w
|
|
|
|
}
|
|
|
|
|
|
|
|
method _rename {} {
|
2007-07-09 00:40:56 +02:00
|
|
|
global current_branch
|
2007-05-28 18:52:57 +02:00
|
|
|
|
|
|
|
if {$oldname eq {}} {
|
|
|
|
tk_messageBox \
|
|
|
|
-icon error \
|
|
|
|
-type ok \
|
|
|
|
-title [wm title $w] \
|
|
|
|
-parent $w \
|
2007-07-21 14:21:34 +02:00
|
|
|
-message [mc "Please select a branch to rename."]
|
2007-05-28 18:52:57 +02:00
|
|
|
focus $w.rename.oldname_m
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if {$newname eq {}
|
|
|
|
|| $newname eq [get_config gui.newbranchtemplate]} {
|
|
|
|
tk_messageBox \
|
|
|
|
-icon error \
|
|
|
|
-type ok \
|
|
|
|
-title [wm title $w] \
|
|
|
|
-parent $w \
|
2007-07-21 14:21:34 +02:00
|
|
|
-message [mc "Please supply a branch name."]
|
2007-05-28 18:52:57 +02:00
|
|
|
focus $w.rename.newname_t
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if {![catch {git show-ref --verify -- "refs/heads/$newname"}]} {
|
|
|
|
tk_messageBox \
|
|
|
|
-icon error \
|
|
|
|
-type ok \
|
|
|
|
-title [wm title $w] \
|
|
|
|
-parent $w \
|
2007-07-21 14:21:34 +02:00
|
|
|
-message [mc "Branch '%s' already exists." $newname]
|
2007-05-28 18:52:57 +02:00
|
|
|
focus $w.rename.newname_t
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if {[catch {git check-ref-format "heads/$newname"}]} {
|
|
|
|
tk_messageBox \
|
|
|
|
-icon error \
|
|
|
|
-type ok \
|
|
|
|
-title [wm title $w] \
|
|
|
|
-parent $w \
|
2007-07-21 14:21:34 +02:00
|
|
|
-message [mc "'%s' is not an acceptable branch name." $newname]
|
2007-05-28 18:52:57 +02:00
|
|
|
focus $w.rename.newname_t
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if {[catch {git branch -m $oldname $newname} err]} {
|
|
|
|
tk_messageBox \
|
|
|
|
-icon error \
|
|
|
|
-type ok \
|
|
|
|
-title [wm title $w] \
|
|
|
|
-parent $w \
|
2007-09-14 07:50:09 +02:00
|
|
|
-message [strcat [mc "Failed to rename '%s'." $oldname] "\n\n$err"]
|
2007-05-28 18:52:57 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$current_branch eq $oldname} {
|
|
|
|
set current_branch $newname
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy $w
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|