Skip to content

Commit 8834ea3

Browse files
committed
Merge branch 'nd/dwim-wildcards-as-pathspecs' into maint
"git show 'HEAD:Foo[BAR]Baz'" did not interpret the argument as a rev, i.e. the object named by the the pathname with wildcard characters in a tree object. * nd/dwim-wildcards-as-pathspecs: get_sha1: don't die() on bogus search strings check_filename: tighten dwim-wildcard ambiguity checkout: reorder check_filename conditional
2 parents fbef03d + aac4fac commit 8834ea3

File tree

5 files changed

+54
-33
lines changed

5 files changed

+54
-33
lines changed

builtin/checkout.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,8 @@ static int parse_branchname_arg(int argc, const char **argv,
981981
*/
982982
int recover_with_dwim = dwim_new_local_branch_ok;
983983

984-
if (check_filename(NULL, arg) && !has_dash_dash)
984+
if (!has_dash_dash &&
985+
(check_filename(NULL, arg) || !no_wildcard(arg)))
985986
recover_with_dwim = 0;
986987
/*
987988
* Accept "git checkout foo" and "git checkout foo --"

setup.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,7 @@ int check_filename(const char *prefix, const char *arg)
139139
if (arg[2] == '\0') /* ":/" is root dir, always exists */
140140
return 1;
141141
name = arg + 2;
142-
} else if (!no_wildcard(arg))
143-
return 1;
144-
else if (prefix)
142+
} else if (prefix)
145143
name = prefix_filename(prefix, strlen(prefix), arg);
146144
else
147145
name = arg;
@@ -202,7 +200,7 @@ void verify_filename(const char *prefix,
202200
{
203201
if (*arg == '-')
204202
die("bad flag '%s' used after filename", arg);
205-
if (check_filename(prefix, arg))
203+
if (check_filename(prefix, arg) || !no_wildcard(arg))
206204
return;
207205
die_verify_filename(prefix, arg, diagnose_misspelt_rev);
208206
}

sha1_name.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,12 +882,12 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
882882

883883
if (prefix[0] == '!') {
884884
if (prefix[1] != '!')
885-
die ("Invalid search pattern: %s", prefix);
885+
return -1;
886886
prefix++;
887887
}
888888

889889
if (regcomp(&regex, prefix, REG_EXTENDED))
890-
die("Invalid search pattern: %s", prefix);
890+
return -1;
891891

892892
for (l = list; l; l = l->next) {
893893
l->item->object.flags |= ONELINE_SEEN;

t/t2019-checkout-ambiguous-ref.sh

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,4 @@ test_expect_success VAGUENESS_SUCCESS 'checkout reports switch to branch' '
5656
test_i18ngrep ! "^HEAD is now at" stderr
5757
'
5858

59-
test_expect_success 'wildcard ambiguation, paths win' '
60-
git init ambi &&
61-
(
62-
cd ambi &&
63-
echo a >a.c &&
64-
git add a.c &&
65-
echo b >a.c &&
66-
git checkout "*.c" &&
67-
echo a >expect &&
68-
test_cmp expect a.c
69-
)
70-
'
71-
72-
test_expect_success !MINGW 'wildcard ambiguation, refs lose' '
73-
git init ambi2 &&
74-
(
75-
cd ambi2 &&
76-
echo a >"*.c" &&
77-
git add . &&
78-
test_must_fail git show :"*.c" &&
79-
git show :"*.c" -- >actual &&
80-
echo a >expect &&
81-
test_cmp expect actual
82-
)
83-
'
84-
8559
test_done

t/t6133-pathspec-rev-dwim.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/sh
2+
3+
test_description='test dwim of revs versus pathspecs in revision parser'
4+
. ./test-lib.sh
5+
6+
test_expect_success 'setup' '
7+
test_commit base &&
8+
echo content >"br[ack]ets" &&
9+
git add . &&
10+
test_tick &&
11+
git commit -m brackets
12+
'
13+
14+
test_expect_success 'non-rev wildcard dwims to pathspec' '
15+
git log -- "*.t" >expect &&
16+
git log "*.t" >actual &&
17+
test_cmp expect actual
18+
'
19+
20+
test_expect_success 'tree:path with metacharacters dwims to rev' '
21+
git show "HEAD:br[ack]ets" -- >expect &&
22+
git show "HEAD:br[ack]ets" >actual &&
23+
test_cmp expect actual
24+
'
25+
26+
test_expect_success '^{foo} with metacharacters dwims to rev' '
27+
git log "HEAD^{/b.*}" -- >expect &&
28+
git log "HEAD^{/b.*}" >actual &&
29+
test_cmp expect actual
30+
'
31+
32+
test_expect_success '@{foo} with metacharacters dwims to rev' '
33+
git log "HEAD@{now [or thereabouts]}" -- >expect &&
34+
git log "HEAD@{now [or thereabouts]}" >actual &&
35+
test_cmp expect actual
36+
'
37+
38+
test_expect_success ':/*.t from a subdir dwims to a pathspec' '
39+
mkdir subdir &&
40+
(
41+
cd subdir &&
42+
git log -- ":/*.t" >expect &&
43+
git log ":/*.t" >actual &&
44+
test_cmp expect actual
45+
)
46+
'
47+
48+
test_done

0 commit comments

Comments
 (0)