aboutsummaryrefslogtreecommitdiff
path: root/t/t9815-git-p4-submit-fail.sh
blob: 1243d96092ad5c6a66d66ee9debc399649ffa0a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
#!/bin/sh

test_description='git p4 submit failure handling'

. ./lib-git-p4.sh

test_expect_success 'start p4d' '
	start_p4d
'

test_expect_success 'init depot' '
	(
		cd "$cli" &&
		p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
		echo line1 >file1 &&
		p4 add file1 &&
		p4 submit -d "line1 in file1"
	)
'

test_expect_success 'conflict on one commit' '
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot &&
	(
		cd "$cli" &&
		p4 open file1 &&
		echo line2 >>file1 &&
		p4 submit -d "line2 in file1"
	) &&
	(
		# now this commit should cause a conflict
		cd "$git" &&
		git config git-p4.skipSubmitEdit true &&
		echo line3 >>file1 &&
		git add file1 &&
		git commit -m "line3 in file1 will conflict" &&
		test_expect_code 1 git p4 submit >out &&
		test_i18ngrep "No commits applied" out
	)
'

test_expect_success 'conflict on second of two commits' '
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot &&
	(
		cd "$cli" &&
		p4 open file1 &&
		echo line3 >>file1 &&
		p4 submit -d "line3 in file1"
	) &&
	(
		cd "$git" &&
		git config git-p4.skipSubmitEdit true &&
		# this commit is okay
		test_commit "first_commit_okay" &&
		# now this submit should cause a conflict
		echo line4 >>file1 &&
		git add file1 &&
		git commit -m "line4 in file1 will conflict" &&
		test_expect_code 1 git p4 submit >out &&
		test_i18ngrep "Applied only the commits" out
	)
'

test_expect_success 'conflict on first of two commits, skip' '
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot &&
	(
		cd "$cli" &&
		p4 open file1 &&
		echo line4 >>file1 &&
		p4 submit -d "line4 in file1"
	) &&
	(
		cd "$git" &&
		git config git-p4.skipSubmitEdit true &&
		# this submit should cause a conflict
		echo line5 >>file1 &&
		git add file1 &&
		git commit -m "line5 in file1 will conflict" &&
		# but this commit is okay
		test_commit "okay_commit_after_skip" &&
		echo s | test_expect_code 1 git p4 submit >out &&
		test_i18ngrep "Applied only the commits" out
	)
'

test_expect_success 'conflict on first of two commits, quit' '
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot &&
	(
		cd "$cli" &&
		p4 open file1 &&
		echo line7 >>file1 &&
		p4 submit -d "line7 in file1"
	) &&
	(
		cd "$git" &&
		git config git-p4.skipSubmitEdit true &&
		# this submit should cause a conflict
		echo line8 >>file1 &&
		git add file1 &&
		git commit -m "line8 in file1 will conflict" &&
		# but this commit is okay
		test_commit "okay_commit_after_quit" &&
		echo q | test_expect_code 1 git p4 submit >out &&
		test_i18ngrep "No commits applied" out
	)
'

test_expect_success 'conflict cli and config options' '
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot &&
	(
		cd "$git" &&
		git p4 submit --conflict=ask &&
		git p4 submit --conflict=skip &&
		git p4 submit --conflict=quit &&
		test_expect_code 2 git p4 submit --conflict=foo &&
		test_expect_code 2 git p4 submit --conflict &&
		git config git-p4.conflict foo &&
		test_expect_code 1 git p4 submit &&
		git config --unset git-p4.conflict &&
		git p4 submit
	)
'

