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.
Change-Id: I2838a810682054dc1a585630480db8110bf71abc
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/CloneWithCommitMsgHook.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/CloneWithCommitMsgHook.java
index 50a11c6..dfb95e6 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/command/CloneWithCommitMsgHook.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/CloneWithCommitMsgHook.java
@@ -48,8 +48,17 @@
.append("@")
.append(sshScheme.getSshdHost())
.append(":hooks/commit-msg ")
- .append(project)
+ .append(getBaseName(project))
.append("/.git/hooks/")
.toString();
}
+
+ private String getBaseName(String project) {
+ int i = project.lastIndexOf('/');
+ if (i < 0) {
+ return project;
+ } else {
+ return project.substring(i + 1);
+ }
+ }
}