From: Rogier Goossens <goossens.rogier@gmail.com>
To: git@vger.kernel.org
Cc: Paul Mackerras <paulus@samba.org>
Subject: [PATCH 2/2] gitk: Allow checking out a remote branch
Date: Fri, 15 Jan 2016 22:43:47 +0100 [thread overview]
Message-ID: <1964156.4P5fNkQCS3@wiske> (raw)
In-Reply-To: <51900395.pKIx87RN0F@wiske>
Git allows checking out remote branches, creating a local tracking
branch in the process. Allow gitk to do this as well, provided a
local branch of the same name does not yet exist.
Signed-off-by: Rogier Goossens <goossens.rogier@gmail.com>
---
gitk | 35 ++++++++++++++++++++++++++++++-----
1 file changed, 30 insertions(+), 5 deletions(-)
diff --git a/gitk b/gitk
index e9465fb..7d5fd33 100755
--- a/gitk
+++ b/gitk
@@ -9826,14 +9826,17 @@ proc readresetstat {fd} {
# context menu for a head
proc headmenu {x y id head} {
- global headmenuid headmenuhead headctxmenu mainhead
+ global headmenuid headmenuhead headctxmenu mainhead headids
stopfinding
set headmenuid $id
set headmenuhead $head
array set state {0 normal 1 normal 2 normal 3 normal}
if {[string match "remotes/*" $head]} {
- set state(0) disabled
+ set localhead [string range $head [expr [string last / $head] + 1] end]
+ if {[info exists headids($localhead)]} {
+ set state(0) disabled
+ }
set state(1) disabled
set state(2) disabled
}
@@ -9852,11 +9855,27 @@ proc cobranch {} {
global showlocalchanges
# check the tree is clean first??
+ set newhead $headmenuhead
+ set command [list | git checkout]
+ if {[string match "remotes/*" $newhead]} {
+ set remote $newhead
+ set newhead [string range $newhead [expr [string last / $newhead] + 1] end]
+ # The following check is redundant - the menu option should
+ # be disabled to begin with...
+ if {[info exists headids($newhead)]} {
+ error_popup [mc "A local branch named %s exists already" $newhead]
+ return
+ }
+ lappend command -b $newhead --track $remote
+ } else {
+ lappend command $newhead
+ }
+ lappend command 2>@1
nowbusy checkout [mc "Checking out"]
update
dohidelocalchanges
if {[catch {
- set fd [open [list | git checkout $headmenuhead 2>@1] r]
+ set fd [open $command r]
} err]} {
notbusy checkout
error_popup $err
@@ -9864,12 +9883,12 @@ proc cobranch {} {
dodiffindex
}
} else {
- filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid]
+ filerun $fd [list readcheckoutstat $fd $newhead $headmenuid]
}
}
proc readcheckoutstat {fd newhead newheadid} {
- global mainhead mainheadid headids showlocalchanges progresscoords
+ global mainhead mainheadid headids idheads showlocalchanges progresscoords
global viewmainheadid curview
if {[gets $fd line] >= 0} {
@@ -9884,8 +9903,14 @@ proc readcheckoutstat {fd newhead newheadid} {
notbusy checkout
if {[catch {close $fd} err]} {
error_popup $err
+ return
}
set oldmainid $mainheadid
+ if {! [info exists headids($newhead)]} {
+ set headids($newhead) $newheadid
+ lappend idheads($newheadid) $newhead
+ addedhead $newheadid $newhead
+ }
set mainhead $newhead
set mainheadid $newheadid
set viewmainheadid($curview) $newheadid
--
2.1.4
next prev parent reply other threads:[~2016-01-15 21:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-15 21:31 [PATCH 0/2] gitk: Two improvements to the branch context menu Rogier Goossens
2016-01-15 21:38 ` [PATCH 1/2] gitk: Add a 'rename' option " Rogier Goossens
2016-03-19 3:45 ` Paul Mackerras
2016-01-15 21:43 ` Rogier Goossens [this message]
2016-03-19 18:31 ` [PATCH v2 0/2] gitk: Two improvements " Rogier Goossens
2016-03-19 18:32 ` [PATCH 1/2] gitk: Add a 'rename' option " Rogier Goossens
2016-03-19 18:33 ` [PATCH 2/2] gitk: Allow checking out a remote branch Rogier Goossens
2016-03-27 7:21 ` [PATCH v2a 3/3] gitk: Include commit title in branch dialog Rogier Goossens
2016-12-12 0:02 ` [PATCH v2 0/2] gitk: Two improvements to the branch context menu 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=1964156.4P5fNkQCS3@wiske \
--to=goossens.rogier@gmail.com \
--cc=git@vger.kernel.org \
--cc=paulus@samba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).