git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] gitk: Add a 'rename' option to the branch context menu

From
RGRogier Goossens <goossens.rogier@gmail.com>
Date
Jan 15, 2016, 21:38 UTC
Message-ID
<1859807.50qitjY8Ul@wiske>
In-Reply-To
<51900395.pKIx87RN0F@wiske>
Signed-off-by: Rogier Goossens <goossens.rogier@gmail.com>
---
 gitk | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 84 insertions(+), 5 deletions(-)
diff --git a/gitk b/gitk
index 5f1255c..e9465fb 100755
--- a/gitk
+++ b/gitk
@@ -2665,6 +2665,7 @@ proc makewindow {} {
     makemenu $headctxmenu {
 	{mc "Check out this branch" command cobranch}
 	{mc "Remove this branch" command rmbranch}
+	{mc "Rename this branch" command mvbranch}
 	{mc "Copy branch name" command {clipboard clear; clipboard append $headmenuhead}}
     }
     $headctxmenu configure -tearoff 0
@@ -9526,6 +9527,80 @@ proc mkbrgo {top} {
     }
 }
 
+proc mvbranch {} {
+    global mvbrtop NS
+    global headmenuid headmenuhead
+
+    set prevname $headmenuhead
+    set id $headmenuid
+
+    set top .renamebranch
+    catch {destroy $top}
+    ttk_toplevel $top
+    make_transient $top .
+    ${NS}::label $top.title -text [mc "Rename branch %s" $prevname]
+    grid $top.title - -pady 10
+    ${NS}::label $top.id -text [mc "ID:"]
+    ${NS}::entry $top.sha1 -width 40
+    $top.sha1 insert 0 $id
+    $top.sha1 conf -state readonly
+    grid $top.id $top.sha1 -sticky w
+    ${NS}::label $top.nlab -text [mc "Name:"]
+    ${NS}::entry $top.name -width 40
+    $top.name insert 0 $prevname
+    grid $top.nlab $top.name -sticky w
+    ${NS}::frame $top.buts
+    ${NS}::button $top.buts.go -text [mc "Rename"] -command [list mvbrgo $top $prevname]
+    ${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
+    bind $top <Key-Return> [list mvbrgo $top $prevname]
+    bind $top <Key-Escape> "catch {destroy $top}"
+    grid $top.buts.go $top.buts.can
+    grid columnconfigure $top.buts 0 -weight 1 -uniform a
+    grid columnconfigure $top.buts 1 -weight 1 -uniform a
+    grid $top.buts - -pady 10 -sticky ew
+    focus $top.name
+}
+
+proc mvbrgo {top prevname} {
+    global headids idheads mainhead mainheadid
+
+    set name [$top.name get]
+    set id [$top.sha1 get]
+    set cmdargs {}
+    if {$name eq $prevname} {
+	catch {destroy $top}
+	return
+    }
+    if {$name eq {}} {
+	error_popup [mc "Please specify a new name for the branch"] $top
+	return
+    }
+    catch {destroy $top}
+    lappend cmdargs -m $prevname $name
+    nowbusy renamebranch
+    update
+    if {[catch {
+	eval exec git branch $cmdargs
+    } err]} {
+	notbusy renamebranch
+	error_popup $err
+    } else {
+	notbusy renamebranch
+	removehead $id $prevname
+	removedhead $id $prevname
+	set headids($name) $id
+	lappend idheads($id) $name
+	addedhead $id $name
+	if {$prevname eq $mainhead} {
+	    set mainhead $name
+	    set mainheadid $id
+	}
+	redrawtags $id
+	dispneartags 0
+	run refill_reflist
+    }
+}
+
 proc exec_citool {tool_args {baseid {}}} {
     global commitinfo env
 
@@ -9756,15 +9831,19 @@ proc headmenu {x y id head} {
     stopfinding
     set headmenuid $id
     set headmenuhead $head
-    set state normal
+    array set state {0 normal 1 normal 2 normal 3 normal}
     if {[string match "remotes/*" $head]} {
-	set state disabled
+	set state(0) disabled
+	set state(1) disabled
+	set state(2) disabled
     }
     if {$head eq $mainhead} {
-	set state disabled
+	set state(0) disabled
+	set state(1) disabled
+    }
+    foreach i {0 1 2 3} {
+	$headctxmenu entryconfigure $i -state $state($i)
     }
-    $headctxmenu entryconfigure 0 -state $state
-    $headctxmenu entryconfigure 1 -state $state
     tk_popup $headctxmenu $x $y
 }
 
-- 
2.1.4
Previous: Rogier GoossensNext: Paul Mackerras
Message 2 of 9 in “gitk: Two improvements to the branch context menu”
  1. 0/2 gitk: Two improvements to the branch context menuRogier Goossens, Jan 15, 2016
  2. 1/2 gitk: Add a 'rename' option to the branch context menuRogier Goossens, Jan 15, 2016
  3. Paul MackerrasMar 19, 2016
  4. 2/2 gitk: Allow checking out a remote branchRogier Goossens, Jan 15, 2016
  5. 0/2 gitk: Two improvements to the branch context menuRogier Goossens, Mar 19, 2016
  6. 1/2 gitk: Add a 'rename' option to the branch context menuRogier Goossens, Mar 19, 2016
  7. 2/2 gitk: Allow checking out a remote branchRogier Goossens, Mar 19, 2016
  8. 3/3 gitk: Include commit title in branch dialogRogier Goossens, Mar 27, 2016
  9. Paul MackerrasDec 12, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.