check_filename(): handle ":^" path magic
authorJeff King <peff@peff.net>
Fri, 26 May 2017 19:08:39 +0000 (15:08 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 May 2017 02:36:56 +0000 (11:36 +0900)
We special-case "git log :/foo" to work when "foo" exists in
the working tree. But :^ (and its alias :!) do not get the
same treatment, requiring the user to supply a
disambiguating "--". Let's make them work without requiring
the user to type the "--".

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
setup.c
t/t4208-log-magic-pathspec.sh
diff --git a/setup.c b/setup.c
index f2a8070bd4d9c9fb0117f87fdadc208d86e07e2b..86bb7c9a96a61ed6ed07aca8bc55bc2c078799c3 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -141,6 +141,10 @@ int check_filename(const char *prefix, const char *arg)
                if (!*arg) /* ":/" is root dir, always exists */
                        return 1;
                prefix = NULL;
+       } else if (skip_prefix(arg, ":!", &arg) ||
+                  skip_prefix(arg, ":^", &arg)) {
+               if (!*arg) /* excluding everything is silly, but allowed */
+                       return 1;
        }
 
        if (prefix)
index 70bc64100b707c8e2d2c7913ff04e6599de64d18..627890d7d895618b8c0d9ff8d66a3265e9e2fdad 100755 (executable)
@@ -52,6 +52,19 @@ test_expect_success 'git log HEAD -- :/' '
        test_cmp expected actual
 '
 
+test_expect_success '"git log :^sub" is not ambiguous' '
+       git log :^sub
+'
+
+test_expect_success '"git log :^does-not-exist" does not match anything' '
+       test_must_fail git log :^does-not-exist
+'
+
+test_expect_success  '"git log :!" behaves the same as :^' '
+       git log :!sub &&
+       test_must_fail git log :!does-not-exist
+'
+
 test_expect_success 'command line pathspec parsing for "git log"' '
        git reset --hard &&
        >a &&