Skip to content

Commit 40d69ac

Browse files
Pete Wyckoffgitster
authored andcommitted
git p4: allow short ref names to --branch
For a clone or sync, --branch says where the newly imported branch should go, or which existing branch to sync up. It takes an argument, which is currently either something that starts with "refs/", or if not, "refs/heads/p4" is prepended. Putting it in heads seems like a bad default; these should go in remotes/p4/ in most situations. Make that the new default, and be more liberal in the form of the branch name. Signed-off-by: Pete Wyckoff <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 182edef commit 40d69ac

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

Documentation/git-p4.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,11 @@ subsequent 'sync' operations.
173173

174174
--branch <branch>::
175175
Import changes into given branch. If the branch starts with
176-
'refs/', it will be used as is, otherwise the path 'refs/heads/'
177-
will be prepended. The default branch is 'p4/master'.
176+
'refs/', it will be used as is. Otherwise if it does not start
177+
with 'p4/', that prefix is added. The branch is assumed to
178+
name a remote tracking, but this can be modified using
179+
'--import-local', or by giving a full ref name. The default
180+
branch is 'master'.
178181
+
179182
This example imports a new remote "p4/proj2" into an existing
180183
git repository:

git-p4.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2841,8 +2841,18 @@ def run(self, args):
28412841
if not self.silent and not self.detectBranches:
28422842
print "Performing incremental import into %s git branch" % self.branch
28432843

2844+
# accept multiple ref name abbreviations:
2845+
# refs/foo/bar/branch -> use it exactly
2846+
# p4/branch -> prepend refs/remotes/ or refs/heads/
2847+
# branch -> prepend refs/remotes/p4/ or refs/heads/p4/
28442848
if not self.branch.startswith("refs/"):
2845-
self.branch = "refs/heads/" + self.branch
2849+
if self.importIntoRemotes:
2850+
prepend = "refs/remotes/"
2851+
else:
2852+
prepend = "refs/heads/"
2853+
if not self.branch.startswith("p4/"):
2854+
prepend += "p4/"
2855+
self.branch = prepend + self.branch
28462856

28472857
if len(args) == 0 and self.depotPaths:
28482858
if not self.silent:

t/t9806-git-p4-options.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,27 @@ test_expect_failure 'sync when branch is not called master should work' '
5151
)
5252
'
5353

54+
test_expect_success 'sync --branch builds the full ref name correctly' '
55+
test_when_finished cleanup_git &&
56+
(
57+
cd "$git" &&
58+
git init &&
59+
60+
git p4 sync --branch=b1 //depot &&
61+
git rev-parse --verify refs/remotes/p4/b1 &&
62+
git p4 sync --branch=p4/b2 //depot &&
63+
git rev-parse --verify refs/remotes/p4/b2 &&
64+
65+
git p4 sync --import-local --branch=h1 //depot &&
66+
git rev-parse --verify refs/heads/p4/h1 &&
67+
git p4 sync --import-local --branch=p4/h2 //depot &&
68+
git rev-parse --verify refs/heads/p4/h2 &&
69+
70+
git p4 sync --branch=refs/stuff //depot &&
71+
git rev-parse --verify refs/stuff
72+
)
73+
'
74+
5475
# engages --detect-branches code, which will do filename filtering so
5576
# no sync to either b1 or b2
5677
test_expect_success 'sync when two branches but no master should noop' '

0 commit comments

Comments
 (0)