Skip to content

Commit c595956

Browse files
Pete Wyckoffgitster
authored andcommitted
git p4: clone --branch should checkout master
When using the --branch argument to "git p4 clone", one might specify a destination for p4 changes different from the default refs/remotes/p4/master. Both cases should create a master branch and checkout files. Signed-off-by: Pete Wyckoff <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 695d699 commit c595956

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

Documentation/git-p4.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ subsequent 'sync' operations.
174174
--branch <branch>::
175175
Import changes into given branch. If the branch starts with
176176
'refs/', it will be used as is, otherwise the path 'refs/heads/'
177-
will be prepended. The default branch is 'master'. If used
178-
with an initial clone, no HEAD will be checked out.
177+
will be prepended. The default branch is 'p4/master'.
179178
+
180179
This example imports a new remote "p4/proj2" into an existing
181180
git repository:

git-p4.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,17 +3118,15 @@ def run(self, args):
31183118

31193119
if not P4Sync.run(self, depotPaths):
31203120
return False
3121-
if self.branch != "master":
3122-
if self.importIntoRemotes:
3123-
masterbranch = "refs/remotes/p4/master"
3124-
else:
3125-
masterbranch = "refs/heads/p4/master"
3126-
if gitBranchExists(masterbranch):
3127-
system("git branch master %s" % masterbranch)
3128-
if not self.cloneBare:
3129-
system("git checkout -f")
3130-
else:
3131-
print "Could not detect main branch. No checkout/master branch created."
3121+
3122+
# create a master branch and check out a work tree
3123+
if gitBranchExists(self.branch):
3124+
system([ "git", "branch", "master", self.branch ])
3125+
if not self.cloneBare:
3126+
system([ "git", "checkout", "-f" ])
3127+
else:
3128+
print 'Not checking out any branch, use ' \
3129+
'"git checkout -q -b master <branch>"'
31323130

31333131
# auto-set this variable if invoked with --use-client-spec
31343132
if self.useClientSpec_from_options:

t/t9806-git-p4-options.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test_expect_success 'clone no --git-dir' '
2727
test_must_fail git p4 clone --git-dir=xx //depot
2828
'
2929

30-
test_expect_failure 'clone --branch should checkout master' '
30+
test_expect_success 'clone --branch should checkout master' '
3131
git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
3232
test_when_finished cleanup_git &&
3333
(

0 commit comments

Comments
 (0)