git p4: revert deleted files after submit cancel
The user can decide not to continue with a submission, by not saving the p4 submit template, then answering "no" to the "Submit anyway?" prompt. In this case, be sure to return the p4 client to its initial state. Deleted files were not reverted; fix this and test all cases. Signed-off-by: Pete Wyckoff <pw@padd.com> Acked-by: Luke Diamand <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pete Wyckoff committed
Sep 9, 2012 at 16:16 UTC
df9c5453b220923d7ec3e6291498d519596e23ed
2 files changed
+121
git-p4.py
+2
@@ -1304,6 +1304,8 @@ class P4Submit(Command, P4UserMap):
1304
for f in filesToAdd:
1305
p4_revert(f)
1306
os.remove(f)
1307
+ for f in filesToDelete:
1308
+ p4_revert(f)
1309
1310
os.remove(fileName)
1311
return ret
t/t9815-git-p4-submit-fail.sh
+119
@@ -240,6 +240,125 @@ test_expect_success 'cleanup rename after submit fail' '
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
'