From: Pete Wyckoff Date: Tue, 15 Jan 2013 00:47:06 +0000 (-0500) Subject: git p4: fix sync --branch when no master branch X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8c9e8b6e756cce90797e19dc64e3b51426546cf3;p=git.git 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 Signed-off-by: Junio C Hamano --- diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt index 7bd5c290c..e79d0467c 100644 --- a/Documentation/git-p4.txt +++ b/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 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 ~~~~~~ diff --git a/git-p4.py b/git-p4.py index 7b71ceb28..9ea1905db 100755 --- a/git-p4.py +++ b/git-p4.py @@ -2804,14 +2804,22 @@ class P4Sync(Command, P4UserMap): # 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 diff --git a/t/t9806-git-p4-options.sh b/t/t9806-git-p4-options.sh index a51f1221e..3b0000fab 100755 --- a/t/t9806-git-p4-options.sh +++ b/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 && ( 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 &&