git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: [JGIT PATCH] Split refspecs on the last : not the first
Date: Fri, 20 Mar 2009 08:12:12 -0700	[thread overview]
Message-ID: <1237561932-26482-1-git-send-email-spearce@spearce.org> (raw)

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

                 reply	other threads:[~2009-03-20 15:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

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

  git send-email \
    --in-reply-to=1237561932-26482-1-git-send-email-spearce@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=robin.rosenberg@dewire.com \
    /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.
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 NNTP newsgroup(s).