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>
Pete Wyckoff committed
Jan 14, 2013 at 19:47 UTC
8c9e8b6e756cce90797e19dc64e3b51426546cf3
3 files changed
+20
-7
Documentation/git-p4.txt
+5
@@ -112,6 +112,11 @@ will be fetched and consulted first during a 'git p4 sync'. Since
112
importing directly from p4 is considerably slower than pulling changes
113
from a git remote, this can be useful in a multi-developer environment.
114
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
+
120
121
Rebase
122
~~~~~~
git-p4.py
+11
-3
@@ -2804,14 +2804,22 @@ class P4Sync(Command, P4UserMap):
2804
2805
# branches holds mapping from branch name to sha1
2806
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()
2815
2816
if len(self.p4BranchesInGit) > 1:
2817
if not self.silent:
2818
print "Importing from/into multiple branches"
2819
self.detectBranches = True
2820
+ for branch in branches.keys():
2821
+ self.initialParents[self.refPrefix + branch] = \
2822
+ branches[branch]
2823
2824
if self.verbose:
2825
print "branches: %s" % self.p4BranchesInGit
t/t9806-git-p4-options.sh
+4
-4
@@ -88,14 +88,14 @@ test_expect_success 'sync when two branches but no master should noop' '
88
)
89
'
90
91
-test_expect_failure 'sync --branch updates specified branch' '
91
+test_expect_success 'sync --branch updates specific branch, no detection' '
92
test_when_finished cleanup_git &&
93
(
94
cd "$git" &&
95
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 &&
99
git show -s --format=%s refs/remotes/p4/b1 >show &&
100
grep "Initial import" show &&
101
git show -s --format=%s refs/remotes/p4/b2 >show &&