git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Pete Wyckoff <pw@padd.com>
To: git@vger.kernel.org
Cc: Olivier Delalleau <shish@keba.be>
Subject: [PATCH 09/14] git p4: allow short ref names to --branch
Date: Mon, 14 Jan 2013 19:47:03 -0500	[thread overview]
Message-ID: <1358210828-2369-10-git-send-email-pw@padd.com> (raw)
In-Reply-To: <1358210828-2369-1-git-send-email-pw@padd.com>

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>
---
 Documentation/git-p4.txt  |  7 +++++--
 git-p4.py                 | 12 +++++++++++-
 t/t9806-git-p4-options.sh | 21 +++++++++++++++++++++
 3 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt
index 7c5230e..7bd5c29 100644
--- a/Documentation/git-p4.txt
+++ b/Documentation/git-p4.txt
@@ -173,8 +173,11 @@ 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 'p4/master'.
+	'refs/', it will be used as is.  Otherwise if it does not start
+	with 'p4/', that prefix is added.  The branch is assumed to
+	name a remote tracking, but this can be modified using
+	'--import-local', or by giving a full ref name.  The default
+	branch is '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 d92f00c..5dcb527 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -2847,8 +2847,18 @@ class P4Sync(Command, P4UserMap):
                 if not self.silent and not self.detectBranches:
                     print "Performing incremental import into %s git branch" % self.branch
 
+        # accept multiple ref name abbreviations:
+        #    refs/foo/bar/branch -> use it exactly
+        #    p4/branch -> prepend refs/remotes/ or refs/heads/
+        #    branch -> prepend refs/remotes/p4/ or refs/heads/p4/
         if not self.branch.startswith("refs/"):
-            self.branch = "refs/heads/" + self.branch
+            if self.importIntoRemotes:
+                prepend = "refs/remotes/"
+            else:
+                prepend = "refs/heads/"
+            if not self.branch.startswith("p4/"):
+                prepend += "p4/"
+            self.branch = prepend + self.branch
 
         if len(args) == 0 and self.depotPaths:
             if not self.silent:
diff --git a/t/t9806-git-p4-options.sh b/t/t9806-git-p4-options.sh
index 2ad3a3e..c0d4433 100755
--- a/t/t9806-git-p4-options.sh
+++ b/t/t9806-git-p4-options.sh
@@ -51,6 +51,27 @@ test_expect_failure 'sync when branch is not called master should work' '
 	)
 '
 
+test_expect_success 'sync --branch builds the full ref name correctly' '
+	test_when_finished cleanup_git &&
+	(
+		cd "$git" &&
+		git init &&
+
+		git p4 sync --branch=b1 //depot &&
+		git rev-parse --verify refs/remotes/p4/b1 &&
+		git p4 sync --branch=p4/b2 //depot &&
+		git rev-parse --verify refs/remotes/p4/b2 &&
+
+		git p4 sync --import-local --branch=h1 //depot &&
+		git rev-parse --verify refs/heads/p4/h1 &&
+		git p4 sync --import-local --branch=p4/h2 //depot &&
+		git rev-parse --verify refs/heads/p4/h2 &&
+
+		git p4 sync --branch=refs/stuff //depot &&
+		git rev-parse --verify refs/stuff
+	)
+'
+
 # engages --detect-branches code, which will do filename filtering so
 # no sync to either b1 or b2
 test_expect_success 'sync when two branches but no master should noop' '
-- 
1.8.1.350.gdbf6fd0

  parent reply	other threads:[~2013-01-15  0:50 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 ` [PATCH 07/14] git p4: clone --branch should checkout master Pete Wyckoff
2013-01-15  0:47 ` [PATCH 08/14] git p4 doc: fix branch detection example Pete Wyckoff
2013-01-15  0:47 ` Pete Wyckoff [this message]
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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=1358210828-2369-10-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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).