Merge branch 'nd/magic-pathspec-from-root'
authorJunio C Hamano <gitster@pobox.com>
Wed, 30 Jan 2013 16:52:53 +0000 (08:52 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 30 Jan 2013 16:52:53 +0000 (08:52 -0800)
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

builtin/grep.c
setup.c
t/t4208-log-magic-pathspec.sh
index 0e1b6c860e18c6c47f343fad885cbd24f641862e..8025964987553b8f1ef21b8319b2085d6d31bb0c 100644 (file)
@@ -823,6 +823,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                        struct object *object = parse_object(sha1);
                        if (!object)
                                die(_("bad object %s"), arg);
+                       if (!seen_dashdash)
+                               verify_non_filename(prefix, arg);
                        add_object_array(object, arg, &list);
                        continue;
                }
diff --git a/setup.c b/setup.c
index 1ccfafaa7a85875338a49953518207b74dca62c4..2e1521b09e5e6a0de585225293805b1d30a03cd4 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -66,7 +66,14 @@ int check_filename(const char *prefix, const char *arg)
        const char *name;
        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))
                return 1; /* file exists */
        if (errno == ENOENT || errno == ENOTDIR)
index 2c482b622b4a9e68bb0614dec8e156d5dfc8fa06..72300b5f244504540a551854cb82f81cf5391a55 100755 (executable)
@@ -11,11 +11,24 @@ test_expect_success 'setup' '
        mkdir sub
 '
 
-test_expect_success '"git log :/" should be ambiguous' '
-       test_must_fail git log :/ 2>error &&
+test_expect_success '"git log :/" should not be ambiguous' '
+       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
 '
 
+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_must_fail git log : 2>error &&
        grep ambiguous error