Skip to content

Commit 5a046c5

Browse files
Rogier Goossenspaulusmack
authored andcommitted
gitk: Add a 'rename' option to the branch context menu
Signed-off-by: Rogier Goossens <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent 22a713c commit 5a046c5

File tree

1 file changed

+85
-11
lines changed

1 file changed

+85
-11
lines changed

gitk

Lines changed: 85 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,6 +2664,7 @@ proc makewindow {} {
26642664
set headctxmenu .headctxmenu
26652665
makemenu $headctxmenu {
26662666
{mc "Check out this branch" command cobranch}
2667+
{mc "Rename this branch" command mvbranch}
26672668
{mc "Remove this branch" command rmbranch}
26682669
{mc "Copy branch name" command {clipboard clear; clipboard append $headmenuhead}}
26692670
}
@@ -9452,26 +9453,58 @@ proc wrcomcan {} {
94529453
}
94539454

94549455
proc mkbranch {} {
9455-
global rowmenuid mkbrtop NS
9456+
global NS rowmenuid
9457+
9458+
set top .branchdialog
9459+
9460+
set val(name) ""
9461+
set val(id) $rowmenuid
9462+
set val(command) [list mkbrgo $top]
9463+
9464+
set ui(title) [mc "Create branch"]
9465+
set ui(accept) [mc "Create"]
9466+
9467+
branchdia $top val ui
9468+
}
9469+
9470+
proc mvbranch {} {
9471+
global NS
9472+
global headmenuid headmenuhead
9473+
9474+
set top .branchdialog
9475+
9476+
set val(name) $headmenuhead
9477+
set val(id) $headmenuid
9478+
set val(command) [list mvbrgo $top $headmenuhead]
9479+
9480+
set ui(title) [mc "Rename branch %s" $headmenuhead]
9481+
set ui(accept) [mc "Rename"]
9482+
9483+
branchdia $top val ui
9484+
}
9485+
9486+
proc branchdia {top valvar uivar} {
9487+
global NS
9488+
upvar $valvar val $uivar ui
94569489

9457-
set top .makebranch
94589490
catch {destroy $top}
94599491
ttk_toplevel $top
94609492
make_transient $top .
9461-
${NS}::label $top.title -text [mc "Create new branch"]
9493+
${NS}::label $top.title -text $ui(title)
94629494
grid $top.title - -pady 10
94639495
${NS}::label $top.id -text [mc "ID:"]
94649496
${NS}::entry $top.sha1 -width 40
9465-
$top.sha1 insert 0 $rowmenuid
9497+
$top.sha1 insert 0 $val(id)
94669498
$top.sha1 conf -state readonly
94679499
grid $top.id $top.sha1 -sticky w
94689500
${NS}::label $top.nlab -text [mc "Name:"]
94699501
${NS}::entry $top.name -width 40
9502+
$top.name insert 0 $val(name)
94709503
grid $top.nlab $top.name -sticky w
94719504
${NS}::frame $top.buts
9472-
${NS}::button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top]
9505+
${NS}::button $top.buts.go -text $ui(accept) -command $val(command)
94739506
${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
9474-
bind $top <Key-Return> [list mkbrgo $top]
9507+
bind $top <Key-Return> $val(command)
94759508
bind $top <Key-Escape> "catch {destroy $top}"
94769509
grid $top.buts.go $top.buts.can
94779510
grid columnconfigure $top.buts 0 -weight 1 -uniform a
@@ -9526,6 +9559,46 @@ proc mkbrgo {top} {
95269559
}
95279560
}
95289561

9562+
proc mvbrgo {top prevname} {
9563+
global headids idheads mainhead mainheadid
9564+
9565+
set name [$top.name get]
9566+
set id [$top.sha1 get]
9567+
set cmdargs {}
9568+
if {$name eq $prevname} {
9569+
catch {destroy $top}
9570+
return
9571+
}
9572+
if {$name eq {}} {
9573+
error_popup [mc "Please specify a new name for the branch"] $top
9574+
return
9575+
}
9576+
catch {destroy $top}
9577+
lappend cmdargs -m $prevname $name
9578+
nowbusy renamebranch
9579+
update
9580+
if {[catch {
9581+
eval exec git branch $cmdargs
9582+
} err]} {
9583+
notbusy renamebranch
9584+
error_popup $err
9585+
} else {
9586+
notbusy renamebranch
9587+
removehead $id $prevname
9588+
removedhead $id $prevname
9589+
set headids($name) $id
9590+
lappend idheads($id) $name
9591+
addedhead $id $name
9592+
if {$prevname eq $mainhead} {
9593+
set mainhead $name
9594+
set mainheadid $id
9595+
}
9596+
redrawtags $id
9597+
dispneartags 0
9598+
run refill_reflist
9599+
}
9600+
}
9601+
95299602
proc exec_citool {tool_args {baseid {}}} {
95309603
global commitinfo env
95319604

@@ -9756,15 +9829,16 @@ proc headmenu {x y id head} {
97569829
stopfinding
97579830
set headmenuid $id
97589831
set headmenuhead $head
9759-
set state normal
9832+
array set state {0 normal 1 normal 2 normal}
97609833
if {[string match "remotes/*" $head]} {
9761-
set state disabled
9834+
array set state {0 disabled 1 disabled 2 disabled}
97629835
}
97639836
if {$head eq $mainhead} {
9764-
set state disabled
9837+
array set state {0 disabled 2 disabled}
9838+
}
9839+
foreach i {0 1 2} {
9840+
$headctxmenu entryconfigure $i -state $state($i)
97659841
}
9766-
$headctxmenu entryconfigure 0 -state $state
9767-
$headctxmenu entryconfigure 1 -state $state
97689842
tk_popup $headctxmenu $x $y
97699843
}
97709844

0 commit comments

Comments
 (0)