Merge branch 'jc/all-negative-pathspec'
A git subcommand like "git add -p" spawns a separate git process while relaying its command line arguments. A pathspec with only negative elements was mistakenly passed with an empty string, which has been corrected. * jc/all-negative-pathspec: pathspec: correct an empty string used as a pathspec elementmaint
commit
f00809500f
|
@ -629,7 +629,7 @@ void parse_pathspec(struct pathspec *pathspec,
|
||||||
*/
|
*/
|
||||||
if (nr_exclude == n) {
|
if (nr_exclude == n) {
|
||||||
int plen = (!(flags & PATHSPEC_PREFER_CWD)) ? 0 : prefixlen;
|
int plen = (!(flags & PATHSPEC_PREFER_CWD)) ? 0 : prefixlen;
|
||||||
init_pathspec_item(item + n, 0, prefix, plen, "");
|
init_pathspec_item(item + n, 0, prefix, plen, ".");
|
||||||
pathspec->nr++;
|
pathspec->nr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -195,6 +195,7 @@ test_expect_success 'multiple exclusions' '
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 't_e_i() exclude case #8' '
|
test_expect_success 't_e_i() exclude case #8' '
|
||||||
|
test_when_finished "rm -fr case8" &&
|
||||||
git init case8 &&
|
git init case8 &&
|
||||||
(
|
(
|
||||||
cd case8 &&
|
cd case8 &&
|
||||||
|
@ -244,4 +245,184 @@ test_expect_success 'grep --untracked PATTERN :(exclude)*FILE' '
|
||||||
test_cmp expect-grep actual-grep
|
test_cmp expect-grep actual-grep
|
||||||
'
|
'
|
||||||
|
|
||||||
|
# Depending on the command, all negative pathspec needs to subtract
|
||||||
|
# either from the full tree, or from the current directory.
|
||||||
|
#
|
||||||
|
# The sample tree checked out at this point has:
|
||||||
|
# file
|
||||||
|
# sub/file
|
||||||
|
# sub/file2
|
||||||
|
# sub/sub/file
|
||||||
|
# sub/sub/sub/file
|
||||||
|
# sub2/file
|
||||||
|
#
|
||||||
|
# but there may also be some cruft that interferes with "git clean"
|
||||||
|
# and "git add" tests.
|
||||||
|
|
||||||
|
test_expect_success 'archive with all negative' '
|
||||||
|
git reset --hard &&
|
||||||
|
git clean -f &&
|
||||||
|
git -C sub archive --format=tar HEAD -- ":!sub/" >archive &&
|
||||||
|
"$TAR" tf archive >actual &&
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
file
|
||||||
|
file2
|
||||||
|
EOF
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'add with all negative' '
|
||||||
|
H=$(git rev-parse HEAD) &&
|
||||||
|
git reset --hard $H &&
|
||||||
|
git clean -f &&
|
||||||
|
test_when_finished "git reset --hard $H" &&
|
||||||
|
for path in file sub/file sub/sub/file sub2/file
|
||||||
|
do
|
||||||
|
echo smudge >>"$path" || return 1
|
||||||
|
done &&
|
||||||
|
git -C sub add -- ":!sub/" &&
|
||||||
|
git diff --name-only --no-renames --cached >actual &&
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
file
|
||||||
|
sub/file
|
||||||
|
sub2/file
|
||||||
|
EOF
|
||||||
|
test_cmp expect actual &&
|
||||||
|
git diff --name-only --no-renames >actual &&
|
||||||
|
echo sub/sub/file >expect &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'add -p with all negative' '
|
||||||
|
H=$(git rev-parse HEAD) &&
|
||||||
|
git reset --hard $H &&
|
||||||
|
git clean -f &&
|
||||||
|
test_when_finished "git reset --hard $H" &&
|
||||||
|
for path in file sub/file sub/sub/file sub2/file
|
||||||
|
do
|
||||||
|
echo smudge >>"$path" || return 1
|
||||||
|
done &&
|
||||||
|
yes | git -C sub add -p -- ":!sub/" &&
|
||||||
|
git diff --name-only --no-renames --cached >actual &&
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
file
|
||||||
|
sub/file
|
||||||
|
sub2/file
|
||||||
|
EOF
|
||||||
|
test_cmp expect actual &&
|
||||||
|
git diff --name-only --no-renames >actual &&
|
||||||
|
echo sub/sub/file >expect &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'clean with all negative' '
|
||||||
|
H=$(git rev-parse HEAD) &&
|
||||||
|
git reset --hard $H &&
|
||||||
|
test_when_finished "git reset --hard $H && git clean -f" &&
|
||||||
|
git clean -f &&
|
||||||
|
for path in file9 sub/file9 sub/sub/file9 sub2/file9
|
||||||
|
do
|
||||||
|
echo cruft >"$path" || return 1
|
||||||
|
done &&
|
||||||
|
git -C sub clean -f -- ":!sub" &&
|
||||||
|
test_path_is_file file9 &&
|
||||||
|
test_path_is_missing sub/file9 &&
|
||||||
|
test_path_is_file sub/sub/file9 &&
|
||||||
|
test_path_is_file sub2/file9
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'commit with all negative' '
|
||||||
|
H=$(git rev-parse HEAD) &&
|
||||||
|
git reset --hard $H &&
|
||||||
|
test_when_finished "git reset --hard $H" &&
|
||||||
|
for path in file sub/file sub/sub/file sub2/file
|
||||||
|
do
|
||||||
|
echo smudge >>"$path" || return 1
|
||||||
|
done &&
|
||||||
|
git -C sub commit -m sample -- ":!sub/" &&
|
||||||
|
git diff --name-only --no-renames HEAD^ HEAD >actual &&
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
file
|
||||||
|
sub/file
|
||||||
|
sub2/file
|
||||||
|
EOF
|
||||||
|
test_cmp expect actual &&
|
||||||
|
git diff --name-only --no-renames HEAD >actual &&
|
||||||
|
echo sub/sub/file >expect &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'reset with all negative' '
|
||||||
|
H=$(git rev-parse HEAD) &&
|
||||||
|
git reset --hard $H &&
|
||||||
|
test_when_finished "git reset --hard $H" &&
|
||||||
|
for path in file sub/file sub/sub/file sub2/file
|
||||||
|
do
|
||||||
|
echo smudge >>"$path" &&
|
||||||
|
git add "$path" || return 1
|
||||||
|
done &&
|
||||||
|
git -C sub reset --quiet -- ":!sub/" &&
|
||||||
|
git diff --name-only --no-renames --cached >actual &&
|
||||||
|
echo sub/sub/file >expect &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'grep with all negative' '
|
||||||
|
H=$(git rev-parse HEAD) &&
|
||||||
|
git reset --hard $H &&
|
||||||
|
test_when_finished "git reset --hard $H" &&
|
||||||
|
for path in file sub/file sub/sub/file sub2/file
|
||||||
|
do
|
||||||
|
echo "needle $path" >>"$path" || return 1
|
||||||
|
done &&
|
||||||
|
git -C sub grep -h needle -- ":!sub/" >actual &&
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
needle sub/file
|
||||||
|
EOF
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'ls-files with all negative' '
|
||||||
|
git reset --hard &&
|
||||||
|
git -C sub ls-files -- ":!sub/" >actual &&
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
file
|
||||||
|
file2
|
||||||
|
EOF
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'rm with all negative' '
|
||||||
|
git reset --hard &&
|
||||||
|
test_when_finished "git reset --hard" &&
|
||||||
|
git -C sub rm -r --cached -- ":!sub/" >actual &&
|
||||||
|
git diff --name-only --no-renames --diff-filter=D --cached >actual &&
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
sub/file
|
||||||
|
sub/file2
|
||||||
|
EOF
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'stash with all negative' '
|
||||||
|
H=$(git rev-parse HEAD) &&
|
||||||
|
git reset --hard $H &&
|
||||||
|
test_when_finished "git reset --hard $H" &&
|
||||||
|
for path in file sub/file sub/sub/file sub2/file
|
||||||
|
do
|
||||||
|
echo smudge >>"$path" || return 1
|
||||||
|
done &&
|
||||||
|
git -C sub stash push -m sample -- ":!sub/" &&
|
||||||
|
git diff --name-only --no-renames HEAD >actual &&
|
||||||
|
echo sub/sub/file >expect &&
|
||||||
|
test_cmp expect actual &&
|
||||||
|
git stash show --name-only >actual &&
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
file
|
||||||
|
sub/file
|
||||||
|
sub2/file
|
||||||
|
EOF
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in New Issue