Fix clone with commit-msg hook when project name contains '/'
Cloning a project 'foo/bar' with
git clone ssh://<user>@<host>:29418/foo/bar
clones the project into a 'bar' folder.
This means that the commit-msg hook needs to be copied into
'bar/.git/hooks/', but so far the command tried to copy it into
'foo/bar/.git/hooks/' which failed since the folder didn't exist.
The clone commands that are returned from the GetServerInfo REST
endpoint may now contain 2 placeholders, '${project}' for the project
name and '${project-base-name}' for the project base name. E.g. for a
project 'foo/bar' '${project}' is a placeholder for 'foo/bar' and
'${project-base-name}' is a placeholder for 'bar'.
Bug: Issue 3444
Change-Id: Ia2dd9a70063498bdf21ecd66f2d25779515dd6d5
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/Documentation/rest-api-config.txt b/Documentation/rest-api-config.txt
index d8a6dba..88aec2e 100644
--- a/Documentation/rest-api-config.txt
+++ b/Documentation/rest-api-config.txt
@@ -1120,7 +1120,10 @@
|`clone_commands` ||
Clone commands as a map which maps the command name to the clone
command. In the clone command '${project}' is used as
-placeholder for the project name.
+placeholder for the project name and '${project-base-name}' as name
+for the project base name (e.g. for a project 'foo/bar' '${project}'
+is a placeholder for 'foo/bar' and '${project-base-name}' is a
+placeholder for 'bar').
Empty, if accessed anonymously and the download scheme requires
authentication.
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/config/DownloadInfo.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/config/DownloadInfo.java
index 187ad59..35234ce 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/config/DownloadInfo.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/config/DownloadInfo.java
@@ -63,6 +63,15 @@
return command(commandName).replaceAll("\\$\\{project\\}", project);
}
+ private String projectBaseName(String project) {
+ int i = project.lastIndexOf('/');
+ if (i < 0) {
+ return project;
+ } else {
+ return project.substring(i + 1);
+ }
+ }
+
public final Set<String> cloneCommandNames() {
return Natives.keys(_cloneCommands());
}
@@ -77,7 +86,8 @@
}
public final String cloneCommand(String commandName, String project) {
- return cloneCommand(commandName).replaceAll("\\$\\{project\\}", project);
+ return cloneCommand(commandName).replaceAll("\\$\\{project\\}", project)
+ .replaceAll("\\$\\{project-base-name\\}", projectBaseName(project));
}
public final String getUrl(String project) {
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/GetServerInfo.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/GetServerInfo.java
index cbcf6fc..673147f 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/config/GetServerInfo.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/GetServerInfo.java
@@ -208,8 +208,10 @@
for (DynamicMap.Entry<CloneCommand> e : cloneCommands) {
String commandName = e.getExportName();
CloneCommand command = e.getProvider().get();
- String c = command.getCommand(scheme, "${project}");
+ String c = command.getCommand(scheme, "${project-path}/${project-base-name}");
if (c != null) {
+ c = c.replaceAll("\\$\\{project-path\\}/\\$\\{project-base-name\\}",
+ "\\$\\{project\\}");
info.cloneCommands.put(commandName, c);
}
}
diff --git a/plugins/download-commands b/plugins/download-commands
index c0f1b84..741c713 160000
--- a/plugins/download-commands
+++ b/plugins/download-commands
@@ -1 +1 @@
-Subproject commit c0f1b84e494c8bab73f4786642dc768ae60468d9
+Subproject commit 741c71342080c33c5644b2ec13dc7287f4b41f4e