Only chmod if commit-msg hook was fetched successfully
There is no reason to attempt to chmod the commit-msg hook if it
failed to download, so use '&&' instead of ';'.
Some shells, and some shell extensions in particular (f.i. zsh and
oh-my-zsh), have url magic features that automatically attempt to
escape characters in conjunction with urls.
This can cause the current implementation to fail as it would escape
the ';' because it was connected to the curl command argument.
This in turn causes the curl command to fail as it would interpret
the chmod command as another argument to curl.
This resolves both issues by chaining the command instead.
Change-Id: I4304abbb11b7be63686bec51b200874fa00eab81
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 76d4166..431c8b9 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
@@ -77,7 +77,7 @@
.append(HOOK)
.append(" ")
.append(getHookUrl())
- .append("; chmod +x ")
+ .append(" && chmod +x ")
.append(HOOKS_DIR)
.append(HOOK)
.append(")");
diff --git a/src/test/java/com/googlesource/gerrit/plugins/download/command/CloneWithCommitMsgHookTest.java b/src/test/java/com/googlesource/gerrit/plugins/download/command/CloneWithCommitMsgHookTest.java
index d4ca37c..24b521e 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/download/command/CloneWithCommitMsgHookTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/download/command/CloneWithCommitMsgHookTest.java
@@ -117,7 +117,7 @@
private String getDefaultHookCommand() {
return String.format(
- "(cd %s && mkdir -p %s && curl -Lo %scommit-msg https://%s/tools/hooks/commit-msg; chmod +x %scommit-msg)",
+ "(cd %s && mkdir -p %s && curl -Lo %scommit-msg https://%s/tools/hooks/commit-msg && chmod +x %scommit-msg)",
baseName(ENV.projectName), HOOKS_DIR, HOOKS_DIR, ENV.fqdn, HOOKS_DIR);
}