diff options
author | Matthieu Moy <Matthieu.Moy@imag.fr> | 2013-10-18 11:25:58 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-10-18 12:57:16 -0700 |
commit | bca39695343ecb113b30c72a3b2e0cb7e73757d8 (patch) | |
tree | 1694059fa4ce68468a592c0072b6f6d2bb654d1c /builtin | |
parent | a047fafc7866cc4087201e284dc1f53e8f9a32d5 (diff) | |
download | git-bca39695343ecb113b30c72a3b2e0cb7e73757d8.tar.gz |
checkout: proper error message on 'git checkout foo bar --'mm/checkout-auto-track-fix
The previous code was detecting the presence of "--" by looking only at
argument 1. As a result, "git checkout foo bar --" was interpreted as an
ambiguous file/revision list, and errored out with:
error: pathspec 'foo' did not match any file(s) known to git.
error: pathspec 'bar' did not match any file(s) known to git.
error: pathspec '--' did not match any file(s) known to git.
This patch fixes it by walking through the argument list to find the
"--", and now complains about the number of references given.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/checkout.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index c98008ab48..e5103b9c95 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -872,7 +872,9 @@ static int parse_branchname_arg(int argc, const char **argv, int argcount = 0; unsigned char branch_rev[20]; const char *arg; - int has_dash_dash; + int dash_dash_pos; + int has_dash_dash = 0; + int i; /* * case 1: git checkout <ref> -- [<paths>] @@ -916,11 +918,20 @@ static int parse_branchname_arg(int argc, const char **argv, if (!argc) return 0; - if (!strcmp(argv[0], "--")) /* case (2) */ - return 1; - arg = argv[0]; - has_dash_dash = (argc > 1) && !strcmp(argv[1], "--"); + dash_dash_pos = -1; + for (i = 0; i < argc; i++) { + if (!strcmp(argv[i], "--")) { + dash_dash_pos = i; + break; + } + } + if (dash_dash_pos == 0) + return 1; /* case (2) */ + else if (dash_dash_pos == 1) + has_dash_dash = 1; /* case (3) or (1) */ + else if (dash_dash_pos >= 2) + die(_("only one reference expected, %d given."), dash_dash_pos); if (!strcmp(arg, "-")) arg = "@{-1}"; |