From: "Jens Lidestrom via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Paul Mackerras [ ]" <paulus@ozlabs.org>,
Johannes Sixt <j6t@kdbg.org>, Jens Lidestrom <jens@lidestrom.se>,
Jens Lidestrom <jens@lidestrom.se>
Subject: [PATCH v2 10/10] gitk: allow checkout of remote branch
Date: Mon, 03 Jul 2023 18:45:58 +0000 [thread overview]
Message-ID: <3f0438fc0277338a917dce815ddf910826c66d66.1688409958.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1551.v2.git.1688409958.gitgitgadget@gmail.com>
From: Jens Lidestrom <jens@lidestrom.se>
This is a consequence of allowing checkout of detached heads (through
keyboard shortcut). It doesn't make sense to disallow checkout of
commits on remote branches if all other commits can be checked out.
Signed-off-by: Jens Lidestrom <jens@lidestrom.se>
---
gitk-git/gitk | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/gitk-git/gitk b/gitk-git/gitk
index fafff2b1a5b..99f93371482 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -9989,10 +9989,6 @@ proc headmenu {x y id head} {
set headmenuhead $head
array set state {0 normal 1 normal 2 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}
}
if {$head eq $mainhead} {
@@ -10078,17 +10074,29 @@ proc checkout {heads_on_commit id_to_checkout} {
set ref_to_checkout $head_to_checkout
}
- # Handle remote branches
set command [list | git checkout]
if {[string match "remotes/*" $head_to_checkout]} {
- set remote $head_to_checkout
+ # Handle remote branches
+ set remote_head $head_to_checkout
set head_to_checkout [string range $head_to_checkout [expr [string last / $head_to_checkout] + 1] end]
- set ref_to_checkout $head_to_checkout
if {[info exists headids($head_to_checkout)]} {
- error_popup [mc "A local branch named %s exists already" $head_to_checkout]
- return
+ # The local branch exists
+ set id_to_checkout $headids($remote_head)
+ if {$headids($head_to_checkout) eq $id_to_checkout} {
+ # Remote and local are at the same commit
+ set ref_to_checkout $head_to_checkout
+ } else {
+ # Check out the detached head of the remote branch
+ set head_to_checkout ""
+ set ref_to_checkout $id_to_checkout
+ }
+ lappend command $ref_to_checkout
+ } else {
+ # Create local branch and checkout
+ set ref_to_checkout $head_to_checkout
+ puts $ref_to_checkout
+ lappend command -b $ref_to_checkout --track $remote_head
}
- lappend command -b $head_to_checkout --track $remote
} else {
lappend command $ref_to_checkout
}
--
gitgitgadget
prev parent reply other threads:[~2023-07-03 18:46 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-27 14:41 [PATCH 0/9] gitk: improve keyboard support Jens Lidestrom via GitGitGadget
2023-06-27 14:41 ` [PATCH 1/9] gitk: add procedures to get commit info from selected row Jens Lidestrom via GitGitGadget
2023-06-27 14:41 ` [PATCH 2/9] gitk: use term "current branch" in gui Jens Lidestrom via GitGitGadget
2023-06-27 14:41 ` [PATCH 3/9] gitk: add keyboard bind for reset Jens Lidestrom via GitGitGadget
2023-06-27 14:41 ` [PATCH 4/9] gitk: show branch name in reset dialog Jens Lidestrom via GitGitGadget
2023-06-27 14:41 ` [PATCH 5/9] gitk: add keyboard bind for checkout Jens Lidestrom via GitGitGadget
2023-07-02 12:10 ` Jens Lideström
2023-06-27 14:41 ` [PATCH 6/9] gitk: add keyboard bind for create and remove branch Jens Lidestrom via GitGitGadget
2023-06-28 5:59 ` Johannes Sixt
2023-06-28 7:12 ` Jens Lideström
2023-06-28 20:30 ` Johannes Sixt
2023-07-02 11:50 ` Jens Lideström
2023-06-27 14:41 ` [PATCH 7/9] gitk: add keyboard bind to cherry-pick Jens Lidestrom via GitGitGadget
2023-06-27 14:41 ` [PATCH 8/9] gitk: focus ok button in reset dialog Jens Lidestrom via GitGitGadget
2023-06-27 14:41 ` [PATCH 9/9] gitk: default select reset hard in dialog Jens Lidestrom via GitGitGadget
2023-06-28 5:46 ` Johannes Sixt
2023-06-28 7:16 ` Jens Lideström
2023-07-02 12:09 ` Jens Lideström
2023-06-28 6:09 ` [PATCH 0/9] gitk: improve keyboard support Johannes Sixt
2023-06-28 7:01 ` Jens Lideström
2023-06-28 17:32 ` Jens Lideström
2023-06-28 20:32 ` Johannes Sixt
2023-07-02 12:28 ` Jens Lideström
2023-07-03 18:45 ` [PATCH v2 00/10] " Jens Lidestrom via GitGitGadget
2023-07-03 18:45 ` [PATCH v2 01/10] gitk: add procedures to get commit info from selected row Jens Lidestrom via GitGitGadget
2023-07-03 18:45 ` [PATCH v2 02/10] gitk: use term "current branch" in gui Jens Lidestrom via GitGitGadget
2023-07-03 18:45 ` [PATCH v2 03/10] gitk: add keyboard bind for reset command Jens Lidestrom via GitGitGadget
2023-07-03 18:45 ` [PATCH v2 04/10] gitk: show branch name in reset dialog Jens Lidestrom via GitGitGadget
2023-07-03 18:45 ` [PATCH v2 05/10] gitk: add keyboard bind for checkout command Jens Lidestrom via GitGitGadget
2023-07-05 17:29 ` Johannes Sixt
2023-07-08 12:09 ` Jens Lideström
2023-07-03 18:45 ` [PATCH v2 06/10] gitk: add keyboard bind for remove branch command Jens Lidestrom via GitGitGadget
2023-07-05 20:00 ` Johannes Sixt
2023-07-08 12:09 ` Jens Lideström
2023-07-03 18:45 ` [PATCH v2 07/10] gitk: add keyboard bind for cherry-pick command Jens Lidestrom via GitGitGadget
2023-07-05 20:07 ` Johannes Sixt
2023-07-08 12:09 ` Jens Lideström
2023-07-03 18:45 ` [PATCH v2 08/10] gitk: add keyboard bind for create branch command Jens Lidestrom via GitGitGadget
2023-07-05 20:02 ` Johannes Sixt
2023-07-03 18:45 ` [PATCH v2 09/10] gitk: improve keyboard convenience in reset dialog Jens Lidestrom via GitGitGadget
2023-07-05 19:52 ` Johannes Sixt
2023-07-03 18:45 ` Jens Lidestrom via GitGitGadget [this message]
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=3f0438fc0277338a917dce815ddf910826c66d66.1688409958.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=j6t@kdbg.org \
--cc=jens@lidestrom.se \
--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 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).