From: Pete Wyckoff <hidden> Date: 2016-06-15 22:55:45
There are multiple oddities in how git-p4 treats multiple
p4 branches, as created with "clone" or "sync" and the
'--branch' argument. Olivier reported some of these recently
in http://thread.gmane.org/gmane.comp.version-control.git/212613
There are two observable behavior changes, but they
are in the category of "bug fixes" in my opinion:
- p4/HEAD symbolic ref is always created now; it used to
be created only after the first sync operation after a clone
- using clone --branch now checks out files; it used to
complain that there was no p4/master ref
Pete Wyckoff (14):
git p4: test sync/clone --branch behavior
git p4: rearrange and simplify hasOrigin handling
git p4: add comments to p4BranchesInGit
git p4: inline listExistingP4GitBranches
git p4: create p4/HEAD on initial clone
git p4: verify expected refs in clone --bare test
git p4: clone --branch should checkout master
git p4 doc: fix branch detection example
git p4: allow short ref names to --branch
git p4: rearrange self.initialParent use
git p4: fail gracefully on sync with no master branch
git p4: fix sync --branch when no master branch
git p4 test: keep P4CLIENT changes inside subshells
git p4: fix submit when no master branch
Documentation/git-p4.txt | 22 +++++--
git-p4.py | 152 ++++++++++++++++++++++++++++++++--------------
t/t9800-git-p4-basic.sh | 9 ++-
t/t9806-git-p4-options.sh | 128 ++++++++++++++++++++++++++++++++++++--
4 files changed, 253 insertions(+), 58 deletions(-)
--
1.8.1.350.gdbf6fd0
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:55:45
Add failing tests to document behavior when there are multiple p4
branches, as created using the --branch option. In particular:
Using clone --branch populates the specified branch correctly, but
dies with an error when trying to checkout master.
Calling sync without a master branch dies with an error looking for
master. When there are two or more branches, a sync does
nothing due to branch detection code, but that is expected.
Using sync --branch to try to update just a particular branch
updates no branch, but appears to succeed.
Signed-off-by: Pete Wyckoff <redacted>
---
t/t9806-git-p4-options.sh | 53 +++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 49 insertions(+), 4 deletions(-)
@@ -27,14 +27,59 @@ test_expect_success 'clone no --git-dir' 'test_must_failgitp4clone--git-dir=xx//depot'-test_expect_success'clone --branch''+test_expect_failure'clone --branch should checkout master''gitp4clone--branch=refs/remotes/p4/sb--dest="$git"//depot&&test_when_finishedcleanup_git&&(cd"$git"&&-gitls-files>files&&-test_line_count=0files&&-test_path_is_file.git/refs/remotes/p4/sb+gitrev-parserefs/remotes/p4/sb>sb&&+gitrev-parserefs/heads/master>master&&+test_cmpsbmaster&&+gitrev-parseHEAD>head&&+test_cmpsbhead+)+'++test_expect_failure'sync when branch is not called master should work''+gitp4clone--branch=refs/remotes/p4/sb--dest="$git"//depot@2&&+test_when_finishedcleanup_git&&+(+cd"$git"&&+gitp4sync&&+gitshow-s--format=%srefs/remotes/p4/sb>show&&+grep"change 3"show+)+'++# engages --detect-branches code, which will do filename filtering so+# no sync to either b1 or b2+test_expect_success'sync when two branches but no master should noop''+test_when_finishedcleanup_git&&+(+cd"$git"&&+gitinit&&+gitp4sync--branch=refs/remotes/p4/b1//depot@2&&+gitp4sync--branch=refs/remotes/p4/b2//depot@2&&+gitp4sync&&+gitshow-s--format=%srefs/remotes/p4/b1>show&&+grep"Initial import"show&&+gitshow-s--format=%srefs/remotes/p4/b2>show&&+grep"Initial import"show+)+'++test_expect_failure'sync --branch updates specified branch''+test_when_finishedcleanup_git&&+(+cd"$git"&&+gitinit&&+gitp4sync--branch=refs/remotes/p4/b1//depot@2&&+gitp4sync--branch=refs/remotes/p4/b2//depot@2&&+gitp4sync--branch=refs/remotes/p4/b2&&+gitshow-s--format=%srefs/remotes/p4/b1>show&&+grep"Initial import"show&&+gitshow-s--format=%srefs/remotes/p4/b2>show&&+grep"change 3"show)'
@@ -2754,23 +2754,23 @@ class P4Sync(Command, P4UserMap):self.changeRange=""self.initialParent=""self.previousDepotPaths=[]+self.hasOrigin=False# map from branch depot path to parent branchself.knownBranches={}self.initialParents={}-self.hasOrigin=originP4BranchesExist()-ifnotself.syncWithOrigin:-self.hasOrigin=Falseifself.importIntoRemotes:self.refPrefix="refs/remotes/p4/"else:self.refPrefix="refs/heads/p4/"-ifself.syncWithOriginandself.hasOrigin:-ifnotself.silent:-print"Syncing with origin first by calling git fetch origin"-system("git fetch origin")+ifself.syncWithOrigin:+self.hasOrigin=originP4BranchesExist()+ifself.hasOrigin:+ifnotself.silent:+print'Syncing with origin first, using "git fetch origin"'+system("git fetch origin")iflen(self.branch)==0:self.branch=self.refPrefix+"master"
@@ -553,27 +553,36 @@ def gitConfigList(key):_gitConfig[key]=read_pipe("git config --get-all %s"%key,ignore_error=True).strip().split(os.linesep)return_gitConfig[key]-defp4BranchesInGit(branchesAreInRemotes=True):+defp4BranchesInGit(branchesAreInRemotes=True):+"""Find all the branches whose names start with "p4/", looking+inremotesorheadsasspecifiedbytheargument.Return+adictionaryof{branch:revision}foreachonefound.+Thebranchnamesaretheshortnames,withoutany+"p4/"prefix."""+branches={}cmdline="git rev-parse --symbolic "ifbranchesAreInRemotes:-cmdline+=" --remotes"+cmdline+="--remotes"else:-cmdline+=" --branches"+cmdline+="--branches"forlineinread_pipe_lines(cmdline):line=line.strip()-## only import to p4/-ifnotline.startswith('p4/')orline=="p4/HEAD":+# only import to p4/+ifnotline.startswith('p4/'):+continue+# special symbolic ref to p4/master+ifline=="p4/HEAD":continue-branch=line-# strip off p4-branch=re.sub("^p4/","",line)+# strip off p4/ prefix+branch=line[len("p4/"):]branches[branch]=parseRevision(line)+returnbranchesdeffindUpstreamBranchPoint(head="HEAD"):
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:55:46
It is four lines of code used in only one place. Simplify by
including it where it is used.
Signed-off-by: Pete Wyckoff <redacted>
---
git-p4.py | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
@@ -2518,13 +2518,6 @@ class P4Sync(Command, P4UserMap):branch=branch[len(self.projectName):]self.knownBranches[branch]=branch-deflistExistingP4GitBranches(self):-# branches holds mapping from name to commit-branches=p4BranchesInGit(self.importIntoRemotes)-self.p4BranchesInGit=branches.keys()-forbranchinbranches.keys():-self.initialParents[self.refPrefix+branch]=branches[branch]-defupdateOptionDict(self,d):option_keys={}ifself.keepRepoPath:
@@ -2805,7 +2798,12 @@ class P4Sync(Command, P4UserMap):ifargs==[]:ifself.hasOrigin:createOrUpdateBranchesFromOrigin(self.refPrefix,self.silent)-self.listExistingP4GitBranches()++# branches holds mapping from branch name to sha1+branches=p4BranchesInGit(self.importIntoRemotes)+self.p4BranchesInGit=branches.keys()+forbranchinbranches.keys():+self.initialParents[self.refPrefix+branch]=branches[branch]iflen(self.p4BranchesInGit)>1:ifnotself.silent:
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:55:46
There is code to create a symbolic reference from p4/HEAD to
p4/master. This allows saying "git show p4" as a shortcut
to "git show p4/master", for example.
But this reference was only created on the second "git p4 sync"
(or first sync after a clone). Make it work on the initial
clone or sync.
Signed-off-by: Pete Wyckoff <redacted>
---
git-p4.py | 12 ++++++++----
t/t9806-git-p4-options.sh | 23 +++++++++++++++++++++++
2 files changed, 31 insertions(+), 4 deletions(-)
@@ -2778,10 +2778,7 @@ class P4Sync(Command, P4UserMap):self.branch=self.refPrefix+"master"ifgitBranchExists("refs/heads/p4")andself.importIntoRemotes:system("git update-ref %s refs/heads/p4"%self.branch)-system("git branch -D p4");-# create it /after/ importing, when master exists-ifnotgitBranchExists(self.refPrefix+"HEAD")andself.importIntoRemotesandgitBranchExists(self.branch):-system("git symbolic-ref %sHEAD %s"%(self.refPrefix,self.branch))+system("git branch -D p4")# accept either the command-line option, or the configuration variableifself.useClientSpec:
@@ -3013,6 +3010,13 @@ class P4Sync(Command, P4UserMap):read_pipe("git update-ref -d %s"%branch)os.rmdir(os.path.join(os.environ.get("GIT_DIR",".git"),self.tempBranchLocation))+# Create a symbolic ref p4/HEAD pointing to p4/<branch> to allow+# a convenient shortcut refname "p4".+ifself.importIntoRemotes:+head_ref=self.refPrefix+"HEAD"+ifnotgitBranchExists(head_ref)andgitBranchExists(self.branch):+system(["git","symbolic-ref",head_ref,self.branch])+returnTrueclassP4Rebase(Command):
@@ -83,6 +83,29 @@ test_expect_failure 'sync --branch updates specified branch' ')'+# allows using the refname "p4" as a short name for p4/master+test_expect_success'clone creates HEAD symbolic reference''+gitp4clone--dest="$git"//depot&&+test_when_finishedcleanup_git&&+(+cd"$git"&&+gitrev-parse--verifyrefs/remotes/p4/master>master&&+gitrev-parse--verifyp4>p4&&+test_cmpmasterp4+)+'++test_expect_success'clone --branch creates HEAD symbolic reference''+gitp4clone--branch=refs/remotes/p4/sb--dest="$git"//depot&&+test_when_finishedcleanup_git&&+(+cd"$git"&&+gitrev-parse--verifyrefs/remotes/p4/sb>sb&&+gitrev-parse--verifyp4>p4&&+test_cmpsbp4+)+'+ test_expect_success'clone --changesfile''test_when_finished"rm cf"&&printf"1\n3\n">cf&&
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:55:46
Make sure that the standard branches are created as expected.
Signed-off-by: Pete Wyckoff <redacted>
---
t/t9800-git-p4-basic.sh | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
@@ -160,9 +160,12 @@ test_expect_success 'clone --bare should make a bare repository' 'test_when_finishedcleanup_git&&(cd"$git"&&-test!-d.git&&-bare=`gitconfig--getcore.bare`&&-test"$bare"=true+test_path_is_missing.git&&+gitconfig--get--boolcore.baretrue&&+gitrev-parse--verifyrefs/remotes/p4/master&&+gitrev-parse--verifyrefs/remotes/p4/HEAD&&+gitrev-parse--verifyrefs/heads/master&&+gitrev-parse--verifyHEAD)'
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:55:46
When using the --branch argument to "git p4 clone", one
might specify a destination for p4 changes different from
the default refs/remotes/p4/master. Both cases should
create a master branch and checkout files.
Signed-off-by: Pete Wyckoff <redacted>
---
Documentation/git-p4.txt | 3 +--
git-p4.py | 20 +++++++++-----------
t/t9806-git-p4-options.sh | 2 +-
3 files changed, 11 insertions(+), 14 deletions(-)
@@ -174,8 +174,7 @@ subsequent 'sync' operations. --branch <branch>:: Import changes into given branch. If the branch starts with 'refs/', it will be used as is, otherwise the path 'refs/heads/'- will be prepended. The default branch is 'master'. If used- with an initial clone, no HEAD will be checked out.+ will be prepended. The default branch is 'p4/master'. + This example imports a new remote "p4/proj2" into an existing git repository:
@@ -3124,17 +3124,15 @@ class P4Clone(P4Sync):ifnotP4Sync.run(self,depotPaths):returnFalse-ifself.branch!="master":-ifself.importIntoRemotes:-masterbranch="refs/remotes/p4/master"-else:-masterbranch="refs/heads/p4/master"-ifgitBranchExists(masterbranch):-system("git branch master %s"%masterbranch)-ifnotself.cloneBare:-system("git checkout -f")-else:-print"Could not detect main branch. No checkout/master branch created."++# create a master branch and check out a work tree+ifgitBranchExists(self.branch):+system(["git","branch","master",self.branch])+ifnotself.cloneBare:+system(["git","checkout","-f"])+else:+print'Not checking out any branch, use ' \+'"git checkout -q -b master <branch>"'# auto-set this variable if invoked with --use-client-specifself.useClientSpec_from_options:
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:55:46
Make sure that the example on how to use git-p4.branchList
works if typed directly. In particular, it does not make sense
to set a config variable until the git repository has been
initialized.
Reported-by: Olivier Delalleau <redacted>
Signed-off-by: Pete Wyckoff <redacted>
---
Documentation/git-p4.txt | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
@@ -393,8 +393,10 @@ the path elements in the p4 repository. The example above relied on the presence of the p4 branch. Without p4 branches, the same result will occur with: ----+git init depot+cd depot git config git-p4.branchList main:branch1-git p4 clone --detect-branches //depot@all+git p4 clone --detect-branches //depot@all . ----
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:55:46
For a clone or sync, --branch says where the newly imported
branch should go, or which existing branch to sync up. It
takes an argument, which is currently either something that
starts with "refs/", or if not, "refs/heads/p4" is prepended.
Putting it in heads seems like a bad default; these should
go in remotes/p4/ in most situations. Make that the new default,
and be more liberal in the form of the branch name.
Signed-off-by: Pete Wyckoff <redacted>
---
Documentation/git-p4.txt | 7 +++++--
git-p4.py | 12 +++++++++++-
t/t9806-git-p4-options.sh | 21 +++++++++++++++++++++
3 files changed, 37 insertions(+), 3 deletions(-)
@@ -173,8 +173,11 @@ subsequent 'sync' operations. --branch <branch>:: Import changes into given branch. If the branch starts with- 'refs/', it will be used as is, otherwise the path 'refs/heads/'- will be prepended. The default branch is 'p4/master'.+ 'refs/', it will be used as is. Otherwise if it does not start+ with 'p4/', that prefix is added. The branch is assumed to+ name a remote tracking, but this can be modified using+ '--import-local', or by giving a full ref name. The default+ branch is 'master'. + This example imports a new remote "p4/proj2" into an existing git repository:
@@ -2847,8 +2847,18 @@ class P4Sync(Command, P4UserMap):ifnotself.silentandnotself.detectBranches:print"Performing incremental import into %s git branch"%self.branch+# accept multiple ref name abbreviations:+# refs/foo/bar/branch -> use it exactly+# p4/branch -> prepend refs/remotes/ or refs/heads/+# branch -> prepend refs/remotes/p4/ or refs/heads/p4/ifnotself.branch.startswith("refs/"):-self.branch="refs/heads/"+self.branch+ifself.importIntoRemotes:+prepend="refs/remotes/"+else:+prepend="refs/heads/"+ifnotself.branch.startswith("p4/"):+prepend+="p4/"+self.branch=prepend+self.branchiflen(args)==0andself.depotPaths:ifnotself.silent:
@@ -51,6 +51,27 @@ test_expect_failure 'sync when branch is not called master should work' ')'+test_expect_success'sync --branch builds the full ref name correctly''+test_when_finishedcleanup_git&&+(+cd"$git"&&+gitinit&&++gitp4sync--branch=b1//depot&&+gitrev-parse--verifyrefs/remotes/p4/b1&&+gitp4sync--branch=p4/b2//depot&&+gitrev-parse--verifyrefs/remotes/p4/b2&&++gitp4sync--import-local--branch=h1//depot&&+gitrev-parse--verifyrefs/heads/p4/h1&&+gitp4sync--import-local--branch=p4/h2//depot&&+gitrev-parse--verifyrefs/heads/p4/h2&&++gitp4sync--branch=refs/stuff//depot&&+gitrev-parse--verifyrefs/stuff+)+'+# engages --detect-branches code, which will do filename filtering so# no sync to either b1 or b2 test_expect_success'sync when two branches but no master should noop''
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:55:46
This was set in a couple of places, both of which were very
far away from its use. Move it a bit closer to importChanges(),
and add some comments.
Signed-off-by: Pete Wyckoff <redacted>
---
git-p4.py | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
@@ -2689,6 +2689,7 @@ class P4Sync(Command, P4UserMap):files=self.extractFilesFromCommit(description)self.commit(description,files,self.branch,self.initialParent)+# only needed once, to connect to the previous commitself.initialParent=""exceptIOError:printself.gitError.read()
@@ -2754,7 +2755,6 @@ class P4Sync(Command, P4UserMap):defrun(self,args):self.depotPaths=[]self.changeRange=""-self.initialParent=""self.previousDepotPaths=[]self.hasOrigin=False
@@ -2842,8 +2842,6 @@ class P4Sync(Command, P4UserMap):ifp4Change>0:self.depotPaths=sorted(self.previousDepotPaths)self.changeRange="@%s,#head"%p4Change-ifnotself.detectBranches:-self.initialParent=parseRevision(self.branch)ifnotself.silentandnotself.detectBranches:print"Performing incremental import into %s git branch"%self.branch
@@ -2988,6 +2986,14 @@ class P4Sync(Command, P4UserMap):self.updatedBranches=set()+ifnotself.detectBranches:+ifargs:+# start a new branch+self.initialParent=""+else:+# build on a previous revision+self.initialParent=parseRevision(self.branch)+self.importChanges(changes)ifnotself.silent:
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:55:46
If --branch was used to build a repository with no
refs/remotes/p4/master, future syncs will not know
which branch to sync. Notice this situation and
print a helpful error message.
Signed-off-by: Pete Wyckoff <redacted>
---
git-p4.py | 29 +++++++++++++++++++++++++++--
t/t9806-git-p4-options.sh | 9 ++++-----
2 files changed, 31 insertions(+), 7 deletions(-)
@@ -585,6 +585,17 @@ def p4BranchesInGit(branchesAreInRemotes=True):returnbranches+defbranch_exists(branch):+"""Make sure that the given ref name really exists."""++cmd=["git","rev-parse","--symbolic","--verify",branch]+p=subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)+out,_=p.communicate()+ifp.returncode:+returnFalse+# expect exactly one line of output: the branch name+returnout.rstrip()==branch+deffindUpstreamBranchPoint(head="HEAD"):branches=p4BranchesInGit()# map from depot-path to branch name
@@ -2774,6 +2785,7 @@ class P4Sync(Command, P4UserMap):print'Syncing with origin first, using "git fetch origin"'system("git fetch origin")+branch_arg_given=bool(self.branch)iflen(self.branch)==0:self.branch=self.refPrefix+"master"ifgitBranchExists("refs/heads/p4")andself.importIntoRemotes:
@@ -2967,8 +2979,21 @@ class P4Sync(Command, P4UserMap):else:# catch "git p4 sync" with no new branches, in a repo that# does not have any existing p4 branches-iflen(args)==0andnotself.p4BranchesInGit:-die("No remote p4 branches. Perhaps you never did \"git p4 clone\" in here.");+iflen(args)==0:+ifnotself.p4BranchesInGit:+die("No remote p4 branches. Perhaps you never did \"git p4 clone\" in here.")++# The default branch is master, unless --branch is used to+# specify something else. Make sure it exists, or complain+# nicely about how to use --branch.+ifnotself.detectBranches:+ifnotbranch_exists(self.branch):+ifbranch_arg_given:+die("Error: branch %s does not exist."%self.branch)+else:+die("Error: no branch %s; perhaps specify one with --branch."%+self.branch)+ifself.verbose:print"Getting p4 changes for %s...%s"%(', '.join(self.depotPaths),self.changeRange)
@@ -40,14 +40,13 @@ test_expect_success 'clone --branch should checkout master' ')'-test_expect_failure'sync when branch is not called master should work''-gitp4clone--branch=refs/remotes/p4/sb--dest="$git"//depot@2&&+test_expect_success'sync when no master branch prints a nice error''test_when_finishedcleanup_git&&+gitp4clone--branch=refs/remotes/p4/sb--dest="$git"//depot@2&&(cd"$git"&&-gitp4sync&&-gitshow-s--format=%srefs/remotes/p4/sb>show&&-grep"change 3"show+test_must_failgitp4sync2>err&&+grep"Error: no branch refs/remotes/p4/master"err)'
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:55:46
It is legal to sync a branch with a different name than
refs/remotes/p4/master, and to do so even when master does
not exist.
Signed-off-by: Pete Wyckoff <redacted>
---
Documentation/git-p4.txt | 5 +++++
git-p4.py | 14 +++++++++++---
t/t9806-git-p4-options.sh | 8 ++++----
3 files changed, 20 insertions(+), 7 deletions(-)
@@ -112,6 +112,11 @@ will be fetched and consulted first during a 'git p4 sync'. Since importing directly from p4 is considerably slower than pulling changes from a git remote, this can be useful in a multi-developer environment.+If there are multiple branches, doing 'git p4 sync' will automatically+use the "BRANCH DETECTION" algorithm to try to partition new changes+into the right branch. This can be overridden with the '--branch'+option to specify just a single branch to update.+ Rebase ~~~~~~
@@ -2810,14 +2810,22 @@ class P4Sync(Command, P4UserMap):# branches holds mapping from branch name to sha1branches=p4BranchesInGit(self.importIntoRemotes)-self.p4BranchesInGit=branches.keys()-forbranchinbranches.keys():-self.initialParents[self.refPrefix+branch]=branches[branch]++# restrict to just this one, disabling detect-branches+ifbranch_arg_given:+short=self.branch.split("/")[-1]+ifshortinbranches:+self.p4BranchesInGit=[short]+else:+self.p4BranchesInGit=branches.keys()iflen(self.p4BranchesInGit)>1:ifnotself.silent:print"Importing from/into multiple branches"self.detectBranches=True+forbranchinbranches.keys():+self.initialParents[self.refPrefix+branch]= \+branches[branch]ifself.verbose:print"branches: %s"%self.p4BranchesInGit
@@ -88,14 +88,14 @@ test_expect_success 'sync when two branches but no master should noop' ')'-test_expect_failure'sync --branch updates specified branch''+test_expect_success'sync --branch updates specific branch, no detection''test_when_finishedcleanup_git&&(cd"$git"&&gitinit&&-gitp4sync--branch=refs/remotes/p4/b1//depot@2&&-gitp4sync--branch=refs/remotes/p4/b2//depot@2&&-gitp4sync--branch=refs/remotes/p4/b2&&+gitp4sync--branch=b1//depot@2&&+gitp4sync--branch=b2//depot@2&&+gitp4sync--branch=b2&&gitshow-s--format=%srefs/remotes/p4/b1>show&&grep"Initial import"show&&gitshow-s--format=%srefs/remotes/p4/b2>show&&
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:55:46
Tests assume that this is set to something valid. Make sure
that the 'clone --use-client-spec' does not leak its changes
out into the rest of the tests.
Signed-off-by: Pete Wyckoff <redacted>
---
t/t9806-git-p4-options.sh | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:55:46
It finds its upstream and applies the commit properly, but
the sync step will fail unless it is told which branch to
work on.
Signed-off-by: Pete Wyckoff <redacted>
---
Documentation/git-p4.txt | 5 +++++
git-p4.py | 6 +++++-
t/t9806-git-p4-options.sh | 25 +++++++++++++++++++++++++
3 files changed, 35 insertions(+), 1 deletion(-)
@@ -294,6 +294,11 @@ These options can be used to modify 'git p4 submit' behavior. to bypass the prompt, causing conflicting commits to be automatically skipped, or to quit trying to apply commits, without prompting.+--branch <branch>::+ After submitting, sync this named branch instead of the default+ p4/master. See the "Sync options" section above for more+ information.+ Rebase options ~~~~~~~~~~~~~~ These options can be used to modify 'git p4 rebase' behavior.
@@ -927,7 +927,8 @@ class P4Submit(Command, P4UserMap):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"),optparse.make_option("--conflict",dest="conflict_behavior",-choices=self.conflict_behavior_choices)+choices=self.conflict_behavior_choices),+optparse.make_option("--branch",dest="branch"),]self.description="Submit changes from git to the perforce depot."self.usage+=" [name of git branch to submit into perforce depot]"
@@ -940,6 +941,7 @@ class P4Submit(Command, P4UserMap):self.isWindows=(platform.system()=="Windows")self.exportLabels=Falseself.p4HasMoveCommand=p4_has_move_command()+self.branch=Nonedefcheck(self):iflen(p4CmdList("opened ..."))>0:
@@ -1676,6 +1678,8 @@ class P4Submit(Command, P4UserMap):print"All commits applied!"sync=P4Sync()+ifself.branch:+sync.branch=self.branchsync.run([])rebase=P4Rebase()
@@ -251,6 +251,31 @@ test_expect_success 'clone --use-client-spec' ')'+test_expect_success'submit works with no p4/master''+test_when_finishedcleanup_git&&+gitp4clone--branch=b1//depot@1,2--destination="$git"&&+(+cd"$git"&&+test_commitsubmit-1-branch&&+gitconfiggit-p4.skipSubmitEdittrue&&+gitp4submit--branch=b1+)+'++# The sync/rebase part post-submit will engage detect-branches+# machinery which will not do anything in this particular test.+test_expect_success'submit works with two branches''+test_when_finishedcleanup_git&&+gitp4clone--branch=b1//depot@1,2--destination="$git"&&+(+cd"$git"&&+gitp4sync--branch=b2//depot@1,3&&+test_commitsubmit-2-branches&&+gitconfiggit-p4.skipSubmitEdittrue&&+gitp4submit+)+'+ test_expect_success'kill p4d''kill_p4d'