]>
Commit | Line | Data |
---|---|---|
a9aecc7a AM |
1 | #!/bin/sh |
2 | ||
3 | test_description='restore --pathspec-from-file' | |
4 | ||
2f64da07 | 5 | TEST_PASSES_SANITIZE_LEAK=true |
a9aecc7a AM |
6 | . ./test-lib.sh |
7 | ||
8 | test_tick | |
9 | ||
10 | test_expect_success setup ' | |
11 | test_commit file0 && | |
12 | ||
bfda204a RS |
13 | mkdir dir1 && |
14 | echo 1 >dir1/file && | |
a9aecc7a AM |
15 | echo 1 >fileA.t && |
16 | echo 1 >fileB.t && | |
17 | echo 1 >fileC.t && | |
18 | echo 1 >fileD.t && | |
bfda204a | 19 | git add dir1 fileA.t fileB.t fileC.t fileD.t && |
a9aecc7a AM |
20 | git commit -m "files 1" && |
21 | ||
bfda204a | 22 | echo 2 >dir1/file && |
a9aecc7a AM |
23 | echo 2 >fileA.t && |
24 | echo 2 >fileB.t && | |
25 | echo 2 >fileC.t && | |
26 | echo 2 >fileD.t && | |
bfda204a | 27 | git add dir1 fileA.t fileB.t fileC.t fileD.t && |
a9aecc7a AM |
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 () { | |
bfda204a | 38 | git status --porcelain --untracked-files=no -- dir1 fileA.t fileB.t fileC.t fileD.t >actual && |
a9aecc7a AM |
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 | ||
568cabb2 AM |
116 | cat >list <<-\EOF && |
117 | "file\101.t" | |
118 | EOF | |
119 | ||
120 | git restore --pathspec-from-file=list --source=HEAD^1 && | |
a9aecc7a AM |
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 | ||
568cabb2 AM |
131 | cat >list <<-\EOF && |
132 | "file\101.t" | |
133 | EOF | |
134 | ||
a9aecc7a AM |
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 | ||
f94f7bd0 AM |
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 && | |
6789275d | 156 | test_grep -e "options .--pathspec-from-file. and .--patch. cannot be used together" err && |
f94f7bd0 AM |
157 | |
158 | test_must_fail git restore --pathspec-from-file=list --source=HEAD^1 -- fileA.t 2>err && | |
6789275d | 159 | test_grep -e ".--pathspec-from-file. and pathspec arguments cannot be used together" err && |
f94f7bd0 AM |
160 | |
161 | test_must_fail git restore --pathspec-file-nul --source=HEAD^1 2>err && | |
6789275d | 162 | test_grep -e "the option .--pathspec-file-nul. requires .--pathspec-from-file." err && |
f94f7bd0 AM |
163 | |
164 | test_must_fail git restore --pathspec-from-file=empty_list --source=HEAD^1 2>err && | |
6789275d | 165 | test_grep -e "you must specify path(s) to restore" err |
f94f7bd0 AM |
166 | ' |
167 | ||
bfda204a RS |
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 | ||
a9aecc7a | 178 | test_done |