git p4: move conflict prompt into run, add [q]uit input

When applying a commit to the p4 workspace fails, a prompt asks what to do next. This belongs up in run() instead of in applyCommit(), where run() can notice, for instance, that the prompt is unnecessary because this is the last commit. Offer two options about how to continue at conflict: [s]kip or [q]uit. Having an explicit "quit" option gives git p4 a chance to clean up, show the applied-commit summary, and do tag export. 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 7e5dd9f2ccf2141d65e4621b765a136796b0d55b
2 files changed +56 -16
git-p4.py
+29 -12
@@ -1198,17 +1198,11 @@ class P4Submit(Command, P4UserMap):
1198 patch_succeeded = True
1199
1200 if not patch_succeeded:
1201 - print "What do you want to do?"
1202 - response = "x"
1203 - while response != "s":
1204 - response = raw_input("[s]kip this patch ")
1205 - if response == "s":
1206 - print "Skipping! Good luck with the next patches..."
1207 - for f in editedFiles:
1208 - p4_revert(f)
1209 - for f in filesToAdd:
1210 - os.remove(f)
1211 - return False
1201 + for f in editedFiles:
1202 + p4_revert(f)
1203 + for f in filesToAdd:
1204 + os.remove(f)
1205 + return False
1206
1207 system(applyPatchCmd)
1208
@@ -1475,11 +1469,34 @@ class P4Submit(Command, P4UserMap):
1469 if gitConfig("git-p4.detectCopiesHarder", "--bool") == "true":
1470 self.diffOpts += " --find-copies-harder"
1471
1472 + #
1473 + # Apply the commits, one at a time. On failure, ask if should
1474 + # continue to try the rest of the patches, or quit.
1475 + #
1476 applied = []
1479 - for commit in commits:
1477 + last = len(commits) - 1
1478 + for i, commit in enumerate(commits):
1479 ok = self.applyCommit(commit)
1480 if ok:
1481 applied.append(commit)
1482 + else:
1483 + if i < last:
1484 + quit = False
1485 + while True:
1486 + print "What do you want to do?"
1487 + response = raw_input("[s]kip this commit but apply"
1488 + " the rest, or [q]uit? ")
1489 + if not response:
1490 + continue
1491 + if response[0] == "s":
1492 + print "Skipping this commit, but applying the rest"
1493 + break
1494 + if response[0] == "q":
1495 + print "Quitting"
1496 + quit = True
1497 + break
1498 + if quit:
1499 + break
1500
1501 chdir(self.oldWorkingDirectory)
1502
t/t9815-git-p4-submit-fail.sh
+27 -4
@@ -18,7 +18,7 @@ test_expect_success 'init depot' '
18 )
19 '
20
21 -test_expect_success 'conflict on one commit, skip' '
21 +test_expect_success 'conflict on one commit' '
22 test_when_finished cleanup_git &&
23 git p4 clone --dest="$git" //depot &&
24 (
@@ -34,12 +34,12 @@ test_expect_success 'conflict on one commit, skip' '
34 echo line3 >>file1 &&
35 git add file1 &&
36 git commit -m "line3 in file1 will conflict" &&
37 - echo s | test_expect_code 1 git p4 submit >out &&
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, skip' '
42 +test_expect_success 'conflict on second of two commits' '
43 test_when_finished cleanup_git &&
44 git p4 clone --dest="$git" //depot &&
45 (
@@ -57,7 +57,7 @@ test_expect_success 'conflict on second of two commits, skip' '
57 echo line4 >>file1 &&
58 git add file1 &&
59 git commit -m "line4 in file1 will conflict" &&
60 - echo s | test_expect_code 1 git p4 submit >out &&
60 + test_expect_code 1 git p4 submit >out &&
61 test_i18ngrep "Applied only the commits" out
62 )
63 '
@@ -85,6 +85,29 @@ test_expect_success 'conflict on first of two commits, skip' '
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 test_expect_success 'kill p4d' '
112 kill_p4d
113 '