From: Pierre Habouzit <madcoder@debian.org>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Pierre Habouzit <madcoder@debian.org>
Subject: [PATCH] git-checkout: fix argument parsing to detect ambiguous arguments.
Date: Wed, 23 Jul 2008 03:02:20 +0200 [thread overview]
Message-ID: <1216774940-4955-1-git-send-email-madcoder@debian.org> (raw)
Note that it also fix a bug, git checkout -- <path> would be badly
understood as git checkout <branch> if <path> is ambiguous with a branch.
Testcases included.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
A user on #git happened to have issues that made me realize that
builtin-checkout is badly broken wrt argument parseing.
This clearly needs to be applied to master, probably to maint too.
The patch is against next though, but should probably apply to other
branches just fine.
builtin-checkout.c | 9 +++++++--
t/t2010-checkout-ambiguous.sh | 27 +++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 2 deletions(-)
create mode 100755 t/t2010-checkout-ambiguous.sh
diff --git a/builtin-checkout.c b/builtin-checkout.c
index fbd5105..1490e8e 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -438,9 +438,14 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
opts.track = git_branch_track;
- argc = parse_options(argc, argv, options, checkout_usage, 0);
- if (argc) {
+ argc = parse_options(argc, argv, options, checkout_usage,
+ PARSE_OPT_KEEP_DASHDASH);
+
+ if (argc && strcmp(argv[0], "--")) {
arg = argv[0];
+
+ if (argc == 1 || strcmp(argv[1], "--"))
+ verify_non_filename(NULL, arg);
if (get_sha1(arg, rev))
;
else if ((new.commit = lookup_commit_reference_gently(rev, 1))) {
diff --git a/t/t2010-checkout-ambiguous.sh b/t/t2010-checkout-ambiguous.sh
new file mode 100755
index 0000000..c1a86a2
--- /dev/null
+++ b/t/t2010-checkout-ambiguous.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+test_description='checkout and pathspecs/refspecs ambiguities'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+ echo hello >world &&
+ git add world &&
+ git commit -m initial &&
+ git branch world
+'
+
+test_expect_success 'branch switching' '
+ git checkout world --
+'
+
+test_expect_success 'checkout world from the index' '
+ git checkout -- world
+'
+
+test_expect_success 'ambiguous call' '
+ test_must_fail git checkout world
+'
+
+test_done
--
1.6.0.rc0.154.g60644
next reply other threads:[~2008-07-23 1:03 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-23 1:02 Pierre Habouzit [this message]
2008-07-23 1:13 ` [PATCH] git-checkout: fix argument parsing to detect ambiguous arguments Pierre Habouzit
2008-07-23 1:17 ` Johannes Schindelin
2008-07-23 1:32 ` Pierre Habouzit
2008-07-23 1:27 ` [RESEND PATCH] " Pierre Habouzit
2008-07-23 1:39 ` Pierre Habouzit
2008-07-23 10:10 ` Johannes Schindelin
2008-07-23 10:15 ` Resubmit after a night of sleep Pierre Habouzit
2008-07-23 10:15 ` [PATCH 1/2] git-checkout: fix command line parsing Pierre Habouzit
2008-07-23 10:15 ` [PATCH 2/2] git-checkout: improve error messages, detect ambiguities Pierre Habouzit
2008-07-23 23:04 ` Junio C Hamano
2008-07-24 2:07 ` Junio C Hamano
2008-07-24 8:33 ` Pierre Habouzit
2008-07-23 11:49 ` [PATCH] checkout: mention '--' in the docs SZEDER Gábor
2008-07-23 11:49 ` [PATCH] bash: offer only paths after '--' for 'git checkout' SZEDER Gábor
2008-07-25 20:34 ` Shawn O. Pearce
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=1216774940-4955-1-git-send-email-madcoder@debian.org \
--to=madcoder@debian.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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.