]> source.dussan.org Git - jgit.git/commitdiff
Handle the tilde notation (~user) of git url 34/1134/1
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Wed, 14 Jul 2010 23:16:09 +0000 (01:16 +0200)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Wed, 14 Jul 2010 23:16:09 +0000 (01:16 +0200)
When the path is prefixed with ~ the URI parser thought about this
as /~. Strip the / if the next character is the tilde.

Bug: 307017
Change-Id: I58203e5617956b46d83e8987d1f8042beddffac3
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java

index d2d37a7edcc1e640d6e2bbe7c21aecd769928aba..ff8c9a6c1edb584c60c953c2d3343c61a2c71a6a 100644 (file)
@@ -250,6 +250,53 @@ public class URIishTest extends TestCase {
                assertEquals(u, new URIish(str));
        }
 
+       public void testGitWithUserHome() throws Exception {
+               final String str = "git://example.com/~some/p ath";
+               URIish u = new URIish(str);
+               assertEquals("git", u.getScheme());
+               assertTrue(u.isRemote());
+               assertEquals("~some/p ath", u.getPath());
+               assertEquals("example.com", u.getHost());
+               assertNull(u.getUser());
+               assertNull(u.getPass());
+               assertEquals(-1, u.getPort());
+               assertEquals(str, u.toPrivateString());
+               assertEquals(u.setPass(null).toPrivateString(), u.toString());
+               assertEquals(u, new URIish(str));
+       }
+
+       /* Resolving ~user is beyond standard Java API and need more support
+       public void testFileWithUserHome() throws Exception {
+               final String str = "~some/p ath";
+               URIish u = new URIish(str);
+               assertEquals("git", u.getScheme());
+               assertTrue(u.isRemote());
+               assertEquals("~some/p ath", u.getPath());
+               assertEquals("example.com", u.getHost());
+               assertNull(u.getUser());
+               assertNull(u.getPass());
+               assertEquals(-1, u.getPort());
+               assertEquals(str, u.toPrivateString());
+               assertEquals(u.setPass(null).toPrivateString(), u.toString());
+               assertEquals(u, new URIish(str));
+       }
+       */
+
+       public void testFileWithNoneUserHomeWithTilde() throws Exception {
+               final String str = "/~some/p ath";
+               URIish u = new URIish(str);
+               assertNull(u.getScheme());
+               assertFalse(u.isRemote());
+               assertEquals("/~some/p ath", u.getPath());
+               assertNull(u.getHost());
+               assertNull(u.getUser());
+               assertNull(u.getPass());
+               assertEquals(-1, u.getPort());
+               assertEquals(str, u.toPrivateString());
+               assertEquals(u.setPass(null).toPrivateString(), u.toString());
+               assertEquals(u, new URIish(str));
+       }
+
        public void testGetNullHumanishName() {
                try {
                        new URIish().getHumanishName();
index 15bd0b1dee731682aeffadebffaf499c3a921caf..3f533281b4d0c830a9822139982a707905b784ae 100644 (file)
@@ -104,6 +104,9 @@ public class URIish implements Serializable {
                        && (path.charAt(1) >= 'A' && path.charAt(1) <= 'Z'
                         || path.charAt(1) >= 'a' && path.charAt(1) <= 'z'))
                                path = path.substring(1);
+                       else if (scheme != null && path.length() >= 2
+                                       && path.charAt(0) == '/' && path.charAt(1) == '~')
+                               path = path.substring(1);
                } else {
                        matcher = SCP_URI.matcher(s);
                        if (matcher.matches()) {