changeset 680:03a544f9eae1 Gaya-8.0.x

TW-33700 fix relative ssh urls resolution
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Fri, 29 Nov 2013 15:24:36 +0400
parents 5abe150c9187
children feb909e10f22 98887e2c7582
files mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubRepo.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubRepoTest.java
diffstat 2 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubRepo.java	Sat Oct 12 19:28:29 2013 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubRepo.java	Fri Nov 29 15:24:36 2013 +0400
@@ -53,6 +53,8 @@
     try {
       URI parentURI = new URI(parentRepoUrl);
       URI subrepoAbsUrl = parentURI.resolve(url());
+      if (isSsh(subrepoAbsUrl) && isPathFromRoot(parentURI))
+        return getUrlWithPathFromRoot(subrepoAbsUrl);
       return subrepoAbsUrl.toString();
     } catch (URISyntaxException e) {
       return parentRepoUrl + url();
@@ -61,6 +63,25 @@
     }
   }
 
+  private boolean isSsh(@NotNull URI uri) {
+    return "ssh".equals(uri.getScheme());
+  }
+
+  private boolean isPathFromRoot(@NotNull URI uri) {
+    return uri.getPath() != null && uri.getPath().startsWith("//");
+  }
+
+  @NotNull
+  private String getUrlWithPathFromRoot(@NotNull URI uri) throws URISyntaxException {
+    return new URI(uri.getScheme(),
+            uri.getUserInfo(),
+            uri.getHost(),
+            uri.getPort(),
+            "/" + uri.getPath(),
+            uri.getQuery(),
+            uri.getFragment()).toString();
+  }
+
   @Override
   public String toString() {
     return myPath + " = " + myUrl + "#" + myRevision;
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubRepoTest.java	Sat Oct 12 19:28:29 2013 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubRepoTest.java	Fri Nov 29 15:24:36 2013 +0400
@@ -9,12 +9,15 @@
 public class SubRepoTest {
 
   public void url_resolution() throws Exception {
+    //http://www.selenic.com/mercurial/hg.1.html#urls
     assertEquals("http://acme.org/subrepo", subrepoWithUrl("../subrepo").resolveUrl("http://acme.org/mainrepo"));
     assertEquals("http://acme.org/mainrepo/subrepo", subrepoWithUrl("./subrepo").resolveUrl("http://acme.org/mainrepo"));
     assertEquals("http://acme.org/mainrepo/subrepo", subrepoWithUrl("subrepo").resolveUrl("http://acme.org/mainrepo"));
     assertEquals("http://some.org/subrepo", subrepoWithUrl("http://some.org/subrepo").resolveUrl("http://acme.org/mainrepo"));
     assertEquals("c:/subrepo", subrepoWithUrl("c:/subrepo").resolveUrl("http://acme.org/mainrepo"));
     assertEquals("c:\\subrepo", subrepoWithUrl("c:\\subrepo").resolveUrl("http://acme.org/mainrepo"));
+    assertEquals("ssh://acme.org//subrepo", subrepoWithUrl("../subrepo").resolveUrl("ssh://acme.org//mainrepo"));
+    assertEquals("ssh://acme.org/subrepo", subrepoWithUrl("../subrepo").resolveUrl("ssh://acme.org/mainrepo"));
   }
 
   private SubRepo subrepoWithUrl(@NotNull String subrepoUrl) {