]> git.ipfire.org Git - thirdparty/git.git/blob - t/t9815-git-p4-submit-fail.sh
1823cff12bf6b4b3a037a56632494c14de349ca5
[thirdparty/git.git] / t / t9815-git-p4-submit-fail.sh
1 #!/bin/sh
2
3 test_description='git p4 submit failure handling'
4
5 . ./lib-git-p4.sh
6
7 test_expect_success 'start p4d' '
8 start_p4d
9 '
10
11 test_expect_success 'init depot' '
12 (
13 cd "$cli" &&
14 p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
15 echo line1 >file1 &&
16 p4 add file1 &&
17 p4 submit -d "line1 in file1"
18 )
19 '
20
21 test_expect_success 'conflict on one commit' '
22 test_when_finished cleanup_git &&
23 git p4 clone --dest="$git" //depot &&
24 (
25 cd "$cli" &&
26 p4 open file1 &&
27 echo line2 >>file1 &&
28 p4 submit -d "line2 in file1"
29 ) &&
30 (
31 # now this commit should cause a conflict
32 cd "$git" &&
33 git config git-p4.skipSubmitEdit true &&
34 echo line3 >>file1 &&
35 git add file1 &&
36 git commit -m "line3 in file1 will conflict" &&
37 test_expect_code 1 git p4 submit >out &&
38 test_i18ngrep "No commits applied" out
39 )
40 '
41
42 test_expect_success 'conflict on second of two commits' '
43 test_when_finished cleanup_git &&
44 git p4 clone --dest="$git" //depot &&
45 (
46 cd "$cli" &&
47 p4 open file1 &&
48 echo line3 >>file1 &&
49 p4 submit -d "line3 in file1"
50 ) &&
51 (
52 cd "$git" &&
53 git config git-p4.skipSubmitEdit true &&
54 # this commit is okay
55 test_commit "first_commit_okay" &&
56 # now this submit should cause a conflict
57 echo line4 >>file1 &&
58 git add file1 &&
59 git commit -m "line4 in file1 will conflict" &&
60 test_expect_code 1 git p4 submit >out &&
61 test_i18ngrep "Applied only the commits" out
62 )
63 '
64
65 test_expect_success 'conflict on first of two commits, skip' '
66 test_when_finished cleanup_git &&
67 git p4 clone --dest="$git" //depot &&
68 (
69 cd "$cli" &&
70 p4 open file1 &&
71 echo line4 >>file1 &&
72 p4 submit -d "line4 in file1"
73 ) &&
74 (
75 cd "$git" &&
76 git config git-p4.skipSubmitEdit true &&
77 # this submit should cause a conflict
78 echo line5 >>file1 &&
79 git add file1 &&
80 git commit -m "line5 in file1 will conflict" &&
81 # but this commit is okay
82 test_commit "okay_commit_after_skip" &&
83 echo s | test_expect_code 1 git p4 submit >out &&
84 test_i18ngrep "Applied only the commits" out
85 )
86 '
87
88 test_expect_success 'conflict on first of two commits, quit' '
89 test_when_finished cleanup_git &&
90 git p4 clone --dest="$git" //depot &&
91 (
92 cd "$cli" &&
93 p4 open file1 &&
94 echo line7 >>file1 &&
95 p4 submit -d "line7 in file1"
96 ) &&
97 (
98 cd "$git" &&
99 git config git-p4.skipSubmitEdit true &&
100 # this submit should cause a conflict
101 echo line8 >>file1 &&
102 git add file1 &&
103 git commit -m "line8 in file1 will conflict" &&
104 # but this commit is okay
105 test_commit "okay_commit_after_quit" &&
106 echo q | test_expect_code 1 git p4 submit >out &&
107 test_i18ngrep "No commits applied" out
108 )
109 '
110
111 #
112 # Cleanup after submit fail, all cases. Some modifications happen
113 # before trying to apply the patch. Make sure these are unwound
114 # properly. Put each one in a diff along with something that will
115 # obviously conflict. Make sure it is back to normal after.
116 #
117
118 test_expect_success 'cleanup edit p4 populate' '
119 (
120 cd "$cli" &&
121 echo text file >text &&
122 p4 add text &&
123 echo text+x file >text+x &&
124 chmod 755 text+x &&
125 p4 add text+x &&
126 p4 submit -d "populate p4"
127 )
128 '
129
130 setup_conflict() {
131 # clone before modifying file1 to force it to conflict
132 test_when_finished cleanup_git &&
133 git p4 clone --dest="$git" //depot &&
134 # ticks outside subshells
135 test_tick &&
136 (
137 cd "$cli" &&
138 p4 open file1 &&
139 echo $test_tick >>file1 &&
140 p4 submit -d "$test_tick in file1"
141 ) &&
142 test_tick &&
143 (
144 cd "$git" &&
145 git config git-p4.skipSubmitEdit true &&
146 # easy conflict
147 echo $test_tick >>file1 &&
148 git add file1
149 # caller will add more and submit
150 )
151 }
152
153 test_expect_success 'cleanup edit after submit fail' '
154 setup_conflict &&
155 (
156 cd "$git" &&
157 echo another line >>text &&
158 git add text &&
159 git commit -m "conflict" &&
160 test_expect_code 1 git p4 submit
161 ) &&
162 (
163 cd "$cli" &&
164 # make sure it is not open
165 ! p4 fstat -T action text
166 )
167 '
168
169 test_expect_success 'cleanup add after submit fail' '
170 setup_conflict &&
171 (
172 cd "$git" &&
173 echo new file >textnew &&
174 git add textnew &&
175 git commit -m "conflict" &&
176 test_expect_code 1 git p4 submit
177 ) &&
178 (
179 cd "$cli" &&
180 # make sure it is not there
181 # and that p4 thinks it is not added
182 # P4 returns 0 both for "not there but added" and
183 # "not there", so grep.
184 test_path_is_missing textnew &&
185 p4 fstat -T action textnew 2>&1 | grep "no such file"
186 )
187 '
188
189 test_expect_success 'cleanup delete after submit fail' '
190 setup_conflict &&
191 (
192 cd "$git" &&
193 git rm text+x &&
194 git commit -m "conflict" &&
195 test_expect_code 1 git p4 submit
196 ) &&
197 (
198 cd "$cli" &&
199 # make sure it is there
200 test_path_is_file text+x &&
201 ! p4 fstat -T action text+x
202 )
203 '
204
205 test_expect_success 'cleanup copy after submit fail' '
206 setup_conflict &&
207 (
208 cd "$git" &&
209 cp text text2 &&
210 git add text2 &&
211 git commit -m "conflict" &&
212 git config git-p4.detectCopies true &&
213 git config git-p4.detectCopiesHarder true &&
214 # make sure setup is okay
215 git diff-tree -r -C --find-copies-harder HEAD | grep text2 | grep C100 &&
216 test_expect_code 1 git p4 submit
217 ) &&
218 (
219 cd "$cli" &&
220 test_path_is_missing text2 &&
221 p4 fstat -T action text2 2>&1 | grep "no such file"
222 )
223 '
224
225 test_expect_success 'cleanup rename after submit fail' '
226 setup_conflict &&
227 (
228 cd "$git" &&
229 git mv text text2 &&
230 git commit -m "conflict" &&
231 git config git-p4.detectRenames true &&
232 # make sure setup is okay
233 git diff-tree -r -M HEAD | grep text2 | grep R100 &&
234 test_expect_code 1 git p4 submit
235 ) &&
236 (
237 cd "$cli" &&
238 test_path_is_missing text2 &&
239 p4 fstat -T action text2 2>&1 | grep "no such file"
240 )
241 '
242
243 #
244 # Cleanup after deciding not to submit during editTemplate. This
245 # involves unwinding more work, because files have been added, deleted
246 # and chmod-ed now. Same approach as above.
247 #
248
249 test_expect_success 'cleanup edit after submit cancel' '
250 test_when_finished cleanup_git &&
251 git p4 clone --dest="$git" //depot &&
252 (
253 cd "$git" &&
254 echo line >>text &&
255 git add text &&
256 git commit -m text &&
257 echo n | test_expect_code 1 git p4 submit &&
258 git reset --hard HEAD^
259 ) &&
260 (
261 cd "$cli" &&
262 ! p4 fstat -T action text &&
263 test_cmp "$git"/text text
264 )
265 '
266
267 test_expect_success 'cleanup add after submit cancel' '
268 test_when_finished cleanup_git &&
269 git p4 clone --dest="$git" //depot &&
270 (
271 cd "$git" &&
272 echo line >textnew &&
273 git add textnew &&
274 git commit -m textnew &&
275 echo n | test_expect_code 1 git p4 submit
276 ) &&
277 (
278 cd "$cli" &&
279 test_path_is_missing textnew &&
280 p4 fstat -T action textnew 2>&1 | grep "no such file"
281 )
282 '
283
284 test_expect_success 'cleanup delete after submit cancel' '
285 test_when_finished cleanup_git &&
286 git p4 clone --dest="$git" //depot &&
287 (
288 cd "$git" &&
289 git rm text &&
290 git commit -m "rm text" &&
291 echo n | test_expect_code 1 git p4 submit
292 ) &&
293 (
294 cd "$cli" &&
295 test_path_is_file text &&
296 ! p4 fstat -T action text
297 )
298 '
299
300 test_expect_success 'cleanup copy after submit cancel' '
301 test_when_finished cleanup_git &&
302 git p4 clone --dest="$git" //depot &&
303 (
304 cd "$git" &&
305 cp text text2 &&
306 git add text2 &&
307 git commit -m text2 &&
308 git config git-p4.detectCopies true &&
309 git config git-p4.detectCopiesHarder true &&
310 git diff-tree -r -C --find-copies-harder HEAD | grep text2 | grep C100 &&
311 echo n | test_expect_code 1 git p4 submit
312 ) &&
313 (
314 cd "$cli" &&
315 test_path_is_missing text2 &&
316 p4 fstat -T action text2 2>&1 | grep "no such file"
317 )
318 '
319
320 test_expect_success 'cleanup rename after submit cancel' '
321 test_when_finished cleanup_git &&
322 git p4 clone --dest="$git" //depot &&
323 (
324 cd "$git" &&
325 git mv text text2 &&
326 git commit -m text2 &&
327 git config git-p4.detectRenames true &&
328 git diff-tree -r -M HEAD | grep text2 | grep R100 &&
329 echo n | test_expect_code 1 git p4 submit
330 ) &&
331 (
332 cd "$cli" &&
333 test_path_is_missing text2 &&
334 p4 fstat -T action text2 2>&1 | grep "no such file"
335 test_path_is_file text &&
336 ! p4 fstat -T action text
337 )
338 '
339
340 test_expect_success 'cleanup chmod after submit cancel' '
341 test_when_finished cleanup_git &&
342 git p4 clone --dest="$git" //depot &&
343 (
344 cd "$git" &&
345 chmod u+x text &&
346 chmod u-x text+x &&
347 git add text text+x &&
348 git commit -m "chmod texts" &&
349 echo n | test_expect_code 1 git p4 submit
350 ) &&
351 (
352 cd "$cli" &&
353 test_path_is_file text &&
354 ! p4 fstat -T action text &&
355 stat --format=%A text | egrep ^-r-- &&
356 test_path_is_file text+x &&
357 ! p4 fstat -T action text+x &&
358 stat --format=%A text+x | egrep ^-r-x
359 )
360 '
361
362 test_expect_success 'kill p4d' '
363 kill_p4d
364 '
365
366 test_done