git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 12/14] git p4: fix sync --branch when no master branch

From
PWPete Wyckoff <pw@padd.com>
Date
Jan 15, 2013, 00:47 UTC
Message-ID
<1358210828-2369-13-git-send-email-pw@padd.com>
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
Previous: Pete WyckoffNext: Pete Wyckoff
Message 13 of 15 in “git p4 branch handling fixes”
  1. 00/14 git p4 branch handling fixesPete Wyckoff, Jan 15, 2013
  2. 01/14 git p4: test sync/clone --branch behaviorPete Wyckoff, Jan 15, 2013
  3. 02/14 git p4: rearrange and simplify hasOrigin handlingPete Wyckoff, Jan 15, 2013
  4. 03/14 git p4: add comments to p4BranchesInGitPete Wyckoff, Jan 15, 2013
  5. 04/14 git p4: inline listExistingP4GitBranchesPete Wyckoff, Jan 15, 2013
  6. 05/14 git p4: create p4/HEAD on initial clonePete Wyckoff, Jan 15, 2013
  7. 06/14 git p4: verify expected refs in clone --bare testPete Wyckoff, Jan 15, 2013
  8. 07/14 git p4: clone --branch should checkout masterPete Wyckoff, Jan 15, 2013
  9. 08/14 git p4 doc: fix branch detection examplePete Wyckoff, Jan 15, 2013
  10. 09/14 git p4: allow short ref names to --branchPete Wyckoff, Jan 15, 2013
  11. 10/14 git p4: rearrange self.initialParent usePete Wyckoff, Jan 15, 2013
  12. 11/14 git p4: fail gracefully on sync with no master branchPete Wyckoff, Jan 15, 2013
  13. 12/14 git p4: fix sync --branch when no master branchPete Wyckoff, Jan 15, 2013
  14. 13/14 git p4 test: keep P4CLIENT changes inside subshellsPete Wyckoff, Jan 15, 2013
  15. 14/14 git p4: fix submit when no master branchPete Wyckoff, Jan 15, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.