git p4: fix sync --branch when no master branch
authorPete Wyckoff <pw@padd.com>
Tue, 15 Jan 2013 00:47:06 +0000 (19:47 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 15 Jan 2013 17:46:30 +0000 (09:46 -0800)
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>
Documentation/git-p4.txt
git-p4.py
t/t9806-git-p4-options.sh

index 7bd5c290c4dbe97fee653ea2e5178847d482595e..e79d0467c4d7125e2efeb9a489e57aee346c4a00 100644 (file)
@@ -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
 ~~~~~~
index 7b71ceb2880d4a6c757a39b95a762787f22c21eb..9ea1905dbedd57dbde08dc72c906564c5b15906a 100755 (executable)
--- 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
index a51f1221edafa049e0e723378c667b70fd523d54..3b0000fab26fad322ff99812441dd83023f2f231 100755 (executable)
@@ -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 &&