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 <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pete Wyckoff committed Jan 14, 2013 at 19:47 UTC 40d69ac3a4fd72b879bab9975b26e1b445b5f0cc
3 files changed +37 -3
Documentation/git-p4.txt
+5 -2
@@ -173,8 +173,11 @@ subsequent 'sync' operations.
173
174 --branch <branch>::
175 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'.
181 +
182 This example imports a new remote "p4/proj2" into an existing
183 git repository:
git-p4.py
+11 -1
@@ -2841,8 +2841,18 @@ class P4Sync(Command, P4UserMap):
2841 if not self.silent and not self.detectBranches:
2842 print "Performing incremental import into %s git branch" % self.branch
2843
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/
2848 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
2856
2857 if len(args) == 0 and self.depotPaths:
2858 if not self.silent:
t/t9806-git-p4-options.sh
+21
@@ -51,6 +51,27 @@ test_expect_failure 'sync when branch is not called master should work' '
51 )
52 '
53
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 +
75 # engages --detect-branches code, which will do filename filtering so
76 # no sync to either b1 or b2
77 test_expect_success 'sync when two branches but no master should noop' '