Merge branch 'kz/merge-fail-early-upon-refresh-failure'
[git.git] / t / t2072-restore-pathspec-file.sh
blob86c9c887881b94a586dc96b3f495a72c022fd827
1 #!/bin/sh
3 test_description='restore --pathspec-from-file'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_tick
10 test_expect_success setup '
11 test_commit file0 &&
13 mkdir dir1 &&
14 echo 1 >dir1/file &&
15 echo 1 >fileA.t &&
16 echo 1 >fileB.t &&
17 echo 1 >fileC.t &&
18 echo 1 >fileD.t &&
19 git add dir1 fileA.t fileB.t fileC.t fileD.t &&
20 git commit -m "files 1" &&
22 echo 2 >dir1/file &&
23 echo 2 >fileA.t &&
24 echo 2 >fileB.t &&
25 echo 2 >fileC.t &&
26 echo 2 >fileD.t &&
27 git add dir1 fileA.t fileB.t fileC.t fileD.t &&
28 git commit -m "files 2" &&
30 git tag checkpoint
33 restore_checkpoint () {
34 git reset --hard checkpoint
37 verify_expect () {
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' '
43 restore_checkpoint &&
45 echo fileA.t | git restore --pathspec-from-file=- --source=HEAD^1 &&
47 cat >expect <<-\EOF &&
48 M fileA.t
49 EOF
50 verify_expect
53 test_expect_success '--pathspec-from-file from file' '
54 restore_checkpoint &&
56 echo fileA.t >list &&
57 git restore --pathspec-from-file=list --source=HEAD^1 &&
59 cat >expect <<-\EOF &&
60 M fileA.t
61 EOF
62 verify_expect
65 test_expect_success 'NUL delimiters' '
66 restore_checkpoint &&
68 printf "fileA.t\0fileB.t\0" | git restore --pathspec-from-file=- --pathspec-file-nul --source=HEAD^1 &&
70 cat >expect <<-\EOF &&
71 M fileA.t
72 M fileB.t
73 EOF
74 verify_expect
77 test_expect_success 'LF delimiters' '
78 restore_checkpoint &&
80 printf "fileA.t\nfileB.t\n" | git restore --pathspec-from-file=- --source=HEAD^1 &&
82 cat >expect <<-\EOF &&
83 M fileA.t
84 M fileB.t
85 EOF
86 verify_expect
89 test_expect_success 'no trailing delimiter' '
90 restore_checkpoint &&
92 printf "fileA.t\nfileB.t" | git restore --pathspec-from-file=- --source=HEAD^1 &&
94 cat >expect <<-\EOF &&
95 M fileA.t
96 M fileB.t
97 EOF
98 verify_expect
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 &&
107 M fileA.t
108 M fileB.t
110 verify_expect
113 test_expect_success 'quotes' '
114 restore_checkpoint &&
116 cat >list <<-\EOF &&
117 "file\101.t"
120 git restore --pathspec-from-file=list --source=HEAD^1 &&
122 cat >expect <<-\EOF &&
123 M fileA.t
125 verify_expect
128 test_expect_success 'quotes not compatible with --pathspec-file-nul' '
129 restore_checkpoint &&
131 cat >list <<-\EOF &&
132 "file\101.t"
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 &&
144 M fileB.t
145 M fileC.t
147 verify_expect
150 test_expect_success 'error conditions' '
151 restore_checkpoint &&
152 echo fileA.t >list &&
153 >empty_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 &&
173 M dir1/file
175 verify_expect
178 test_done