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 <pw@padd.com> Acked-by: Luke Diamand <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
ef739f0829
commit
728b7ad8bb
@ -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
|
Show just what commits would be submitted to p4; do not change
|
||||||
state in git or p4.
|
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
|
Rebase options
|
||||||
~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~
|
||||||
These options can be used to modify 'git p4 rebase' behavior.
|
These options can be used to modify 'git p4 rebase' behavior.
|
||||||
|
46
git-p4.py
46
git-p4.py
@ -854,6 +854,7 @@ class P4Submit(Command, P4UserMap):
|
|||||||
optparse.make_option("--preserve-user", dest="preserveUser", action="store_true"),
|
optparse.make_option("--preserve-user", dest="preserveUser", action="store_true"),
|
||||||
optparse.make_option("--export-labels", dest="exportLabels", 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("--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.description = "Submit changes from git to the perforce depot."
|
||||||
self.usage += " [name of git branch to submit into 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.detectRenames = False
|
||||||
self.preserveUser = gitConfig("git-p4.preserveUser").lower() == "true"
|
self.preserveUser = gitConfig("git-p4.preserveUser").lower() == "true"
|
||||||
self.dry_run = False
|
self.dry_run = False
|
||||||
|
self.prepare_p4_only = False
|
||||||
self.isWindows = (platform.system() == "Windows")
|
self.isWindows = (platform.system() == "Windows")
|
||||||
self.exportLabels = False
|
self.exportLabels = False
|
||||||
self.p4HasMoveCommand = p4_has_command("move")
|
self.p4HasMoveCommand = p4_has_command("move")
|
||||||
@ -1270,6 +1272,41 @@ class P4Submit(Command, P4UserMap):
|
|||||||
tmpFile.write(submitTemplate + separatorLine + diff + newdiff)
|
tmpFile.write(submitTemplate + separatorLine + diff + newdiff)
|
||||||
tmpFile.close()
|
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.
|
# Let the user edit the change description, then submit it.
|
||||||
#
|
#
|
||||||
@ -1370,6 +1407,9 @@ class P4Submit(Command, P4UserMap):
|
|||||||
|
|
||||||
if self.dry_run:
|
if self.dry_run:
|
||||||
print "Would create p4 label %s for tag" % name
|
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:
|
else:
|
||||||
p4_write_pipe(["label", "-i"], labelTemplate)
|
p4_write_pipe(["label", "-i"], labelTemplate)
|
||||||
|
|
||||||
@ -1510,6 +1550,10 @@ class P4Submit(Command, P4UserMap):
|
|||||||
if ok:
|
if ok:
|
||||||
applied.append(commit)
|
applied.append(commit)
|
||||||
else:
|
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:
|
if i < last:
|
||||||
quit = False
|
quit = False
|
||||||
while True:
|
while True:
|
||||||
@ -1532,6 +1576,8 @@ class P4Submit(Command, P4UserMap):
|
|||||||
|
|
||||||
if self.dry_run:
|
if self.dry_run:
|
||||||
pass
|
pass
|
||||||
|
elif self.prepare_p4_only:
|
||||||
|
pass
|
||||||
elif len(commits) == len(applied):
|
elif len(commits) == len(applied):
|
||||||
print "All commits applied!"
|
print "All commits applied!"
|
||||||
|
|
||||||
|
@ -375,6 +375,30 @@ test_expect_success 'description with Jobs section and bogus following text' '
|
|||||||
make_job $(cat jobname) &&
|
make_job $(cat jobname) &&
|
||||||
test_must_fail git p4 submit 2>err &&
|
test_must_fail git p4 submit 2>err &&
|
||||||
test_i18ngrep "Unknown field name" 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
|
||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user