From: Alex Riesen <raa.lkml@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <junkio@cox.net>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH] Extend "checkout --track" DWIM to support more cases
Date: Wed, 20 Aug 2008 20:50:28 +0200 [thread overview]
Message-ID: <20080820185028.GA16626@blimp.local> (raw)
The code handles additionally "refs/remotes/<something>/name",
"remotes/<something>/name", and "refs/<namespace>/name".
Test cases included.
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
Johannes has likable ideas :)
builtin-checkout.c | 20 +++++++++++++++-----
t/t7201-co.sh | 23 ++++++++++++++++++++++-
2 files changed, 37 insertions(+), 6 deletions(-)
diff --git a/builtin-checkout.c b/builtin-checkout.c
index e95eab9..20466e2 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -447,11 +447,21 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
char *slash;
if (!argc || !strcmp(argv[0], "--"))
die ("--track needs a branch name");
- slash = strchr(argv[0], '/');
- if (slash && !prefixcmp(argv[0], "refs/"))
- slash = strchr(slash + 1, '/');
- if (slash && !prefixcmp(argv[0], "remotes/"))
- slash = strchr(slash + 1, '/');
+ if (!prefixcmp(argv[0], "remotes/"))
+ /* skip the name of a remote */
+ slash = strchr(argv[0] + 8, '/');
+ else if (!prefixcmp(argv[0], "refs/")) {
+ /* skip namespaces, try use the names of their
+ * branches, but for the target namespace
+ * (heads) demand a new name. Also skip the
+ * first element in "remotes" namespace */
+ const char *ns = argv[0] + 5;
+ slash = !prefixcmp(ns, "heads/") ? NULL:
+ !prefixcmp(ns, "remotes/") ?
+ strchr(ns + 8, '/'): strchr(ns, '/');
+ } else
+ /* otherwise - just skip the first element */
+ slash = strchr(argv[0], '/');
if (!slash || !slash[1])
die ("Missing branch name; try -b");
opts.new_branch = slash + 1;
diff --git a/t/t7201-co.sh b/t/t7201-co.sh
index 943dd57..1dff84d 100755
--- a/t/t7201-co.sh
+++ b/t/t7201-co.sh
@@ -340,9 +340,30 @@ test_expect_success \
test_expect_success \
'checkout with --track fakes a sensible -b <name>' '
git update-ref refs/remotes/origin/koala/bear renamer &&
+ git update-ref refs/new/koala/bear renamer &&
+
git checkout --track origin/koala/bear &&
test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" &&
- test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)"'
+ test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" &&
+
+ git checkout master && git branch -D koala/bear &&
+
+ git checkout --track refs/remotes/origin/koala/bear &&
+ test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" &&
+
+ git checkout master && git branch -D koala/bear &&
+
+ git checkout --track remotes/origin/koala/bear &&
+ test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" &&
+
+ git checkout master && git branch -D koala/bear &&
+
+ git checkout --track refs/new/koala/bear &&
+ test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)"
+'
test_expect_success \
'checkout with --track, but without -b, fails with too short tracked name' '
--
1.6.0.22.g09248
next reply other threads:[~2008-08-20 18:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-20 18:50 Alex Riesen [this message]
2008-08-20 19:52 ` [PATCH] Extend "checkout --track" DWIM to support more cases Johannes Schindelin
2008-08-20 20:04 ` Alex Riesen
2008-08-20 20:16 ` Johannes Schindelin
2008-08-20 20:29 ` Alex Riesen
2008-08-20 22:22 ` Junio C Hamano
2008-08-21 17:23 ` Alex Riesen
2008-08-22 5:54 ` Junio C Hamano
2008-08-22 9:08 ` Alex Riesen
2008-08-22 21:17 ` Junio C Hamano
2008-08-22 23:33 ` Jay Soffian
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=20080820185028.GA16626@blimp.local \
--to=raa.lkml@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/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).