From 9b1deadcb432cfd0f463c79549b5991fec8c67d6 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 2 Jul 2015 14:15:22 +0200 Subject: URIish: fall back to host as humanish name When we have a URI that contains an empty path component (that is it only contains a "/") we want to fall back to the host as humanish name. This change is according to the behavior of upstream git, which falls back on the hostname when guessing directory names for newly cloned repositories (see [1] for the discussion). [1] http://article.gmane.org/gmane.comp.version-control.git/274669 Change-Id: I44400c6ab72a2722d2155d53d63671bd867d6c44 Signed-off-by: Patrick Steinhardt --- .../tst/org/eclipse/jgit/transport/URIishTest.java | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'org.eclipse.jgit.test') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java index 8c7c992b70..745c322013 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java @@ -3,6 +3,7 @@ * Copyright (C) 2008, Robin Rosenberg * Copyright (C) 2008, Shawn O. Pearce * Copyright (C) 2013, Robin Stocker + * Copyright (C) 2015, Patrick Steinhardt * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -378,6 +379,56 @@ public class URIishTest { assertEquals(u, new URIish(str)); } + @Test + public void testSshProtoHostOnly() throws Exception { + final String str = "ssh://example.com/"; + URIish u = new URIish(str); + assertEquals("ssh", u.getScheme()); + assertTrue(u.isRemote()); + assertEquals("/", u.getRawPath()); + assertEquals("/", u.getPath()); + assertEquals("example.com", u.getHost()); + assertEquals(-1, u.getPort()); + assertEquals("ssh://example.com/", u.toString()); + assertEquals("ssh://example.com/", u.toASCIIString()); + assertEquals("example.com", u.getHumanishName()); + assertEquals(u, new URIish(str)); + } + + @Test + public void testSshProtoHostWithAuthentication() throws Exception { + final String str = "ssh://user:secret@pass@example.com/"; + URIish u = new URIish(str); + assertEquals("ssh", u.getScheme()); + assertTrue(u.isRemote()); + assertEquals("/", u.getRawPath()); + assertEquals("/", u.getPath()); + assertEquals("example.com", u.getHost()); + assertEquals(-1, u.getPort()); + assertEquals("ssh://user@example.com/", u.toString()); + assertEquals("ssh://user@example.com/", u.toASCIIString()); + assertEquals("example.com", u.getHumanishName()); + assertEquals("user", u.getUser()); + assertEquals("secret@pass", u.getPass()); + assertEquals(u, new URIish(str)); + } + + @Test + public void testSshProtoHostWithPort() throws Exception { + final String str = "ssh://example.com:2222/"; + URIish u = new URIish(str); + assertEquals("ssh", u.getScheme()); + assertTrue(u.isRemote()); + assertEquals("/", u.getRawPath()); + assertEquals("/", u.getPath()); + assertEquals("example.com", u.getHost()); + assertEquals(2222, u.getPort()); + assertEquals("ssh://example.com:2222/", u.toString()); + assertEquals("ssh://example.com:2222/", u.toASCIIString()); + assertEquals("example.com", u.getHumanishName()); + assertEquals(u, new URIish(str)); + } + @Test public void testSshProtoWithUserAndPort() throws Exception { final String str = "ssh://user@example.com:33/some/p ath"; @@ -622,6 +673,13 @@ public class URIishTest { assertEquals("abc", humanishName); } + @Test + public void testGetEmptyHumanishNameWithAuthorityOnly() throws IllegalArgumentException, + URISyntaxException { + String humanishName = new URIish(GIT_SCHEME + "abc").getHumanishName(); + assertEquals("abc", humanishName); + } + @Test public void testGetValidSlashHumanishName() throws IllegalArgumentException, URISyntaxException { -- cgit v1.2.3