[JGIT PATCH] Split refspecs on the last : not the first
From: Shawn O. Pearce <hidden>
Date: 2016-06-15 22:46:26
Subsystem:
the rest · Maintainer:
Linus Torvalds
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 <redacted> --- .../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