Allow full URLs as repository names in GerritRemoteReader.
Change-Id: I4f5afdeead3d24beefdbf3969bd4d744df94973f
diff --git a/src/main/java/com/googlesource/gerrit/plugins/supermanifest/SuperManifestRefUpdatedListener.java b/src/main/java/com/googlesource/gerrit/plugins/supermanifest/SuperManifestRefUpdatedListener.java
index 447252a..bb8fde4 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/supermanifest/SuperManifestRefUpdatedListener.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/supermanifest/SuperManifestRefUpdatedListener.java
@@ -16,6 +16,7 @@
import static com.google.gerrit.reviewdb.client.RefNames.REFS_HEADS;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.events.GitReferenceUpdatedListener;
@@ -467,6 +468,8 @@
return repos.get(name);
}
+ name = urlToRepoKey(canonicalWebUrl, name);
+
Repository repo = repoManager.openRepository(new Project.NameKey(name));
repos.put(name, repo);
return repo;
@@ -480,4 +483,18 @@
repos.clear();
}
}
+
+ @VisibleForTesting
+ static String urlToRepoKey(URI baseUrl, String name) {
+ if (name.startsWith(baseUrl.toString())) {
+ // It would be nice to parse the URL and do relativize on the Path, but
+ // I am lazy, and nio.Path considers the file system and symlinks.
+ name = name.substring(baseUrl.toString().length());
+ while (name.startsWith("/")) {
+ name = name.substring(1);
+ }
+ }
+ return name;
+ }
+
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/supermanifest/SuperManifestIT.java b/src/test/java/com/googlesource/gerrit/plugins/supermanifest/SuperManifestIT.java
index 9a6cbe3..4618996 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/supermanifest/SuperManifestIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/supermanifest/SuperManifestIT.java
@@ -358,5 +358,18 @@
assertThat(subUrl).doesNotContain("../");
}
+ @Test
+ public void testToRepoKey() {
+ URI base = URI.create("https://gerrit-review.googlesource.com");
+ assertThat(
+ SuperManifestRefUpdatedListener.urlToRepoKey(base,
+ "https://gerrit-review.googlesource.com/repo")).isEqualTo("repo");
+ assertThat(SuperManifestRefUpdatedListener.urlToRepoKey(base, "repo")).isEqualTo("repo");
+ assertThat(
+ SuperManifestRefUpdatedListener.urlToRepoKey(
+ URI.create("https://gerrit-review.googlesource.com/"),
+ "https://gerrit-review.googlesource.com/repo")).isEqualTo("repo");
+ }
+
// TODO - should add tests for all the error handling in configuration parsing?
}