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

[PATCHv2 11/12] git p4: add submit --prepare-p4-only option

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

This option can be used to prepare the client workspace for submission, only. It does not invoke the final "p4 submit". A message describes how to proceed, either submitting the changes or reverting.

Signed-off-by: Pete Wyckoff <pw@padd.com>
---
 Documentation/git-p4.txt |  7 +++++++
 git-p4.py                | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 t/t9807-git-p4-submit.sh | 24 ++++++++++++++++++++++++
 3 files changed, 77 insertions(+)
diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt
index 1f32b8e..4be4290 100644
--- a/Documentation/git-p4.txt
+++ b/Documentation/git-p4.txt
@@ -273,6 +273,13 @@ These options can be used to modify 'git p4 submit' behavior.
 	Show just what commits would be submitted to p4; do not change
 	state in git or p4.
 
+--prepare-p4-only::
+	Apply a commit to the p4 workspace, opening, adding and deleting
+	files in p4 as for a normal submit operation.  Do not issue the
+	final "p4 submit", but instead print a message about how to
+	submit manually or revert.  This option always stops after the
+	first (oldest) commit.  Git tags are not exported to p4.
+
 Rebase options
 ~~~~~~~~~~~~~~
 These options can be used to modify 'git p4 rebase' behavior.
diff --git a/git-p4.py b/git-p4.py
index 04e9a80..2dd2b76 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -854,6 +854,7 @@ class P4Submit(Command, P4UserMap):
                 optparse.make_option("--preserve-user", dest="preserveUser", action="store_true"),
                 optparse.make_option("--export-labels", dest="exportLabels", action="store_true"),
                 optparse.make_option("--dry-run", "-n", dest="dry_run", action="store_true"),
+                optparse.make_option("--prepare-p4-only", dest="prepare_p4_only", action="store_true"),
         ]
         self.description = "Submit changes from git to the perforce depot."
         self.usage += " [name of git branch to submit into perforce depot]"
@@ -861,6 +862,7 @@ class P4Submit(Command, P4UserMap):
         self.detectRenames = False
         self.preserveUser = gitConfig("git-p4.preserveUser").lower() == "true"
         self.dry_run = False
+        self.prepare_p4_only = False
         self.isWindows = (platform.system() == "Windows")
         self.exportLabels = False
         self.p4HasMoveCommand = p4_has_command("move")
@@ -1270,6 +1272,41 @@ class P4Submit(Command, P4UserMap):
         tmpFile.write(submitTemplate + separatorLine + diff + newdiff)
         tmpFile.close()
 
+        if self.prepare_p4_only:
+            #
+            # Leave the p4 tree prepared, and the submit template around
+            # and let the user decide what to do next
+            #
+            print
+            print "P4 workspace prepared for submission."
+            print "To submit or revert, go to client workspace"
+            print "  " + self.clientPath
+            print
+            print "To submit, use \"p4 submit\" to write a new description,"
+            print "or \"p4 submit -i %s\" to use the one prepared by" \
+                  " \"git p4\"." % fileName
+            print "You can delete the file \"%s\" when finished." % fileName
+
+            if self.preserveUser and p4User and not self.p4UserIsMe(p4User):
+                print "To preserve change ownership by user %s, you must\n" \
+                      "do \"p4 change -f <change>\" after submitting and\n" \
+                      "edit the User field."
+            if pureRenameCopy:
+                print "After submitting, renamed files must be re-synced."
+                print "Invoke \"p4 sync -f\" on each of these files:"
+                for f in pureRenameCopy:
+                    print "  " + f
+
+            print
+            print "To revert the changes, use \"p4 revert ...\", and delete"
+            print "the submit template file \"%s\"" % fileName
+            if filesToAdd:
+                print "Since the commit adds new files, they must be deleted:"
+                for f in filesToAdd:
+                    print "  " + f
+            print
+            return True
+
         #
         # Let the user edit the change description, then submit it.
         #
@@ -1370,6 +1407,9 @@ class P4Submit(Command, P4UserMap):
 
             if self.dry_run:
                 print "Would create p4 label %s for tag" % name
+            elif self.prepare_p4_only:
+                print "Not creating p4 label %s for tag due to option" \
+                      " --prepare-p4-only" % name
             else:
                 p4_write_pipe(["label", "-i"], labelTemplate)
 
@@ -1510,6 +1550,10 @@ class P4Submit(Command, P4UserMap):
             if ok:
                 applied.append(commit)
             else:
+                if self.prepare_p4_only and i < last:
+                    print "Processing only the first commit due to option" \
+                          " --prepare-p4-only"
+                    break
                 if i < last:
                     quit = False
                     while True:
@@ -1532,6 +1576,8 @@ class P4Submit(Command, P4UserMap):
 
         if self.dry_run:
             pass
+        elif self.prepare_p4_only:
+            pass
         elif len(commits) == len(applied):
             print "All commits applied!"
 
diff --git a/t/t9807-git-p4-submit.sh b/t/t9807-git-p4-submit.sh
index 9cb6aa7..0ae048f 100755
--- a/t/t9807-git-p4-submit.sh
+++ b/t/t9807-git-p4-submit.sh
@@ -375,6 +375,30 @@ test_expect_success 'description with Jobs section and bogus following text' '
 		make_job $(cat jobname) &&
 		test_must_fail git p4 submit 2>err &&
 		test_i18ngrep "Unknown field name" err
+	) &&
+	(
+		cd "$cli" &&
+		p4 revert desc6 &&
+		rm desc6
+	)
+'
+
+test_expect_success 'submit --prepare-p4-only' '
+	test_when_finished cleanup_git &&
+	git p4 clone --dest="$git" //depot &&
+	(
+		cd "$git" &&
+		echo prep-only-add >prep-only-add &&
+		git add prep-only-add &&
+		git commit -m "prep only add" &&
+		git p4 submit --prepare-p4-only >out &&
+		test_i18ngrep "prepared for submission" out &&
+		test_i18ngrep "must be deleted" out
+	) &&
+	(
+		cd "$cli" &&
+		test_path_is_file prep-only-add &&
+		p4 fstat -T action prep-only-add | grep -w add
 	)
 '
 
-- 
1.7.12.rc2.111.g96f7c73
Previous: Pete WyckoffNext: Pete Wyckoff
Message 21 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.