Merge "Fix clone with commit-msg hook when project name contains '/'"

This commit is contained in:
David Pursehouse
2015-06-23 08:50:59 +00:00
committed by Gerrit Code Review
4 changed files with 19 additions and 4 deletions

View File

@@ -1120,7 +1120,10 @@ authentication.
|`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.

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) {

View File

@@ -208,8 +208,10 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
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);
}
}