git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCHv2 04/12] git p4: move conflict prompt into run, add [q]uit input

From
PWPete Wyckoff <pw@padd.com>
Date
Sep 9, 2012, 20:16 UTC
Message-ID
<1347221773-12773-5-git-send-email-pw@padd.com>
In-Reply-To
<1347221773-12773-1-git-send-email-pw@padd.com>

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>
---
 git-p4.py                     | 41 +++++++++++++++++++++++++++++------------
 t/t9815-git-p4-submit-fail.sh | 31 +++++++++++++++++++++++++++----
 2 files changed, 56 insertions(+), 16 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index e08fea1..479f1fc 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1198,17 +1198,11 @@ class P4Submit(Command, P4UserMap):
                     patch_succeeded = True
 
         if not patch_succeeded:
-            print "What do you want to do?"
-            response = "x"
-            while response != "s":
-                response = raw_input("[s]kip this patch ")
-            if response == "s":
-                print "Skipping! Good luck with the next patches..."
-                for f in editedFiles:
-                    p4_revert(f)
-                for f in filesToAdd:
-                    os.remove(f)
-                return False
+            for f in editedFiles:
+                p4_revert(f)
+            for f in filesToAdd:
+                os.remove(f)
+            return False
 
         system(applyPatchCmd)
 
@@ -1475,11 +1469,34 @@ class P4Submit(Command, P4UserMap):
         if gitConfig("git-p4.detectCopiesHarder", "--bool") == "true":
             self.diffOpts += " --find-copies-harder"
 
+        #
+        # Apply the commits, one at a time.  On failure, ask if should
+        # continue to try the rest of the patches, or quit.
+        #
         applied = []
-        for commit in commits:
+        last = len(commits) - 1
+        for i, commit in enumerate(commits):
             ok = self.applyCommit(commit)
             if ok:
                 applied.append(commit)
+            else:
+                if i < last:
+                    quit = False
+                    while True:
+                        print "What do you want to do?"
+                        response = raw_input("[s]kip this commit but apply"
+                                             " the rest, or [q]uit? ")
+                        if not response:
+                            continue
+                        if response[0] == "s":
+                            print "Skipping this commit, but applying the rest"
+                            break
+                        if response[0] == "q":
+                            print "Quitting"
+                            quit = True
+                            break
+                    if quit:
+                        break
 
         chdir(self.oldWorkingDirectory)
 
diff --git a/t/t9815-git-p4-submit-fail.sh b/t/t9815-git-p4-submit-fail.sh
index 5c36714..397b3e8 100755
--- a/t/t9815-git-p4-submit-fail.sh
+++ b/t/t9815-git-p4-submit-fail.sh
@@ -18,7 +18,7 @@ test_expect_success 'init depot' '
 	)
 '
 
-test_expect_success 'conflict on one commit, skip' '
+test_expect_success 'conflict on one commit' '
 	test_when_finished cleanup_git &&
 	git p4 clone --dest="$git" //depot &&
 	(
@@ -34,12 +34,12 @@ test_expect_success 'conflict on one commit, skip' '
 		echo line3 >>file1 &&
 		git add file1 &&
 		git commit -m "line3 in file1 will conflict" &&
-		echo s | test_expect_code 1 git p4 submit >out &&
+		test_expect_code 1 git p4 submit >out &&
 		test_i18ngrep "No commits applied" out
 	)
 '
 
-test_expect_success 'conflict on second of two commits, skip' '
+test_expect_success 'conflict on second of two commits' '
 	test_when_finished cleanup_git &&
 	git p4 clone --dest="$git" //depot &&
 	(
@@ -57,7 +57,7 @@ test_expect_success 'conflict on second of two commits, skip' '
 		echo line4 >>file1 &&
 		git add file1 &&
 		git commit -m "line4 in file1 will conflict" &&
-		echo s | test_expect_code 1 git p4 submit >out &&
+		test_expect_code 1 git p4 submit >out &&
 		test_i18ngrep "Applied only the commits" out
 	)
 '
@@ -85,6 +85,29 @@ test_expect_success 'conflict on first of two commits, skip' '
 	)
 '
 
+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 'kill p4d' '
 	kill_p4d
 '
-- 
1.7.12.rc2.111.g96f7c73
Previous: Luke DiamandNext: Luke Diamand
Message 12 of 22 in “[PATCHv2 00/12] git p4: submit conflict handling”
  1. Pete WyckoffSep 9, 2012
  2. 01/12 git p4 test: remove bash-ism of combined export/assignmentPete Wyckoff, Sep 9, 2012
  3. Luke DiamandSep 15, 2012
  4. Junio C HamanoSep 16, 2012
  5. Luke DiamandSep 16, 2012
  6. Junio C HamanoSep 17, 2012
  7. Luke DiamandSep 17, 2012
  8. 02/12 git p4: gracefully fail if some commits could not be appliedPete Wyckoff, Sep 9, 2012
  9. Luke DiamandSep 15, 2012
  10. 03/12 git p4: remove submit failure options [a]pply and [w]ritePete Wyckoff, Sep 9, 2012
  11. Luke DiamandSep 15, 2012
  12. 04/12 git p4: move conflict prompt into run, add [q]uit inputPete Wyckoff, Sep 9, 2012
  13. Luke DiamandSep 15, 2012
  14. 05/12 git p4: standardize submit cancel due to unchanged templatePete Wyckoff, Sep 9, 2012
  15. Luke DiamandSep 15, 2012
  16. 06/12 git p4: test clean-up after failed submit, fix added filesPete Wyckoff, Sep 9, 2012
  17. 07/12 git p4: rearrange submit template constructionPete Wyckoff, Sep 9, 2012
  18. 08/12 git p4: revert deleted files after submit cancelPete Wyckoff, Sep 9, 2012
  19. 09/12 git p4: accept -v for --verbosePete Wyckoff, Sep 9, 2012
  20. 10/12 git p4: add submit --dry-run optionPete Wyckoff, Sep 9, 2012
  21. 11/12 git p4: add submit --prepare-p4-only optionPete Wyckoff, Sep 9, 2012
  22. 12/12 git-p4: add submit --conflict option and config varaiablePete Wyckoff, Sep 9, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.