From: Jeff King Date: Fri, 26 May 2017 19:08:39 +0000 (-0400) Subject: check_filename(): handle ":^" path magic X-Git-Tag: v2.14.0-rc0~89^2~2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/42471bcee44e87669eb17f9fa13c8041a0fc35a1 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 Signed-off-by: Junio C Hamano --- diff --git a/setup.c b/setup.c index f2a8070bd4..86bb7c9a96 100644 --- 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) diff --git a/t/t4208-log-magic-pathspec.sh b/t/t4208-log-magic-pathspec.sh index 70bc64100b..627890d7d8 100755 --- a/t/t4208-log-magic-pathspec.sh +++ b/t/t4208-log-magic-pathspec.sh @@ -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 &&