Merge branch 'rs/checkout-no-overlay-pathspec-fix'

"git restore/checkout --no-overlay" with wildcarded pathspec
mistakenly removed matching paths in subdirectories, which has been
corrected.

* rs/checkout-no-overlay-pathspec-fix:
  checkout, restore: make pathspec recursive
This commit is contained in:
Junio C Hamano 2020-08-31 15:49:50 -07:00
commit c57afd73ef
3 changed files with 30 additions and 3 deletions

View File

@ -1709,6 +1709,8 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
die(_("--pathspec-file-nul requires --pathspec-from-file"));
}
opts->pathspec.recursive = 1;
if (opts->pathspec.nr) {
if (1 < !!opts->writeout_stage + !!opts->force + !!opts->merge)
die(_("git checkout: --ours/--theirs, --force and --merge are incompatible when\n"

View File

@ -44,4 +44,16 @@ test_expect_success '--no-overlay --theirs with D/F conflict deletes file' '
test_path_is_missing file1
'
test_expect_success 'wildcard pathspec matches file in subdirectory' '
git reset --hard &&
mkdir subdir &&
test_commit file3-1 subdir/file3 &&
test_commit file3-2 subdir/file3 &&
git checkout --no-overlay file3-1 "*file3" &&
echo file3-1 >expect &&
test_path_is_file subdir/file3 &&
test_cmp expect subdir/file3
'
test_done

View File

@ -9,18 +9,21 @@ test_tick
test_expect_success setup '
test_commit file0 &&
mkdir dir1 &&
echo 1 >dir1/file &&
echo 1 >fileA.t &&
echo 1 >fileB.t &&
echo 1 >fileC.t &&
echo 1 >fileD.t &&
git add fileA.t fileB.t fileC.t fileD.t &&
git add dir1 fileA.t fileB.t fileC.t fileD.t &&
git commit -m "files 1" &&
echo 2 >dir1/file &&
echo 2 >fileA.t &&
echo 2 >fileB.t &&
echo 2 >fileC.t &&
echo 2 >fileD.t &&
git add fileA.t fileB.t fileC.t fileD.t &&
git add dir1 fileA.t fileB.t fileC.t fileD.t &&
git commit -m "files 2" &&
git tag checkpoint
@ -31,7 +34,7 @@ restore_checkpoint () {
}
verify_expect () {
git status --porcelain --untracked-files=no -- fileA.t fileB.t fileC.t fileD.t >actual &&
git status --porcelain --untracked-files=no -- dir1 fileA.t fileB.t fileC.t fileD.t >actual &&
test_cmp expect actual
}
@ -161,4 +164,14 @@ test_expect_success 'error conditions' '
test_i18ngrep -e "you must specify path(s) to restore" err
'
test_expect_success 'wildcard pathspec matches file in subdirectory' '
restore_checkpoint &&
echo "*file" | git restore --pathspec-from-file=- --source=HEAD^1 &&
cat >expect <<-\EOF &&
M dir1/file
EOF
verify_expect
'
test_done