Browse Source

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 <pw@padd.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Pete Wyckoff 12 years ago committed by Junio C Hamano
parent
commit
8c9e8b6e75
  1. 5
      Documentation/git-p4.txt
  2. 14
      git-p4.py
  3. 8
      t/t9806-git-p4-options.sh

5
Documentation/git-p4.txt

@ -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 importing directly from p4 is considerably slower than pulling changes
from a git remote, this can be useful in a multi-developer environment. 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 Rebase
~~~~~~ ~~~~~~

14
git-p4.py

@ -2804,14 +2804,22 @@ class P4Sync(Command, P4UserMap):


# branches holds mapping from branch name to sha1 # branches holds mapping from branch name to sha1
branches = p4BranchesInGit(self.importIntoRemotes) branches = p4BranchesInGit(self.importIntoRemotes)
self.p4BranchesInGit = branches.keys()
for branch in branches.keys(): # restrict to just this one, disabling detect-branches
self.initialParents[self.refPrefix + branch] = branches[branch] 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 len(self.p4BranchesInGit) > 1:
if not self.silent: if not self.silent:
print "Importing from/into multiple branches" print "Importing from/into multiple branches"
self.detectBranches = True self.detectBranches = True
for branch in branches.keys():
self.initialParents[self.refPrefix + branch] = \
branches[branch]


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

8
t/t9806-git-p4-options.sh

@ -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 && test_when_finished cleanup_git &&
( (
cd "$git" && cd "$git" &&
git init && git init &&
git p4 sync --branch=refs/remotes/p4/b1 //depot@2 && git p4 sync --branch=b1 //depot@2 &&
git p4 sync --branch=refs/remotes/p4/b2 //depot@2 && git p4 sync --branch=b2 //depot@2 &&
git p4 sync --branch=refs/remotes/p4/b2 && git p4 sync --branch=b2 &&
git show -s --format=%s refs/remotes/p4/b1 >show && git show -s --format=%s refs/remotes/p4/b1 >show &&
grep "Initial import" show && grep "Initial import" show &&
git show -s --format=%s refs/remotes/p4/b2 >show && git show -s --format=%s refs/remotes/p4/b2 >show &&

Loading…
Cancel
Save