Skip to content

Commit 728b7ad

Browse files
Pete Wyckoffgitster
authored andcommitted
git p4: add submit --prepare-p4-only option
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 <[email protected]> Acked-by: Luke Diamand <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ef739f0 commit 728b7ad

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

Documentation/git-p4.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@ These options can be used to modify 'git p4 submit' behavior.
273273
Show just what commits would be submitted to p4; do not change
274274
state in git or p4.
275275

276+
--prepare-p4-only::
277+
Apply a commit to the p4 workspace, opening, adding and deleting
278+
files in p4 as for a normal submit operation. Do not issue the
279+
final "p4 submit", but instead print a message about how to
280+
submit manually or revert. This option always stops after the
281+
first (oldest) commit. Git tags are not exported to p4.
282+
276283
Rebase options
277284
~~~~~~~~~~~~~~
278285
These options can be used to modify 'git p4 rebase' behavior.

git-p4.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,13 +854,15 @@ def __init__(self):
854854
optparse.make_option("--preserve-user", dest="preserveUser", action="store_true"),
855855
optparse.make_option("--export-labels", dest="exportLabels", action="store_true"),
856856
optparse.make_option("--dry-run", "-n", dest="dry_run", action="store_true"),
857+
optparse.make_option("--prepare-p4-only", dest="prepare_p4_only", action="store_true"),
857858
]
858859
self.description = "Submit changes from git to the perforce depot."
859860
self.usage += " [name of git branch to submit into perforce depot]"
860861
self.origin = ""
861862
self.detectRenames = False
862863
self.preserveUser = gitConfig("git-p4.preserveUser").lower() == "true"
863864
self.dry_run = False
865+
self.prepare_p4_only = False
864866
self.isWindows = (platform.system() == "Windows")
865867
self.exportLabels = False
866868
self.p4HasMoveCommand = p4_has_command("move")
@@ -1270,6 +1272,41 @@ def applyCommit(self, id):
12701272
tmpFile.write(submitTemplate + separatorLine + diff + newdiff)
12711273
tmpFile.close()
12721274

1275+
if self.prepare_p4_only:
1276+
#
1277+
# Leave the p4 tree prepared, and the submit template around
1278+
# and let the user decide what to do next
1279+
#
1280+
print
1281+
print "P4 workspace prepared for submission."
1282+
print "To submit or revert, go to client workspace"
1283+
print " " + self.clientPath
1284+
print
1285+
print "To submit, use \"p4 submit\" to write a new description,"
1286+
print "or \"p4 submit -i %s\" to use the one prepared by" \
1287+
" \"git p4\"." % fileName
1288+
print "You can delete the file \"%s\" when finished." % fileName
1289+
1290+
if self.preserveUser and p4User and not self.p4UserIsMe(p4User):
1291+
print "To preserve change ownership by user %s, you must\n" \
1292+
"do \"p4 change -f <change>\" after submitting and\n" \
1293+
"edit the User field."
1294+
if pureRenameCopy:
1295+
print "After submitting, renamed files must be re-synced."
1296+
print "Invoke \"p4 sync -f\" on each of these files:"
1297+
for f in pureRenameCopy:
1298+
print " " + f
1299+
1300+
print
1301+
print "To revert the changes, use \"p4 revert ...\", and delete"
1302+
print "the submit template file \"%s\"" % fileName
1303+
if filesToAdd:
1304+
print "Since the commit adds new files, they must be deleted:"
1305+
for f in filesToAdd:
1306+
print " " + f
1307+
print
1308+
return True
1309+
12731310
#
12741311
# Let the user edit the change description, then submit it.
12751312
#
@@ -1370,6 +1407,9 @@ def exportGitTags(self, gitTags):
13701407

13711408
if self.dry_run:
13721409
print "Would create p4 label %s for tag" % name
1410+
elif self.prepare_p4_only:
1411+
print "Not creating p4 label %s for tag due to option" \
1412+
" --prepare-p4-only" % name
13731413
else:
13741414
p4_write_pipe(["label", "-i"], labelTemplate)
13751415

@@ -1510,6 +1550,10 @@ def run(self, args):
15101550
if ok:
15111551
applied.append(commit)
15121552
else:
1553+
if self.prepare_p4_only and i < last:
1554+
print "Processing only the first commit due to option" \
1555+
" --prepare-p4-only"
1556+
break
15131557
if i < last:
15141558
quit = False
15151559
while True:
@@ -1532,6 +1576,8 @@ def run(self, args):
15321576

15331577
if self.dry_run:
15341578
pass
1579+
elif self.prepare_p4_only:
1580+
pass
15351581
elif len(commits) == len(applied):
15361582
print "All commits applied!"
15371583

t/t9807-git-p4-submit.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,30 @@ test_expect_success 'description with Jobs section and bogus following text' '
375375
make_job $(cat jobname) &&
376376
test_must_fail git p4 submit 2>err &&
377377
test_i18ngrep "Unknown field name" err
378+
) &&
379+
(
380+
cd "$cli" &&
381+
p4 revert desc6 &&
382+
rm desc6
383+
)
384+
'
385+
386+
test_expect_success 'submit --prepare-p4-only' '
387+
test_when_finished cleanup_git &&
388+
git p4 clone --dest="$git" //depot &&
389+
(
390+
cd "$git" &&
391+
echo prep-only-add >prep-only-add &&
392+
git add prep-only-add &&
393+
git commit -m "prep only add" &&
394+
git p4 submit --prepare-p4-only >out &&
395+
test_i18ngrep "prepared for submission" out &&
396+
test_i18ngrep "must be deleted" out
397+
) &&
398+
(
399+
cd "$cli" &&
400+
test_path_is_file prep-only-add &&
401+
p4 fstat -T action prep-only-add | grep -w add
378402
)
379403
'
380404

0 commit comments

Comments
 (0)