test_expect_success 'conflict on first of two commits, --conflict=skip' '
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot &&
	(
		cd "$cli" &&
		p4 open file1 &&
		echo line9 >>file1 &&
		p4 submit -d "line9 in file1"
	) &&
	(
		cd "$git" &&
		git config git-p4.skipSubmitEdit true &&
		# this submit should cause a conflict
		echo line10 >>file1 &&
		git add file1 &&
		git commit -m "line10 in file1 will conflict" &&
		# but this commit is okay
		test_commit "okay_commit_after_auto_skip" &&
		test_expect_code 1 git p4 submit --conflict=skip >out &&
		test_i18ngrep "Applied only the commits" out
	)
'

test_expect_success 'conflict on first of two commits, --conflict=quit' '
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot &&
	(
		cd "$cli" &&
		p4 open file1 &&
		echo line11 >>file1 &&
		p4 submit -d "line11 in file1"
	) &&
	(
		cd "$git" &&
		git config git-p4.skipSubmitEdit true &&
		# this submit should cause a conflict
		echo line12 >>file1 &&
		git add file1 &&
		git commit -m "line12 in file1 will conflict" &&
		# but this commit is okay
		test_commit "okay_commit_after_auto_quit" &&
		test_expect_code 1 git p4 submit --conflict=quit >out &&
		test_i18ngrep "No commits applied" out
	)
'

#
# Cleanup after submit fail, all cases.  Some modifications happen
# before trying to apply the patch.  Make sure these are unwound
# properly.  Put each one in a diff along with something that will
# obviously conflict.  Make sure it is back to normal after.
#

test_expect_success 'cleanup edit p4 populate' '
	(
		cd "$cli" &&
		echo text file >text &&
		p4 add text &&
		echo text+x file >text+x &&
		chmod 755 text+x &&
		p4 add text+x &&
		p4 submit -d "populate p4"
	)
'

setup_conflict() {
	# clone before modifying file1 to force it to conflict
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot &&
	# ticks outside subshells
	test_tick &&
	(
		cd "$cli" &&
		p4 open file1 &&
		echo $test_tick >>file1 &&
		p4 submit -d "$test_tick in file1"
	) &&
	test_tick &&
	(
		cd "$git" &&
		git config git-p4.skipSubmitEdit true &&
		# easy conflict
		echo $test_tick >>file1 &&
		git add file1
		# caller will add more and submit
	)
}

test_expect_success 'cleanup edit after submit fail' '
	setup_conflict &&
	(
		cd "$git" &&
		echo another line >>text &&
		git add text &&
		git commit -m "conflict" &&
		test_expect_code 1 git p4 submit
	) &&
	(
		cd "$cli" &&
		# make sure it is not open
		! p4 fstat -T action text
	)
'

test_expect_success 'cleanup add after submit fail' '
	setup_conflict &&
	(
		cd "$git" &&
		echo new file >textnew &&
		git add textnew &&
		git commit -m "conflict" &&
		test_expect_code 1 git p4 submit
	) &&
	(
		cd "$cli" &&
		# make sure it is not there
		# and that p4 thinks it is not added
		#   P4 returns 0 both for "not there but added" and
		#   "not there", so grep.
		test_path_is_missing textnew &&
		p4 fstat -T action textnew 2>&1 | grep "no such file"
	)
'

test_expect_success 'cleanup delete after submit fail' '
	setup_conflict &&
	(
		cd "$git" &&
		git rm text+x &&
		git commit -m "conflict" &&
		test_expect_code 1 git p4 submit
	) &&
	(
		cd "$cli" &&
		# make sure it is there
		test_path_is_file text+x &&
		! p4 fstat -T action text+x
	)
'

test_expect_success 'cleanup copy after submit fail' '
	setup_conflict &&
	(
		cd "$git" &&
		cp text text2 &&
		git add text2 &&
		git commit -m "conflict" &&
		git config git-p4.detectCopies true &&
		git config git-p4.detectCopiesHarder true &&
		# make sure setup is okay
		git diff-tree -r -C --find-copies-harder HEAD | grep text2 | grep C100 &&
		test_expect_code 1 git p4 submit
	) &&
	(
		cd "$cli" &&
		test_path_is_missing text2 &&
		p4 fstat -T action text2 2>&1 | grep "no such file"
	)
