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 12/14] git p4: fix sync --branch when no master branch
Date: Mon, 14 Jan 2013 19:47:06 -0500	[thread overview]
Message-ID: <1358210828-2369-13-git-send-email-pw@padd.com> (raw)
In-Reply-To: <1358210828-2369-1-git-send-email-pw@padd.com>

It is legal to sync a branch with a different name than
refs/remotes/p4/master, and to do so even when master does
not exist.

Signed-off-by: Pete Wyckoff <pw@padd.com>
---
 Documentation/git-p4.txt  |  5 +++++
 git-p4.py                 | 14 +++++++++++---
 t/t9806-git-p4-options.sh |  8 ++++----
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt
index 7bd5c29..e79d046 100644
--- a/Documentation/git-p4.txt
+++ b/Documentation/git-p4.txt
@@ -112,6 +112,11 @@ will be fetched and consulted first during a 'git p4 sync'.  Since
 importing directly from p4 is considerably slower than pulling changes
 from a git remote, this can be useful in a multi-developer environment.
 
+If there are multiple branches, doing 'git p4 sync' will automatically
+use the "BRANCH DETECTION" algorithm to try to partition new changes
+into the right branch.  This can be overridden with the '--branch'
+option to specify just a single branch to update.
+
 
 Rebase
 ~~~~~~
diff --git a/git-p4.py b/git-p4.py
index 390d3f1..77bde59 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -2810,14 +2810,22 @@ class P4Sync(Command, P4UserMap):
 
             # branches holds mapping from branch name to sha1
             branches = p4BranchesInGit(self.importIntoRemotes)
-            self.p4BranchesInGit = branches.keys()
-            for branch in branches.keys():
-                self.initialParents[self.refPrefix + branch] = branches[branch]
+
+            # restrict to just this one, disabling detect-branches
+            if branch_arg_given:
+                short = self.branch.split("/")[-1]
+                if short in branches:
+                    self.p4BranchesInGit = [ short ]
+            else:
+                self.p4BranchesInGit = branches.keys()
 
             if len(self.p4BranchesInGit) > 1:
                 if not self.silent:
                     print "Importing from/into multiple branches"
                 self.detectBranches = True
+                for branch in branches.keys():
+                    self.initialParents[self.refPrefix + branch] = \
+                        branches[branch]
 
             if self.verbose:
                 print "branches: %s" % self.p4BranchesInGit
diff --git a/t/t9806-git-p4-options.sh b/t/t9806-git-p4-options.sh
index a51f122..3b0000f 100755
--- a/t/t9806-git-p4-options.sh
+++ b/t/t9806-git-p4-options.sh
@@ -88,14 +88,14 @@ test_expect_success 'sync when two branches but no master should noop' '
 	)
 '
 
-test_expect_failure 'sync --branch updates specified branch' '
+test_expect_success 'sync --branch updates specific branch, no detection' '
 	test_when_finished cleanup_git &&
 	(
 		cd "$git" &&
 		git init &&
-		git p4 sync --branch=refs/remotes/p4/b1 //depot@2 &&
-		git p4 sync --branch=refs/remotes/p4/b2 //depot@2 &&
-		git p4 sync --branch=refs/remotes/p4/b2 &&
+		git p4 sync --branch=b1 //depot@2 &&
+		git p4 sync --branch=b2 //depot@2 &&
+		git p4 sync --branch=b2 &&
 		git show -s --format=%s refs/remotes/p4/b1 >show &&
 		grep "Initial import" show &&
 		git show -s --format=%s refs/remotes/p4/b2 >show &&
-- 
1.8.1.350.gdbf6fd0

  parent reply	other threads:[~2013-01-15  0:51 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 ` [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 ` Pete Wyckoff [this message]
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-13-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).