aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--setup.c20
-rwxr-xr-xt/t4208-log-magic-pathspec.sh13
2 files changed, 32 insertions, 1 deletions
diff --git a/setup.c b/setup.c
index 86bb7c9a9..89fcc12ab 100644
--- a/setup.c
+++ b/setup.c
@@ -186,6 +186,24 @@ static void NORETURN die_verify_filename(const char *prefix,
}
/*
+ * Check for arguments that don't resolve as actual files,
+ * but which look sufficiently like pathspecs that we'll consider
+ * them such for the purposes of rev/pathspec DWIM parsing.
+ */
+static int looks_like_pathspec(const char *arg)
+{
+ /* anything with a wildcard character */
+ if (!no_wildcard(arg))
+ return 1;
+
+ /* long-form pathspec magic */
+ if (starts_with(arg, ":("))
+ return 1;
+
+ return 0;
+}
+
+/*
* Verify a filename that we got as an argument for a pathspec
* entry. Note that a filename that begins with "-" never verifies
* as true, because even if such a filename were to exist, we want
@@ -211,7 +229,7 @@ void verify_filename(const char *prefix,
{
if (*arg == '-')
die("bad flag '%s' used after filename", arg);
- if (check_filename(prefix, arg) || !no_wildcard(arg))
+ if (check_filename(prefix, arg) || looks_like_pathspec(arg))
return;
die_verify_filename(prefix, arg, diagnose_misspelt_rev);
}
diff --git a/t/t4208-log-magic-pathspec.sh b/t/t4208-log-magic-pathspec.sh
index 627890d7d..935df6a65 100755
--- a/t/t4208-log-magic-pathspec.sh
+++ b/t/t4208-log-magic-pathspec.sh
@@ -65,6 +65,19 @@ test_expect_success '"git log :!" behaves the same as :^' '
test_must_fail git log :!does-not-exist
'
+test_expect_success '"git log :(exclude)sub" is not ambiguous' '
+ git log ":(exclude)sub"
+'
+
+test_expect_success '"git log :(exclude)sub --" must resolve as an object' '
+ test_must_fail git log ":(exclude)sub" --
+'
+
+test_expect_success '"git log :(unknown-magic) complains of bogus magic' '
+ test_must_fail git log ":(unknown-magic)" 2>error &&
+ test_i18ngrep pathspec.magic error
+'
+
test_expect_success 'command line pathspec parsing for "git log"' '
git reset --hard &&
>a &&