'

test_expect_success 'cleanup rename after submit fail' '
	setup_conflict &&
	(
		cd "$git" &&
		git mv text text2 &&
		git commit -m "conflict" &&
		git config git-p4.detectRenames true &&
		# make sure setup is okay
		git diff-tree -r -M HEAD | grep text2 | grep R100 &&
		test_expect_code 1 git p4 submit
	) &&
	(
		cd "$cli" &&
		test_path_is_missing text2 &&
		p4 fstat -T action text2 2>&1 | grep "no such file"
	)
'

#
# Cleanup after deciding not to submit during editTemplate.  This
# involves unwinding more work, because files have been added, deleted
# and chmod-ed now.  Same approach as above.
#

test_expect_success 'cleanup edit after submit cancel' '
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot &&
	(
		cd "$git" &&
		echo line >>text &&
		git add text &&
		git commit -m text &&
		echo n | test_expect_code 1 git p4 submit &&
		git reset --hard HEAD^
	) &&
	(
		cd "$cli" &&
		! p4 fstat -T action text &&
		test_cmp "$git"/text text
	)
'

test_expect_success 'cleanup add after submit cancel' '
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot &&
	(
		cd "$git" &&
		echo line >textnew &&
		git add textnew &&
		git commit -m textnew &&
		echo n | test_expect_code 1 git p4 submit
	) &&
	(
		cd "$cli" &&
		test_path_is_missing textnew &&
		p4 fstat -T action textnew 2>&1 | grep "no such file"
	)
'

test_expect_success 'cleanup delete after submit cancel' '
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot &&
	(
		cd "$git" &&
		git rm text &&
		git commit -m "rm text" &&
		echo n | test_expect_code 1 git p4 submit
	) &&
	(
		cd "$cli" &&
		test_path_is_file text &&
		! p4 fstat -T action text
	)
'

test_expect_success 'cleanup copy after submit cancel' '
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot &&
	(
		cd "$git" &&
		cp text text2 &&
		git add text2 &&
		git commit -m text2 &&
		git config git-p4.detectCopies true &&
		git config git-p4.detectCopiesHarder true &&
		git diff-tree -r -C --find-copies-harder HEAD | grep text2 | grep C100 &&
		echo n | test_expect_code 1 git p4 submit
	) &&
	(
		cd "$cli" &&
		test_path_is_missing text2 &&
		p4 fstat -T action text2 2>&1 | grep "no such file"
	)
'

test_expect_success 'cleanup rename after submit cancel' '
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot &&
	(
		cd "$git" &&
		git mv text text2 &&
		git commit -m text2 &&
		git config git-p4.detectRenames true &&
		git diff-tree -r -M HEAD | grep text2 | grep R100 &&
		echo n | test_expect_code 1 git p4 submit
	) &&
	(
		cd "$cli" &&
		test_path_is_missing text2 &&
		p4 fstat -T action text2 2>&1 | grep "no such file"
		test_path_is_file text &&
		! p4 fstat -T action text
	)
'

test_expect_success 'cleanup chmod after submit cancel' '
	test_when_finished cleanup_git &&
	git p4 clone --dest="$git" //depot &&
	(
		cd "$git" &&
		test_chmod +x text &&
		test_chmod -x text+x &&
		git add text text+x &&
		git commit -m "chmod texts" &&
		echo n | test_expect_code 1 git p4 submit
	) &&
	(
		cd "$cli" &&
		test_path_is_file text &&
		! p4 fstat -T action text &&
		test_path_is_file text+x &&
		! p4 fstat -T action text+x &&
		if test_have_prereq NOT_CYGWIN
		then
			stat --format=%A text | egrep ^-r-- &&
			stat --format=%A text+x | egrep ^-r-x
		fi
	)
'

test_expect_success 'kill p4d' '
	kill_p4d
'

test_done