git-p4: allow submit to create shelved changelists.
Add a --shelve command line argument which invokes p4 shelve instead of submitting changes. After shelving the changes are reverted from the p4 workspace. Signed-off-by: Vinicius Kursancew <viniciusalexandre@gmail.com> Reviewed-by: Luke Diamand <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Vinicius Kursancew committed
Nov 28, 2016 at 09:33 UTC
b34fa5777d84abf123cd6b306e2a9a02dac4fc86
3 files changed
+58
-14
Documentation/git-p4.txt
+5
@@ -303,6 +303,11 @@ These options can be used to modify 'git p4 submit' behavior.
303
submit manually or revert. This option always stops after the
304
first (oldest) commit. Git tags are not exported to p4.
305
306
+--shelve::
307
+ Instead of submitting create a series of shelved changelists.
308
+ After creating each shelve, the relevant files are reverted/deleted.
309
+ If you have multiple commits pending multiple shelves will be created.
310
+
311
--conflict=(ask|skip|quit)::
312
Conflicts can occur when applying a commit to p4. When this
313
happens, the default behavior ("ask") is to prompt whether to
git-p4.py
+22
-14
@@ -1289,6 +1289,9 @@ class P4Submit(Command, P4UserMap):
1289
optparse.make_option("--conflict", dest="conflict_behavior",
1290
choices=self.conflict_behavior_choices),
1291
optparse.make_option("--branch", dest="branch"),
1292
+ optparse.make_option("--shelve", dest="shelve", action="store_true",
1293
+ help="Shelve instead of submit. Shelved files are reverted, "
1294
+ "restoring the workspace to the state before the shelve"),
1295
]
1296
self.description = "Submit changes from git to the perforce depot."
1297
self.usage += " [name of git branch to submit into perforce depot]"
@@ -1296,6 +1299,7 @@ class P4Submit(Command, P4UserMap):
1299
self.detectRenames = False
1300
self.preserveUser = gitConfigBool("git-p4.preserveUser")
1301
self.dry_run = False
1302
+ self.shelve = False
1303
self.prepare_p4_only = False
1304
self.conflict_behavior = None
1305
self.isWindows = (platform.system() == "Windows")
@@ -1785,7 +1789,14 @@ class P4Submit(Command, P4UserMap):
1789
if self.isWindows:
1790
message = message.replace("\r\n", "\n")
1791
submitTemplate = message[:message.index(separatorLine)]
1788
- p4_write_pipe(['submit', '-i'], submitTemplate)
1792
+ if self.shelve:
1793
+ p4_write_pipe(['shelve', '-i'], submitTemplate)
1794
+ else:
1795
+ p4_write_pipe(['submit', '-i'], submitTemplate)
1796
+ # The rename/copy happened by applying a patch that created a
1797
+ # new file. This leaves it writable, which confuses p4.
1798
+ for f in pureRenameCopy:
1799
+ p4_sync(f, "-f")
1800
1801
if self.preserveUser:
1802
if p4User:
@@ -1795,23 +1806,20 @@ class P4Submit(Command, P4UserMap):
1806
changelist = self.lastP4Changelist()
1807
self.modifyChangelistUser(changelist, p4User)
1808
1798
- # The rename/copy happened by applying a patch that created a
1799
- # new file. This leaves it writable, which confuses p4.
1800
- for f in pureRenameCopy:
1801
- p4_sync(f, "-f")
1809
submitted = True
1810
1811
finally:
1812
# skip this patch
1806
- if not submitted:
1807
- print "Submission cancelled, undoing p4 changes."
1808
- for f in editedFiles:
1813
+ if not submitted or self.shelve:
1814
+ if self.shelve:
1815
+ print ("Reverting shelved files.")
1816
+ else:
1817
+ print ("Submission cancelled, undoing p4 changes.")
1818
+ for f in editedFiles | filesToDelete:
1819
p4_revert(f)
1820
for f in filesToAdd:
1821
p4_revert(f)
1822
os.remove(f)
1813
- for f in filesToDelete:
1814
- p4_revert(f)
1823
1824
os.remove(fileName)
1825
return submitted
@@ -2067,13 +2075,13 @@ class P4Submit(Command, P4UserMap):
2075
break
2076
2077
chdir(self.oldWorkingDirectory)
2070
-
2078
+ shelved_applied = "shelved" if self.shelve else "applied"
2079
if self.dry_run:
2080
pass
2081
elif self.prepare_p4_only:
2082
pass
2083
elif len(commits) == len(applied):
2076
- print "All commits applied!"
2084
+ print ("All commits {0}!".format(shelved_applied))
2085
2086
sync = P4Sync()
2087
if self.branch:
@@ -2085,9 +2093,9 @@ class P4Submit(Command, P4UserMap):
2093
2094
else:
2095
if len(applied) == 0:
2088
- print "No commits applied."
2096
+ print ("No commits {0}.".format(shelved_applied))
2097
else:
2090
- print "Applied only the commits marked with '*':"
2098
+ print ("{0} only the commits marked with '*':".format(shelved_applied.capitalize()))
2099
for c in commits:
2100
if c in applied:
2101
star = "*"
t/t9807-git-p4-submit.sh
+31
@@ -413,6 +413,37 @@ test_expect_success 'submit --prepare-p4-only' '
413
)
414
'
415
416
+test_expect_success 'submit --shelve' '
417
+ test_when_finished cleanup_git &&
418
+ git p4 clone --dest="$git" //depot &&
419
+ (
420
+ cd "$cli" &&
421
+ p4 revert ... &&
422
+ cd "$git" &&
423
+ git config git-p4.skipSubmitEdit true &&
424
+ test_commit "shelveme1" &&
425
+ git p4 submit --origin=HEAD^ &&
426
+
427
+ echo 654321 >shelveme2.t &&
428
+ echo 123456 >>shelveme1.t &&
429
+ git add shelveme* &&
430
+ git commit -m"shelvetest" &&
431
+ git p4 submit --shelve --origin=HEAD^ &&
432
+
433
+ test_path_is_file shelveme1.t &&
434
+ test_path_is_file shelveme2.t
435
+ ) &&
436
+ (
437
+ cd "$cli" &&
438
+ change=$(p4 -G changes -s shelved -m 1 //depot/... | \
439
+ marshal_dump change) &&
440
+ p4 describe -S $change | grep shelveme2 &&
441
+ p4 describe -S $change | grep 123456 &&
442
+ test_path_is_file shelveme1.t &&
443
+ test_path_is_missing shelveme2.t
444
+ )
445
+'
446
+
447
test_expect_success 'kill p4d' '
448
kill_p4d
449
'