]>
Commit | Line | Data |
---|---|---|
a9aecc7a AM |
1 | #!/bin/sh |
2 | ||
3 | test_description='restore --pathspec-from-file' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_tick | |
8 | ||
9 | test_expect_success setup ' | |
10 | test_commit file0 && | |
11 | ||
bfda204a RS |
12 | mkdir dir1 && |
13 | echo 1 >dir1/file && | |
a9aecc7a AM |
14 | echo 1 >fileA.t && |
15 | echo 1 >fileB.t && | |
16 | echo 1 >fileC.t && | |
17 | echo 1 >fileD.t && | |
bfda204a | 18 | git add dir1 fileA.t fileB.t fileC.t fileD.t && |
a9aecc7a AM |
19 | git commit -m "files 1" && |
20 | ||
bfda204a | 21 | echo 2 >dir1/file && |
a9aecc7a AM |
22 | echo 2 >fileA.t && |
23 | echo 2 >fileB.t && | |
24 | echo 2 >fileC.t && | |
25 | echo 2 >fileD.t && | |
bfda204a | 26 | git add dir1 fileA.t fileB.t fileC.t fileD.t && |
a9aecc7a AM |
27 | git commit -m "files 2" && |
28 | ||
29 | git tag checkpoint | |
30 | ' | |
31 | ||
32 | restore_checkpoint () { | |
33 | git reset --hard checkpoint | |
34 | } | |
35 | ||
36 | verify_expect () { | |
bfda204a | 37 | git status --porcelain --untracked-files=no -- dir1 fileA.t fileB.t fileC.t fileD.t >actual && |
a9aecc7a AM |
38 | test_cmp expect actual |
39 | } | |
40 | ||
41 | test_expect_success '--pathspec-from-file from stdin' ' | |
42 | restore_checkpoint && | |
43 | ||
44 | echo fileA.t | git restore --pathspec-from-file=- --source=HEAD^1 && | |
45 | ||
46 | cat >expect <<-\EOF && | |
47 | M fileA.t | |
48 | EOF | |
49 | verify_expect | |
50 | ' | |
51 | ||
52 | test_expect_success '--pathspec-from-file from file' ' | |
53 | restore_checkpoint && | |
54 | ||
55 | echo fileA.t >list && | |
56 | git restore --pathspec-from-file=list --source=HEAD^1 && | |
57 | ||
58 | cat >expect <<-\EOF && | |
59 | M fileA.t | |
60 | EOF | |
61 | verify_expect | |
62 | ' | |
63 | ||
64 | test_expect_success 'NUL delimiters' ' | |
65 | restore_checkpoint && | |
66 | ||
67 | printf "fileA.t\0fileB.t\0" | git restore --pathspec-from-file=- --pathspec-file-nul --source=HEAD^1 && | |
68 | ||
69 | cat >expect <<-\EOF && | |
70 | M fileA.t | |
71 | M fileB.t | |
72 | EOF | |
73 | verify_expect | |
74 | ' | |
75 | ||
76 | test_expect_success 'LF delimiters' ' | |
77 | restore_checkpoint && | |
78 | ||
79 | printf "fileA.t\nfileB.t\n" | git restore --pathspec-from-file=- --source=HEAD^1 && | |
80 | ||
81 | cat >expect <<-\EOF && | |
82 | M fileA.t | |
83 | M fileB.t | |
84 | EOF | |
85 | verify_expect | |
86 | ' | |
87 | ||
88 | test_expect_success 'no trailing delimiter' ' | |
89 | restore_checkpoint && | |
90 | ||
91 | printf "fileA.t\nfileB.t" | git restore --pathspec-from-file=- --source=HEAD^1 && | |
92 | ||
93 | cat >expect <<-\EOF && | |
94 | M fileA.t | |
95 | M fileB.t | |
96 | EOF | |
97 | verify_expect | |
98 | ' | |
99 | ||
100 | test_expect_success 'CRLF delimiters' ' | |
101 | restore_checkpoint && | |
102 | ||
103 | printf "fileA.t\r\nfileB.t\r\n" | git restore --pathspec-from-file=- --source=HEAD^1 && | |
104 | ||
105 | cat >expect <<-\EOF && | |
106 | M fileA.t | |
107 | M fileB.t | |
108 | EOF | |
109 | verify_expect | |
110 | ' | |
111 | ||
112 | test_expect_success 'quotes' ' | |
113 | restore_checkpoint && | |
114 | ||
568cabb2 AM |
115 | cat >list <<-\EOF && |
116 | "file\101.t" | |
117 | EOF | |
118 | ||
119 | git restore --pathspec-from-file=list --source=HEAD^1 && | |
a9aecc7a AM |
120 | |
121 | cat >expect <<-\EOF && | |
122 | M fileA.t | |
123 | EOF | |
124 | verify_expect | |
125 | ' | |
126 | ||
127 | test_expect_success 'quotes not compatible with --pathspec-file-nul' ' | |
128 | restore_checkpoint && | |
129 | ||
568cabb2 AM |
130 | cat >list <<-\EOF && |
131 | "file\101.t" | |
132 | EOF | |
133 | ||
a9aecc7a AM |
134 | test_must_fail git restore --pathspec-from-file=list --pathspec-file-nul --source=HEAD^1 |
135 | ' | |
136 | ||
137 | test_expect_success 'only touches what was listed' ' | |
138 | restore_checkpoint && | |
139 | ||
140 | printf "fileB.t\nfileC.t\n" | git restore --pathspec-from-file=- --source=HEAD^1 && | |
141 | ||
142 | cat >expect <<-\EOF && | |
143 | M fileB.t | |
144 | M fileC.t | |
145 | EOF | |
146 | verify_expect | |
147 | ' | |
148 | ||
f94f7bd0 AM |
149 | test_expect_success 'error conditions' ' |
150 | restore_checkpoint && | |
151 | echo fileA.t >list && | |
152 | >empty_list && | |
153 | ||
154 | test_must_fail git restore --pathspec-from-file=list --patch --source=HEAD^1 2>err && | |
6789275d | 155 | test_grep -e "options .--pathspec-from-file. and .--patch. cannot be used together" err && |
f94f7bd0 AM |
156 | |
157 | test_must_fail git restore --pathspec-from-file=list --source=HEAD^1 -- fileA.t 2>err && | |
6789275d | 158 | test_grep -e ".--pathspec-from-file. and pathspec arguments cannot be used together" err && |
f94f7bd0 AM |
159 | |
160 | test_must_fail git restore --pathspec-file-nul --source=HEAD^1 2>err && | |
6789275d | 161 | test_grep -e "the option .--pathspec-file-nul. requires .--pathspec-from-file." err && |
f94f7bd0 AM |
162 | |
163 | test_must_fail git restore --pathspec-from-file=empty_list --source=HEAD^1 2>err && | |
6789275d | 164 | test_grep -e "you must specify path(s) to restore" err |
f94f7bd0 AM |
165 | ' |
166 | ||
bfda204a RS |
167 | test_expect_success 'wildcard pathspec matches file in subdirectory' ' |
168 | restore_checkpoint && | |
169 | ||
170 | echo "*file" | git restore --pathspec-from-file=- --source=HEAD^1 && | |
171 | cat >expect <<-\EOF && | |
172 | M dir1/file | |
173 | EOF | |
174 | verify_expect | |
175 | ' | |
176 | ||
a9aecc7a | 177 | test_done |