Add curl '-f' option to fail on download problems By default curl will exit with exit code '0' even if there was a problem with the transfer. Option '-f' will make curl to exit with error code '22' if HTTP response code was 400 or higher. If there was a problem with transfer, it does not make sense to process the next command - chmod. Option '-f' was introduced in curl in version 4.0, released in 1998, so is safe to be used. Change-Id: I74b1669b48d10a690a290dae2c24480f3a6994c6
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 a6ce048..0c6cdb2 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
@@ -72,7 +72,7 @@ .append(QuoteUtil.quote(projectName)) .append(" && mkdir -p ") .append(HOOKS_DIR) - .append(" && curl -Lo ") + .append(" && curl -fLo ") .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 67f63e2..9762ab7 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
@@ -167,7 +167,7 @@ private String getDefaultHookCommand() { return String.format( - "(cd %s && mkdir -p %s && curl -Lo %scommit-msg https://%s/tools/hooks/commit-msg && chmod" + "(cd %s && mkdir -p %s && curl -fLo %scommit-msg https://%s/tools/hooks/commit-msg && chmod" + " +x %scommit-msg)", baseName(ENV.projectName), HOOKS_DIR, HOOKS_DIR, ENV.fqdn, HOOKS_DIR); }