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>
This commit is contained in:
Edwin Kempin
2015-06-23 09:44:19 +02:00
parent e0227d76c9
commit 4bf36efa04
4 changed files with 19 additions and 4 deletions

View File

@@ -63,6 +63,15 @@ public class DownloadInfo extends JavaScriptObject {
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 class DownloadInfo extends JavaScriptObject {
}
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) {