check_filename(): handle ":^" path magic
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>
Jeff King committed
May 26, 2017 at 15:08 UTC
42471bcee44e87669eb17f9fa13c8041a0fc35a1
2 files changed
+17
setup.c
+4
@@ -141,6 +141,10 @@ int check_filename(const char *prefix, const char *arg)
141
if (!*arg) /* ":/" is root dir, always exists */
142
return 1;
143
prefix = NULL;
144
+ } else if (skip_prefix(arg, ":!", &arg) ||
145
+ skip_prefix(arg, ":^", &arg)) {
146
+ if (!*arg) /* excluding everything is silly, but allowed */
147
+ return 1;
148
}
149
150
if (prefix)
t/t4208-log-magic-pathspec.sh
+13
@@ -52,6 +52,19 @@ test_expect_success 'git log HEAD -- :/' '
52
test_cmp expected actual
53
'
54
55
+test_expect_success '"git log :^sub" is not ambiguous' '
56
+ git log :^sub
57
+'
58
+
59
+test_expect_success '"git log :^does-not-exist" does not match anything' '
60
+ test_must_fail git log :^does-not-exist
61
+'
62
+
63
+test_expect_success '"git log :!" behaves the same as :^' '
64
+ git log :!sub &&
65
+ test_must_fail git log :!does-not-exist
66
+'
67
+
68
test_expect_success 'command line pathspec parsing for "git log"' '
69
git reset --hard &&
70
>a &&