1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-21 13:56:11 +02:00

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>
This commit is contained in:
Luke Diamand 2018-06-08 21:32:44 +01:00 committed by Junio C Hamano
parent 3b3477ea5a
commit b9d34db9a2
2 changed files with 28 additions and 11 deletions

View File

@ -344,6 +344,11 @@ These options can be used to modify 'git p4 submit' behavior.
Disable the automatic rebase after all commits have been successfully Disable the automatic rebase after all commits have been successfully
submitted. Can also be set with git-p4.disableRebase. submitted. Can also be set with git-p4.disableRebase.
--disable-p4sync::
Disable the automatic sync of p4/master from Perforce after commits have
been submitted. Implies --disable-rebase. Can also be set with
git-p4.disableP4Sync. Sync with origin/master still goes ahead if possible.
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.
@ -661,6 +666,9 @@ git-p4.conflict::
git-p4.disableRebase:: git-p4.disableRebase::
Do not rebase the tree against p4/master following a submit. Do not rebase the tree against p4/master following a submit.
git-p4.disableP4Sync::
Do not sync p4/master with Perforce following a submit. Implies git-p4.disableRebase.
IMPLEMENTATION DETAILS IMPLEMENTATION DETAILS
---------------------- ----------------------
* Changesets from p4 are imported using Git fast-import. * Changesets from p4 are imported using Git fast-import.

View File

@ -1357,7 +1357,9 @@ def __init__(self):
help="submit only the specified commit(s), one commit or xxx..xxx"), help="submit only the specified commit(s), one commit or xxx..xxx"),
optparse.make_option("--disable-rebase", dest="disable_rebase", action="store_true", optparse.make_option("--disable-rebase", dest="disable_rebase", action="store_true",
help="Disable rebase after submit is completed. Can be useful if you " help="Disable rebase after submit is completed. Can be useful if you "
"work from a local git branch that is not master") "work from a local git branch that is not master"),
optparse.make_option("--disable-p4sync", dest="disable_p4sync", action="store_true",
help="Skip Perforce sync of p4/master after submit or shelve"),
] ]
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]"
@ -1369,6 +1371,7 @@ def __init__(self):
self.update_shelve = list() self.update_shelve = list()
self.commit = "" self.commit = ""
self.disable_rebase = gitConfigBool("git-p4.disableRebase") self.disable_rebase = gitConfigBool("git-p4.disableRebase")
self.disable_p4sync = gitConfigBool("git-p4.disableP4Sync")
self.prepare_p4_only = False self.prepare_p4_only = False
self.conflict_behavior = None self.conflict_behavior = None
self.isWindows = (platform.system() == "Windows") self.isWindows = (platform.system() == "Windows")
@ -2229,11 +2232,14 @@ def run(self, args):
sync = P4Sync() sync = P4Sync()
if self.branch: if self.branch:
sync.branch = self.branch sync.branch = self.branch
sync.run([]) if self.disable_p4sync:
sync.sync_origin_only()
else:
sync.run([])
if self.disable_rebase is False: if not self.disable_rebase:
rebase = P4Rebase() rebase = P4Rebase()
rebase.rebase() rebase.rebase()
else: else:
if len(applied) == 0: if len(applied) == 0:
@ -3261,6 +3267,14 @@ def importChanges(self, changes):
print self.gitError.read() print self.gitError.read()
sys.exit(1) sys.exit(1)
def sync_origin_only(self):
if self.syncWithOrigin:
self.hasOrigin = originP4BranchesExist()
if self.hasOrigin:
if not self.silent:
print 'Syncing with origin first, using "git fetch origin"'
system("git fetch origin")
def importHeadRevision(self, revision): def importHeadRevision(self, revision):
print "Doing initial import of %s from revision %s into %s" % (' '.join(self.depotPaths), revision, self.branch) print "Doing initial import of %s from revision %s into %s" % (' '.join(self.depotPaths), revision, self.branch)
@ -3333,12 +3347,7 @@ def run(self, args):
else: else:
self.refPrefix = "refs/heads/p4/" self.refPrefix = "refs/heads/p4/"
if self.syncWithOrigin: self.sync_origin_only()
self.hasOrigin = originP4BranchesExist()
if self.hasOrigin:
if not self.silent:
print 'Syncing with origin first, using "git fetch origin"'
system("git fetch origin")
branch_arg_given = bool(self.branch) branch_arg_given = bool(self.branch)
if len(self.branch) == 0: if len(self.branch) == 0: