3 test_description
='restore --pathspec-from-file'
5 TEST_PASSES_SANITIZE_LEAK
=true
10 test_expect_success setup
'
19 git add dir1 fileA.t fileB.t fileC.t fileD.t &&
20 git commit -m "files 1" &&
27 git add dir1 fileA.t fileB.t fileC.t fileD.t &&
28 git commit -m "files 2" &&
33 restore_checkpoint
() {
34 git
reset --hard checkpoint
38 git status
--porcelain --untracked-files=no
-- dir1 fileA.t fileB.t fileC.t fileD.t
>actual
&&
39 test_cmp expect actual
42 test_expect_success
'--pathspec-from-file from stdin' '
45 echo fileA.t | git restore --pathspec-from-file=- --source=HEAD^1 &&
47 cat >expect <<-\EOF &&
53 test_expect_success
'--pathspec-from-file from file' '
57 git restore --pathspec-from-file=list --source=HEAD^1 &&
59 cat >expect <<-\EOF &&
65 test_expect_success
'NUL delimiters' '
68 printf "fileA.t\0fileB.t\0" | git restore --pathspec-from-file=- --pathspec-file-nul --source=HEAD^1 &&
70 cat >expect <<-\EOF &&
77 test_expect_success
'LF delimiters' '
80 printf "fileA.t\nfileB.t\n" | git restore --pathspec-from-file=- --source=HEAD^1 &&
82 cat >expect <<-\EOF &&
89 test_expect_success
'no trailing delimiter' '
92 printf "fileA.t\nfileB.t" | git restore --pathspec-from-file=- --source=HEAD^1 &&
94 cat >expect <<-\EOF &&
101 test_expect_success
'CRLF delimiters' '
102 restore_checkpoint &&
104 printf "fileA.t\r\nfileB.t\r\n" | git restore --pathspec-from-file=- --source=HEAD^1 &&
106 cat >expect <<-\EOF &&
113 test_expect_success
'quotes' '
114 restore_checkpoint &&
120 git restore --pathspec-from-file=list --source=HEAD^1 &&
122 cat >expect <<-\EOF &&
128 test_expect_success
'quotes not compatible with --pathspec-file-nul' '
129 restore_checkpoint &&
135 test_must_fail git restore --pathspec-from-file=list --pathspec-file-nul --source=HEAD^1
138 test_expect_success
'only touches what was listed' '
139 restore_checkpoint &&
141 printf "fileB.t\nfileC.t\n" | git restore --pathspec-from-file=- --source=HEAD^1 &&
143 cat >expect <<-\EOF &&
150 test_expect_success
'error conditions' '
151 restore_checkpoint &&
152 echo fileA.t >list &&
155 test_must_fail git restore --pathspec-from-file=list --patch --source=HEAD^1 2>err &&
156 test_grep -e "options .--pathspec-from-file. and .--patch. cannot be used together" err &&
158 test_must_fail git restore --pathspec-from-file=list --source=HEAD^1 -- fileA.t 2>err &&
159 test_grep -e ".--pathspec-from-file. and pathspec arguments cannot be used together" err &&
161 test_must_fail git restore --pathspec-file-nul --source=HEAD^1 2>err &&
162 test_grep -e "the option .--pathspec-file-nul. requires .--pathspec-from-file." err &&
164 test_must_fail git restore --pathspec-from-file=empty_list --source=HEAD^1 2>err &&
165 test_grep -e "you must specify path(s) to restore" err
168 test_expect_success
'wildcard pathspec matches file in subdirectory' '
169 restore_checkpoint &&
171 echo "*file" | git restore --pathspec-from-file=- --source=HEAD^1 &&
172 cat >expect <<-\EOF &&