Browse Source

Merge "Handle the tilde notation (~user) of git url"

stable-0.9
Shawn Pearce 15 years ago committed by Code Review
parent
commit
19473b1dbc
  1. 47
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
  2. 3
      org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java

47
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java

@ -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();

3
org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java

@ -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()) {

Loading…
Cancel
Save