git-p4: add option to disable syncing of p4/master with p4
Add an option to the git-p4 submit command to disable syncing with Perforce. This is useful for the case where a git-p4 mirror has been setup on a server somewhere, running from (e.g.) cron, and developers then clone from this. Having the local cloned copy also sync from Perforce just isn't useful. Signed-off-by: Luke Diamand <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Luke Diamand committed
Jun 8, 2018 at 21:32 UTC
b9d34db9a2108755ad01926cccc2a5007b5862a6
2 files changed
+28
-11
Documentation/git-p4.txt
+8
@@ -344,6 +344,11 @@ These options can be used to modify 'git p4 submit' behavior.
344
Disable the automatic rebase after all commits have been successfully
345
submitted. Can also be set with git-p4.disableRebase.
346
347
+--disable-p4sync::
348
+ Disable the automatic sync of p4/master from Perforce after commits have
349
+ been submitted. Implies --disable-rebase. Can also be set with
350
+ git-p4.disableP4Sync. Sync with origin/master still goes ahead if possible.
351
+
352
Rebase options
353
~~~~~~~~~~~~~~
354
These options can be used to modify 'git p4 rebase' behavior.
@@ -661,6 +666,9 @@ git-p4.conflict::
666
git-p4.disableRebase::
667
Do not rebase the tree against p4/master following a submit.
668
669
+git-p4.disableP4Sync::
670
+ Do not sync p4/master with Perforce following a submit. Implies git-p4.disableRebase.
671
+
672
IMPLEMENTATION DETAILS
673
----------------------
674
* Changesets from p4 are imported using Git fast-import.
git-p4.py
+20
-11
@@ -1357,7 +1357,9 @@ class P4Submit(Command, P4UserMap):
1357
help="submit only the specified commit(s), one commit or xxx..xxx"),
1358
optparse.make_option("--disable-rebase", dest="disable_rebase", action="store_true",
1359
help="Disable rebase after submit is completed. Can be useful if you "
1360
- "work from a local git branch that is not master")
1360
+ "work from a local git branch that is not master"),
1361
+ optparse.make_option("--disable-p4sync", dest="disable_p4sync", action="store_true",
1362
+ help="Skip Perforce sync of p4/master after submit or shelve"),
1363
]
1364
self.description = "Submit changes from git to the perforce depot."
1365
self.usage += " [name of git branch to submit into perforce depot]"
@@ -1369,6 +1371,7 @@ class P4Submit(Command, P4UserMap):
1371
self.update_shelve = list()
1372
self.commit = ""
1373
self.disable_rebase = gitConfigBool("git-p4.disableRebase")
1374
+ self.disable_p4sync = gitConfigBool("git-p4.disableP4Sync")
1375
self.prepare_p4_only = False
1376
self.conflict_behavior = None
1377
self.isWindows = (platform.system() == "Windows")
@@ -2229,11 +2232,14 @@ class P4Submit(Command, P4UserMap):
2232
sync = P4Sync()
2233
if self.branch:
2234
sync.branch = self.branch
2232
- sync.run([])
2235
+ if self.disable_p4sync:
2236
+ sync.sync_origin_only()
2237
+ else:
2238
+ sync.run([])
2239
2234
- if self.disable_rebase is False:
2235
- rebase = P4Rebase()
2236
- rebase.rebase()
2240
+ if not self.disable_rebase:
2241
+ rebase = P4Rebase()
2242
+ rebase.rebase()
2243
2244
else:
2245
if len(applied) == 0:
@@ -3261,6 +3267,14 @@ class P4Sync(Command, P4UserMap):
3267
print self.gitError.read()
3268
sys.exit(1)
3269
3270
+ def sync_origin_only(self):
3271
+ if self.syncWithOrigin:
3272
+ self.hasOrigin = originP4BranchesExist()
3273
+ if self.hasOrigin:
3274
+ if not self.silent:
3275
+ print 'Syncing with origin first, using "git fetch origin"'
3276
+ system("git fetch origin")
3277
+
3278
def importHeadRevision(self, revision):
3279
print "Doing initial import of %s from revision %s into %s" % (' '.join(self.depotPaths), revision, self.branch)
3280
@@ -3333,12 +3347,7 @@ class P4Sync(Command, P4UserMap):
3347
else:
3348
self.refPrefix = "refs/heads/p4/"
3349
3336
- if self.syncWithOrigin:
3337
- self.hasOrigin = originP4BranchesExist()
3338
- if self.hasOrigin:
3339
- if not self.silent:
3340
- print 'Syncing with origin first, using "git fetch origin"'
3341
- system("git fetch origin")
3350
+ self.sync_origin_only()
3351
3352
branch_arg_given = bool(self.branch)
3353
if len(self.branch) == 0: