From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Pierre Habouzit <madcoder@debian.org>
Cc: git@vger.kernel.org, gitster@pobox.com
Subject: Re: [RESEND PATCH] git-checkout: fix argument parsing to detect ambiguous arguments.
Date: Wed, 23 Jul 2008 12:10:03 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.1.00.0807231158390.2830@eeepc-johanness> (raw)
In-Reply-To: <20080723012751.GI11831@artemis.madism.org>
Hi,
On Wed, 23 Jul 2008, Pierre Habouzit wrote:
> Note that it also fix a bug, git checkout -- <path> would be badly
s/fix/fixes/
> understood as git checkout <branch> if <path> is ambiguous with a branch.
>
> Testcases included.
>
> Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Instead of the "Testcases included", I would have expected something like
When calling "git checkout <name>" and <name> is both a path and a
branch, Git would silently assume that you meant the branch.
Worse, "git checkout -- <name>" would behave the same.
probably even as first paragraph.
> This is a resend with proper patches that made me realize that my
s/patches/tests/
> previous patch had silly mistakes and wasn't testing thigns properly.
>
> builtin-checkout.c | 23 +++++++++++++++++------
> t/t2010-checkout-ambiguous.sh | 35 +++++++++++++++++++++++++++++++++++
> 2 files changed, 52 insertions(+), 6 deletions(-)
> create mode 100755 t/t2010-checkout-ambiguous.sh
>
> diff --git a/builtin-checkout.c b/builtin-checkout.c
> index fbd5105..97321e6 100644
> --- a/builtin-checkout.c
> +++ b/builtin-checkout.c
> @@ -438,12 +438,17 @@ 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], "--")) {
> + int may_be_ambiguous = argc == 1 || strcmp(argv[1], "--");
> +
> arg = argv[0];
> - if (get_sha1(arg, rev))
> - ;
> - else if ((new.commit = lookup_commit_reference_gently(rev, 1))) {
> + if (get_sha1(arg, rev)) {
> + if (may_be_ambiguous)
> + verify_filename(NULL, arg);
Still you allow "git checkout <path> --" to succeed, right? It should
not.
IMHO you need "must_be_branch" and "must_not_be_path" instead of
"may_be_ambiguous".
I.e. something like
int must_be_branch = argc > 1 && !strcmp(argv[1], "--");
int must_not_be_path = argc > 1 && strcmp(argv[1], "--");
arg = argv[0];
if (get_sha1(arg, rev)) {
if (must_be_branch)
die ("Not a branch: '%s'", arg);
}
else {
if (must_not_be_path)
verify_non_filename(NULL, arg);
if ((new.commit = lookup_commit_reference_gently(rev, 1))) {
[...]
And maybe you want to add a test for "git checkout <path> --" to fail,
too.
Ciao,
Dscho
next prev parent reply other threads:[~2008-07-23 10:10 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-23 1:02 [PATCH] git-checkout: fix argument parsing to detect ambiguous arguments Pierre Habouzit
2008-07-23 1:13 ` 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 [this message]
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=alpine.DEB.1.00.0807231158390.2830@eeepc-johanness \
--to=johannes.schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=madcoder@debian.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