All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre Dumuid <pmdumuid@gmail.com>
To: paulus@ozlabs.org, git@vger.kernel.org
Cc: Pierre Dumuid <pmdumuid@gmail.com>
Subject: [PATCH 2/6] Add ability to follow a remote branch with a dialog
Date: Thu, 15 Dec 2016 21:58:43 +1030	[thread overview]
Message-ID: <20161215112847.14719-2-pmdumuid@gmail.com> (raw)
In-Reply-To: <20161215112847.14719-1-pmdumuid@gmail.com>

A suggested name is provided when creating a new "following" branch.

Signed-off-by: Pierre Dumuid <pmdumuid@gmail.com>
---
 gitk | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 82 insertions(+), 4 deletions(-)

diff --git a/gitk b/gitk
index 50d1ef4..36cba49 100755
--- a/gitk
+++ b/gitk
@@ -2673,6 +2673,7 @@ proc makewindow {} {
 	{mc "Rename this branch" command mvbranch}
 	{mc "Remove this branch" command rmbranch}
 	{mc "Copy branch name" command {clipboard clear; clipboard append $headmenuhead}}
+	{mc "Follow this branch"  command follow_remote_branch_dialog}
     }
     $headctxmenu configure -tearoff 0
 
@@ -9947,23 +9948,100 @@ proc headmenu {x y id head} {
     stopfinding
     set headmenuid $id
     set headmenuhead $head
-    array set state {0 normal 1 normal 2 normal}
+    array set state {0 normal 1 normal 2 normal 3 normal}
     if {[string match "remotes/*" $head]} {
 	set localhead [string range $head [expr [string last / $head] + 1] end]
 	if {[info exists headids($localhead)]} {
 	    set state(0) disabled
 	}
-	array set state {1 disabled 2 disabled}
+	array set state {1 disabled 2 disabled 3 normal}
     }
     if {$head eq $mainhead} {
-	array set state {0 disabled 2 disabled}
+	array set state {0 disabled 2 disabled 3 disabled}
+    } else {
+	set state(3) disabled
     }
-    foreach i {0 1 2} {
+    foreach i {0 1 2 3} {
 	$headctxmenu entryconfigure $i -state $state($i)
     }
     tk_popup $headctxmenu $x $y
 }
 
+proc follow_remote_branch_dialog {} {
+    global headmenuhead NS
+
+    # check the tree is clean first??
+    nowbusy createFollowingBranch [mc "Creating following branch"]
+    update
+    dohidelocalchanges
+
+    set top .create_following_branch
+    catch {destroy $top}
+    ttk_toplevel $top
+    make_transient $top .
+
+    ${NS}::label $top.title -text [mc "Create following branch"]
+    grid $top.title - -pady 10
+
+    ${NS}::label $top.remote_branch_name_label -text [mc "Remote Branch:"]
+    ${NS}::entry $top.remote_branch_name -width 40
+    $top.remote_branch_name insert 0 $headmenuhead
+    $top.remote_branch_name conf -state readonly
+    grid $top.remote_branch_name_label $top.remote_branch_name -sticky w
+
+    ${NS}::label $top.new_branch_name_label -text [mc "Name:"]
+    ${NS}::entry $top.new_branch_name -width 40
+    set suggested_name $headmenuhead
+    regsub {^remotes/[^/]*/} $suggested_name {} suggested_name
+    $top.new_branch_name insert 0 $suggested_name
+    grid $top.new_branch_name_label $top.new_branch_name -sticky w
+
+    set actionCreate [list follow_remote_branch_callback $top]
+    set actionCancel "catch {notbusy createFollowingBranch; destroy $top}"
+
+    ${NS}::frame $top.buts
+    ${NS}::button $top.buts.go  -text [mc "Create"] -command $actionCreate
+    ${NS}::button $top.buts.can -text [mc "Cancel"] -command $actionCancel
+    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
+
+    bind $top <Key-Return> $actionCreate
+    bind $top <Key-Escape> $actionCancel
+
+    focus $top.new_branch_name
+}
+
+proc follow_remote_branch_callback {top} {
+    global headids idheads NS
+    set new_branch_name    [$top.new_branch_name get]
+    set remote_branch_name [$top.remote_branch_name get]
+    set cmdargs {}
+
+    if {$new_branch_name eq {}} {
+	error_popup [mc "Please specify a name for the new branch"] $top
+	return
+    }
+    if {[info exists headids($new_branch_name)]} {
+	error_popup [mc "The branch name you specified already exists, please specify a new name"] $top
+	return
+    }
+    catch {destroy $top}
+
+    lappend cmdargs $new_branch_name $remote_branch_name
+
+    if {[catch {
+	eval exec git branch --track $cmdargs
+    } err]} {
+	notbusy createFollowingBranch
+	error_popup $err
+    } else {
+	notbusy createFollowingBranch
+	updatecommits
+    }
+}
+
 proc cobranch {} {
     global headmenuid headmenuhead headids
     global showlocalchanges
-- 
2.10.2


  reply	other threads:[~2016-12-15 11:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-15 11:28 [PATCH 1/6] Enable ability to visualise the results of git cherry C1 C2 Pierre Dumuid
2016-12-15 11:28 ` Pierre Dumuid [this message]
2016-12-31  8:53   ` [PATCH 2/6] Add ability to follow a remote branch with a dialog Paul Mackerras
2016-12-15 11:28 ` [PATCH 3/6] Add a tree view to the local branches, remote branches and tags, where / is treated as a directory seperator Pierre Dumuid
2016-12-31  9:08   ` Paul Mackerras
2016-12-15 11:28 ` [PATCH 4/6] Add DirDiffTool as additional option Pierre Dumuid
2016-12-15 11:28 ` [PATCH 5/6] gitk: Add a "Save file as" menu item Pierre Dumuid
2016-12-15 11:28 ` [PATCH 6/6] Rename 'remotes/' to 'r../' in heads Pierre Dumuid
2016-12-31  8:30 ` [PATCH 1/6] Enable ability to visualise the results of git cherry C1 C2 Paul Mackerras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161215112847.14719-2-pmdumuid@gmail.com \
    --to=pmdumuid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=paulus@ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.