Skip to content

Commit 8c9e8b6

Browse files
Pete Wyckoffgitster
authored andcommitted
git p4: fix sync --branch when no master branch
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5a8e84c commit 8c9e8b6

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

Documentation/git-p4.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ will be fetched and consulted first during a 'git p4 sync'. Since
112112
importing directly from p4 is considerably slower than pulling changes
113113
from a git remote, this can be useful in a multi-developer environment.
114114

115+
If there are multiple branches, doing 'git p4 sync' will automatically
116+
use the "BRANCH DETECTION" algorithm to try to partition new changes
117+
into the right branch. This can be overridden with the '--branch'
118+
option to specify just a single branch to update.
119+
115120

116121
Rebase
117122
~~~~~~

git-p4.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2804,14 +2804,22 @@ def run(self, args):
28042804

28052805
# branches holds mapping from branch name to sha1
28062806
branches = p4BranchesInGit(self.importIntoRemotes)
2807-
self.p4BranchesInGit = branches.keys()
2808-
for branch in branches.keys():
2809-
self.initialParents[self.refPrefix + branch] = branches[branch]
2807+
2808+
# restrict to just this one, disabling detect-branches
2809+
if branch_arg_given:
2810+
short = self.branch.split("/")[-1]
2811+
if short in branches:
2812+
self.p4BranchesInGit = [ short ]
2813+
else:
2814+
self.p4BranchesInGit = branches.keys()
28102815

28112816
if len(self.p4BranchesInGit) > 1:
28122817
if not self.silent:
28132818
print "Importing from/into multiple branches"
28142819
self.detectBranches = True
2820+
for branch in branches.keys():
2821+
self.initialParents[self.refPrefix + branch] = \
2822+
branches[branch]
28152823

28162824
if self.verbose:
28172825
print "branches: %s" % self.p4BranchesInGit

t/t9806-git-p4-options.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ test_expect_success 'sync when two branches but no master should noop' '
8888
)
8989
'
9090

91-
test_expect_failure 'sync --branch updates specified branch' '
91+
test_expect_success 'sync --branch updates specific branch, no detection' '
9292
test_when_finished cleanup_git &&
9393
(
9494
cd "$git" &&
9595
git init &&
96-
git p4 sync --branch=refs/remotes/p4/b1 //depot@2 &&
97-
git p4 sync --branch=refs/remotes/p4/b2 //depot@2 &&
98-
git p4 sync --branch=refs/remotes/p4/b2 &&
96+
git p4 sync --branch=b1 //depot@2 &&
97+
git p4 sync --branch=b2 //depot@2 &&
98+
git p4 sync --branch=b2 &&
9999
git show -s --format=%s refs/remotes/p4/b1 >show &&
100100
grep "Initial import" show &&
101101
git show -s --format=%s refs/remotes/p4/b2 >show &&

0 commit comments

Comments
 (0)