mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
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
This commit is contained in:
commit
8834ea375a
|
@ -981,7 +981,8 @@ static int parse_branchname_arg(int argc, const char **argv,
|
||||||
*/
|
*/
|
||||||
int recover_with_dwim = dwim_new_local_branch_ok;
|
int recover_with_dwim = dwim_new_local_branch_ok;
|
||||||
|
|
||||||
if (check_filename(NULL, arg) && !has_dash_dash)
|
if (!has_dash_dash &&
|
||||||
|
(check_filename(NULL, arg) || !no_wildcard(arg)))
|
||||||
recover_with_dwim = 0;
|
recover_with_dwim = 0;
|
||||||
/*
|
/*
|
||||||
* Accept "git checkout foo" and "git checkout foo --"
|
* Accept "git checkout foo" and "git checkout foo --"
|
||||||
|
|
6
setup.c
6
setup.c
|
@ -139,9 +139,7 @@ int check_filename(const char *prefix, const char *arg)
|
||||||
if (arg[2] == '\0') /* ":/" is root dir, always exists */
|
if (arg[2] == '\0') /* ":/" is root dir, always exists */
|
||||||
return 1;
|
return 1;
|
||||||
name = arg + 2;
|
name = arg + 2;
|
||||||
} else if (!no_wildcard(arg))
|
} else if (prefix)
|
||||||
return 1;
|
|
||||||
else if (prefix)
|
|
||||||
name = prefix_filename(prefix, strlen(prefix), arg);
|
name = prefix_filename(prefix, strlen(prefix), arg);
|
||||||
else
|
else
|
||||||
name = arg;
|
name = arg;
|
||||||
|
@ -202,7 +200,7 @@ void verify_filename(const char *prefix,
|
||||||
{
|
{
|
||||||
if (*arg == '-')
|
if (*arg == '-')
|
||||||
die("bad flag '%s' used after filename", arg);
|
die("bad flag '%s' used after filename", arg);
|
||||||
if (check_filename(prefix, arg))
|
if (check_filename(prefix, arg) || !no_wildcard(arg))
|
||||||
return;
|
return;
|
||||||
die_verify_filename(prefix, arg, diagnose_misspelt_rev);
|
die_verify_filename(prefix, arg, diagnose_misspelt_rev);
|
||||||
}
|
}
|
||||||
|
|
|
@ -882,12 +882,12 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
|
||||||
|
|
||||||
if (prefix[0] == '!') {
|
if (prefix[0] == '!') {
|
||||||
if (prefix[1] != '!')
|
if (prefix[1] != '!')
|
||||||
die ("Invalid search pattern: %s", prefix);
|
return -1;
|
||||||
prefix++;
|
prefix++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (regcomp(®ex, prefix, REG_EXTENDED))
|
if (regcomp(®ex, prefix, REG_EXTENDED))
|
||||||
die("Invalid search pattern: %s", prefix);
|
return -1;
|
||||||
|
|
||||||
for (l = list; l; l = l->next) {
|
for (l = list; l; l = l->next) {
|
||||||
l->item->object.flags |= ONELINE_SEEN;
|
l->item->object.flags |= ONELINE_SEEN;
|
||||||
|
|
|
@ -56,30 +56,4 @@ test_expect_success VAGUENESS_SUCCESS 'checkout reports switch to branch' '
|
||||||
test_i18ngrep ! "^HEAD is now at" stderr
|
test_i18ngrep ! "^HEAD is now at" stderr
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'wildcard ambiguation, paths win' '
|
|
||||||
git init ambi &&
|
|
||||||
(
|
|
||||||
cd ambi &&
|
|
||||||
echo a >a.c &&
|
|
||||||
git add a.c &&
|
|
||||||
echo b >a.c &&
|
|
||||||
git checkout "*.c" &&
|
|
||||||
echo a >expect &&
|
|
||||||
test_cmp expect a.c
|
|
||||||
)
|
|
||||||
'
|
|
||||||
|
|
||||||
test_expect_success !MINGW 'wildcard ambiguation, refs lose' '
|
|
||||||
git init ambi2 &&
|
|
||||||
(
|
|
||||||
cd ambi2 &&
|
|
||||||
echo a >"*.c" &&
|
|
||||||
git add . &&
|
|
||||||
test_must_fail git show :"*.c" &&
|
|
||||||
git show :"*.c" -- >actual &&
|
|
||||||
echo a >expect &&
|
|
||||||
test_cmp expect actual
|
|
||||||
)
|
|
||||||
'
|
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
48
t/t6133-pathspec-rev-dwim.sh
Executable file
48
t/t6133-pathspec-rev-dwim.sh
Executable file
|
@ -0,0 +1,48 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='test dwim of revs versus pathspecs in revision parser'
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
test_expect_success 'setup' '
|
||||||
|
test_commit base &&
|
||||||
|
echo content >"br[ack]ets" &&
|
||||||
|
git add . &&
|
||||||
|
test_tick &&
|
||||||
|
git commit -m brackets
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'non-rev wildcard dwims to pathspec' '
|
||||||
|
git log -- "*.t" >expect &&
|
||||||
|
git log "*.t" >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'tree:path with metacharacters dwims to rev' '
|
||||||
|
git show "HEAD:br[ack]ets" -- >expect &&
|
||||||
|
git show "HEAD:br[ack]ets" >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success '^{foo} with metacharacters dwims to rev' '
|
||||||
|
git log "HEAD^{/b.*}" -- >expect &&
|
||||||
|
git log "HEAD^{/b.*}" >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success '@{foo} with metacharacters dwims to rev' '
|
||||||
|
git log "HEAD@{now [or thereabouts]}" -- >expect &&
|
||||||
|
git log "HEAD@{now [or thereabouts]}" >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success ':/*.t from a subdir dwims to a pathspec' '
|
||||||
|
mkdir subdir &&
|
||||||
|
(
|
||||||
|
cd subdir &&
|
||||||
|
git log -- ":/*.t" >expect &&
|
||||||
|
git log ":/*.t" >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_done
|
Loading…
Reference in a new issue