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

[JGIT PATCH] Split refspecs on the last : not the first

From
Shawn O. Pearce <spearce@spearce.org>
Date
Mar 20, 2009, 15:12 UTC
Message-ID
<1237561932-26482-1-git-send-email-spearce@spearce.org>

Recent discussion about a potential ':%branchname' syntax for remote branches led rise to the question on #git of whether or not this could be used on the lhs of a push refspec, such as "+:%master:master".

Testing shows git-core permits this, as it must be splitting the refspec with strrchr(), splitting along the last : in the string. Make JGit match the split semantics.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../spearce/jgit/transport/RefSpecTestCase.java    |   12 ++++++++++++
 .../src/org/spearce/jgit/transport/RefSpec.java    |    2 +-
 2 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/transport/RefSpecTestCase.java b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/RefSpecTestCase.java
index 11e7cdb..2f7214c 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/transport/RefSpecTestCase.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/RefSpecTestCase.java
@@ -63,6 +63,18 @@ public void testMasterMaster() {
 		assertFalse(rs.matchDestination(r));
 	}
 
+	public void testSplitLastColon() {
+		final String lhs = ":m:a:i:n:t";
+		final String rhs = "refs/heads/maint";
+		final RefSpec rs = new RefSpec(lhs + ":" + rhs);
+		assertFalse(rs.isForceUpdate());
+		assertFalse(rs.isWildcard());
+		assertEquals(lhs, rs.getSource());
+		assertEquals(rhs, rs.getDestination());
+		assertEquals(lhs + ":" + rhs, rs.toString());
+		assertEquals(rs, new RefSpec(rs.toString()));
+	}
+
 	public void testForceMasterMaster() {
 		final String sn = "refs/heads/master";
 		final RefSpec rs = new RefSpec("+" + sn + ":" + sn);
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/RefSpec.java b/org.spearce.jgit/src/org/spearce/jgit/transport/RefSpec.java
index e75b272..273aacc 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/RefSpec.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/RefSpec.java
@@ -115,7 +115,7 @@ public RefSpec(final String spec) {
 			s = s.substring(1);
 		}
 
-		final int c = s.indexOf(':');
+		final int c = s.lastIndexOf(':');
 		if (c == 0) {
 			s = s.substring(1);
 			if (isWildcard(s))
-- 
1.6.2.1.352.gae594
Message 1 of 1 in “Split refspecs on the last : not the first”
  1. Split refspecs on the last : not the firstShawn O. Pearce, Mar 20, 2009

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.