Merge branch 'nd/magic-pathspec-from-root'
When giving arguments without "--" disambiguation, object names that come earlier on the command line must not be interpretable as pathspecs and pathspecs that come later on the command line must not be interpretable as object names. Tweak the disambiguation rule so that ":/" (no other string before or after) is always interpreted as a pathspec, to avoid having to say "git cmd -- :/". * nd/magic-pathspec-from-root: grep: avoid accepting ambiguous revision Update :/abc ambiguity check
This commit is contained in:
@ -823,6 +823,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
|
|||||||
struct object *object = parse_object(sha1);
|
struct object *object = parse_object(sha1);
|
||||||
if (!object)
|
if (!object)
|
||||||
die(_("bad object %s"), arg);
|
die(_("bad object %s"), arg);
|
||||||
|
if (!seen_dashdash)
|
||||||
|
verify_non_filename(prefix, arg);
|
||||||
add_object_array(object, arg, &list);
|
add_object_array(object, arg, &list);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
9
setup.c
9
setup.c
@ -66,7 +66,14 @@ int check_filename(const char *prefix, const char *arg)
|
|||||||
const char *name;
|
const char *name;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
name = prefix ? prefix_filename(prefix, strlen(prefix), arg) : arg;
|
if (!prefixcmp(arg, ":/")) {
|
||||||
|
if (arg[2] == '\0') /* ":/" is root dir, always exists */
|
||||||
|
return 1;
|
||||||
|
name = arg + 2;
|
||||||
|
} else if (prefix)
|
||||||
|
name = prefix_filename(prefix, strlen(prefix), arg);
|
||||||
|
else
|
||||||
|
name = arg;
|
||||||
if (!lstat(name, &st))
|
if (!lstat(name, &st))
|
||||||
return 1; /* file exists */
|
return 1; /* file exists */
|
||||||
if (errno == ENOENT || errno == ENOTDIR)
|
if (errno == ENOENT || errno == ENOTDIR)
|
||||||
|
@ -11,11 +11,24 @@ test_expect_success 'setup' '
|
|||||||
mkdir sub
|
mkdir sub
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '"git log :/" should be ambiguous' '
|
test_expect_success '"git log :/" should not be ambiguous' '
|
||||||
test_must_fail git log :/ 2>error &&
|
git log :/
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success '"git log :/a" should be ambiguous (applied both rev and worktree)' '
|
||||||
|
: >a &&
|
||||||
|
test_must_fail git log :/a 2>error &&
|
||||||
grep ambiguous error
|
grep ambiguous error
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success '"git log :/a -- " should not be ambiguous' '
|
||||||
|
git log :/a --
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success '"git log -- :/a" should not be ambiguous' '
|
||||||
|
git log -- :/a
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success '"git log :" should be ambiguous' '
|
test_expect_success '"git log :" should be ambiguous' '
|
||||||
test_must_fail git log : 2>error &&
|
test_must_fail git log : 2>error &&
|
||||||
grep ambiguous error
|
grep ambiguous error
|
||||||
|
Reference in New Issue
Block a user