git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pete Wyckoff <pw@padd.com>
To: git@vger.kernel.org
Cc: Olivier Delalleau <shish@keba.be>
Subject: [PATCH 07/14] git p4: clone --branch should checkout master
Date: Mon, 14 Jan 2013 19:47:01 -0500	[thread overview]
Message-ID: <1358210828-2369-8-git-send-email-pw@padd.com> (raw)
In-Reply-To: <1358210828-2369-1-git-send-email-pw@padd.com>

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 <pw@padd.com>
---
 Documentation/git-p4.txt  |  3 +--
 git-p4.py                 | 20 +++++++++-----------
 t/t9806-git-p4-options.sh |  2 +-
 3 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt
index beff622..2623bee 100644
--- a/Documentation/git-p4.txt
+++ b/Documentation/git-p4.txt
@@ -174,8 +174,7 @@ subsequent 'sync' operations.
 --branch <branch>::
 	Import changes into given branch.  If the branch starts with
 	'refs/', it will be used as is, otherwise the path 'refs/heads/'
-	will be prepended.  The default branch is 'master'.  If used
-	with an initial clone, no HEAD will be checked out.
+	will be prepended.  The default branch is 'p4/master'.
 +
 This example imports a new remote "p4/proj2" into an existing
 git repository:
diff --git a/git-p4.py b/git-p4.py
index 537eac6..d92f00c 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -3124,17 +3124,15 @@ class P4Clone(P4Sync):
 
         if not P4Sync.run(self, depotPaths):
             return False
-        if self.branch != "master":
-            if self.importIntoRemotes:
-                masterbranch = "refs/remotes/p4/master"
-            else:
-                masterbranch = "refs/heads/p4/master"
-            if gitBranchExists(masterbranch):
-                system("git branch master %s" % masterbranch)
-                if not self.cloneBare:
-                    system("git checkout -f")
-            else:
-                print "Could not detect main branch. No checkout/master branch created."
+
+        # create a master branch and check out a work tree
+        if gitBranchExists(self.branch):
+            system([ "git", "branch", "master", self.branch ])
+            if not self.cloneBare:
+                system([ "git", "checkout", "-f" ])
+        else:
+            print 'Not checking out any branch, use ' \
+                  '"git checkout -q -b master <branch>"'
 
         # auto-set this variable if invoked with --use-client-spec
         if self.useClientSpec_from_options:
diff --git a/t/t9806-git-p4-options.sh b/t/t9806-git-p4-options.sh
index 4900aef..2ad3a3e 100755
--- a/t/t9806-git-p4-options.sh
+++ b/t/t9806-git-p4-options.sh
@@ -27,7 +27,7 @@ test_expect_success 'clone no --git-dir' '
 	test_must_fail git p4 clone --git-dir=xx //depot
 '
 
-test_expect_failure 'clone --branch should checkout master' '
+test_expect_success 'clone --branch should checkout master' '
 	git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
 	test_when_finished cleanup_git &&
 	(
-- 
1.8.1.350.gdbf6fd0

  parent reply	other threads:[~2013-01-15  0:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-15  0:46 [PATCH 00/14] git p4 branch handling fixes Pete Wyckoff
2013-01-15  0:46 ` [PATCH 01/14] git p4: test sync/clone --branch behavior Pete Wyckoff
2013-01-15  0:46 ` [PATCH 02/14] git p4: rearrange and simplify hasOrigin handling Pete Wyckoff
2013-01-15  0:46 ` [PATCH 03/14] git p4: add comments to p4BranchesInGit Pete Wyckoff
2013-01-15  0:46 ` [PATCH 04/14] git p4: inline listExistingP4GitBranches Pete Wyckoff
2013-01-15  0:46 ` [PATCH 05/14] git p4: create p4/HEAD on initial clone Pete Wyckoff
2013-01-15  0:47 ` [PATCH 06/14] git p4: verify expected refs in clone --bare test Pete Wyckoff
2013-01-15  0:47 ` Pete Wyckoff [this message]
2013-01-15  0:47 ` [PATCH 08/14] git p4 doc: fix branch detection example Pete Wyckoff
2013-01-15  0:47 ` [PATCH 09/14] git p4: allow short ref names to --branch Pete Wyckoff
2013-01-15  0:47 ` [PATCH 10/14] git p4: rearrange self.initialParent use Pete Wyckoff
2013-01-15  0:47 ` [PATCH 11/14] git p4: fail gracefully on sync with no master branch Pete Wyckoff
2013-01-15  0:47 ` [PATCH 12/14] git p4: fix sync --branch when " Pete Wyckoff
2013-01-15  0:47 ` [PATCH 13/14] git p4 test: keep P4CLIENT changes inside subshells Pete Wyckoff
2013-01-15  0:47 ` [PATCH 14/14] git p4: fix submit when no master branch Pete Wyckoff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1358210828-2369-8-git-send-email-pw@padd.com \
    --to=pw@padd.com \
    --cc=git@vger.kernel.org \
    --cc=shish@keba.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).