]> git.ipfire.org Git - thirdparty/git.git/blob - t/t2072-restore-pathspec-file.sh
The third batch
[thirdparty/git.git] / t / t2072-restore-pathspec-file.sh
1 #!/bin/sh
2
3 test_description='restore --pathspec-from-file'
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_tick
9
10 test_expect_success setup '
11 test_commit file0 &&
12
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" &&
21
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" &&
29
30 git tag checkpoint
31 '
32
33 restore_checkpoint () {
34 git reset --hard checkpoint
35 }
36
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
40 }
41
42 test_expect_success '--pathspec-from-file from stdin' '
43 restore_checkpoint &&
44
45 echo fileA.t | git restore --pathspec-from-file=- --source=HEAD^1 &&
46
47 cat >expect <<-\EOF &&
48 M fileA.t
49 EOF
50 verify_expect
51 '
52
53 test_expect_success '--pathspec-from-file from file' '
54 restore_checkpoint &&
55
56 echo fileA.t >list &&
57 git restore --pathspec-from-file=list --source=HEAD^1 &&
58
59 cat >expect <<-\EOF &&
60 M fileA.t
61 EOF
62 verify_expect
63 '
64
65 test_expect_success 'NUL delimiters' '
66 restore_checkpoint &&
67
68 printf "fileA.t\0fileB.t\0" | git restore --pathspec-from-file=- --pathspec-file-nul --source=HEAD^1 &&
69
70 cat >expect <<-\EOF &&
71 M fileA.t
72 M fileB.t
73 EOF
74 verify_expect
75 '
76
77 test_expect_success 'LF delimiters' '
78 restore_checkpoint &&
79
80 printf "fileA.t\nfileB.t\n" | git restore --pathspec-from-file=- --source=HEAD^1 &&
81
82 cat >expect <<-\EOF &&
83 M fileA.t
84 M fileB.t
85 EOF
86 verify_expect
87 '
88
89 test_expect_success 'no trailing delimiter' '
90 restore_checkpoint &&
91
92 printf "fileA.t\nfileB.t" | git restore --pathspec-from-file=- --source=HEAD^1 &&
93
94 cat >expect <<-\EOF &&
95 M fileA.t
96 M fileB.t
97 EOF
98 verify_expect
99 '
100
101 test_expect_success 'CRLF delimiters' '
102 restore_checkpoint &&
103
104 printf "fileA.t\r\nfileB.t\r\n" | git restore --pathspec-from-file=- --source=HEAD^1 &&
105
106 cat >expect <<-\EOF &&
107 M fileA.t
108 M fileB.t
109 EOF
110 verify_expect
111 '
112
113 test_expect_success 'quotes' '
114 restore_checkpoint &&
115
116 cat >list <<-\EOF &&
117 "file\101.t"
118 EOF
119
120 git restore --pathspec-from-file=list --source=HEAD^1 &&
121
122 cat >expect <<-\EOF &&
123 M fileA.t
124 EOF
125 verify_expect
126 '
127
128 test_expect_success 'quotes not compatible with --pathspec-file-nul' '
129 restore_checkpoint &&
130
131 cat >list <<-\EOF &&
132 "file\101.t"
133 EOF
134
135 test_must_fail git restore --pathspec-from-file=list --pathspec-file-nul --source=HEAD^1
136 '
137
138 test_expect_success 'only touches what was listed' '
139 restore_checkpoint &&
140
141 printf "fileB.t\nfileC.t\n" | git restore --pathspec-from-file=- --source=HEAD^1 &&
142
143 cat >expect <<-\EOF &&
144 M fileB.t
145 M fileC.t
146 EOF
147 verify_expect
148 '
149
150 test_expect_success 'error conditions' '
151 restore_checkpoint &&
152 echo fileA.t >list &&
153 >empty_list &&
154
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 &&
157
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 &&
160
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 &&
163
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
166 '
167
168 test_expect_success 'wildcard pathspec matches file in subdirectory' '
169 restore_checkpoint &&
170
171 echo "*file" | git restore --pathspec-from-file=- --source=HEAD^1 &&
172 cat >expect <<-\EOF &&
173 M dir1/file
174 EOF
175 verify_expect
176 '
177
178 test_done