Skip to content

Commit

Permalink
git p4: fix sync --branch when no master branch
Browse files Browse the repository at this point in the history
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 <pw@padd.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Pete Wyckoff authored and Junio C Hamano committed Jan 15, 2013
1 parent 5a8e84c commit 8c9e8b6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
5 changes: 5 additions & 0 deletions Documentation/git-p4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~
Expand Down
14 changes: 11 additions & 3 deletions git-p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -2804,14 +2804,22 @@ def run(self, args):

# branches holds mapping from branch name to sha1
branches = p4BranchesInGit(self.importIntoRemotes)
self.p4BranchesInGit = branches.keys()
for branch in branches.keys():
self.initialParents[self.refPrefix + branch] = branches[branch]

# restrict to just this one, disabling detect-branches
if branch_arg_given:
short = self.branch.split("/")[-1]
if short in branches:
self.p4BranchesInGit = [ short ]
else:
self.p4BranchesInGit = branches.keys()

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

if self.verbose:
print "branches: %s" % self.p4BranchesInGit
Expand Down
8 changes: 4 additions & 4 deletions t/t9806-git-p4-options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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_finished cleanup_git &&
(
cd "$git" &&
git init &&
git p4 sync --branch=refs/remotes/p4/b1 //depot@2 &&
git p4 sync --branch=refs/remotes/p4/b2 //depot@2 &&
git p4 sync --branch=refs/remotes/p4/b2 &&
git p4 sync --branch=b1 //depot@2 &&
git p4 sync --branch=b2 //depot@2 &&
git p4 sync --branch=b2 &&
git show -s --format=%s refs/remotes/p4/b1 >show &&
grep "Initial import" show &&
git show -s --format=%s refs/remotes/p4/b2 >show &&
Expand Down

0 comments on commit 8c9e8b6

Please sign in to comment.