summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWendy Wang <wendy.wang10@sap.com>2022-03-11 12:45:06 +0100
committerWendy Wen Wang <wendy.wang10@sap.com>2022-03-16 12:56:50 +0000
commit49129230a142a876689a0a98c8a78dfba03d18c1 (patch)
tree5f5a1149cbef77dfc3c2c3142707041d233b42f4
parent8ea9fec379c61e7ee6cebabb18649d1f9e203fca (diff)
Show HTTP(S) message in Missing Change ID Error message
The assumption that the existence of the SSH host key means that all users use SSH protocol is incorrect, since some might use HTTP protocol. Since a CommitValidationListener doesn't know which protocol was used, provide both SSH and HTTP variant of the command to install the commit message hook. Release-Notes: skip Change-Id: I10ae721315de8afb964e720033e2d6498bce3e55
-rw-r--r--java/com/google/gerrit/server/git/validators/CommitValidators.java22
1 files changed, 15 insertions, 7 deletions
diff --git a/java/com/google/gerrit/server/git/validators/CommitValidators.java b/java/com/google/gerrit/server/git/validators/CommitValidators.java
index c67df8be90..f84b696d04 100644
--- a/java/com/google/gerrit/server/git/validators/CommitValidators.java
+++ b/java/com/google/gerrit/server/git/validators/CommitValidators.java
@@ -266,6 +266,12 @@ public class CommitValidators {
"multiple Change-Id lines in message footer";
private static final String INVALID_CHANGE_ID_MSG =
"invalid Change-Id line format in message footer";
+ private static final String HTTP_INSTALL_HOOK =
+ "f=\"$(git rev-parse --git-dir)/hooks/commit-msg\"; curl -o \"$f\""
+ + " %stools/hooks/commit-msg ; chmod +x \"$f\"";
+ private static final String SSH_INSTALL_HOOK =
+ "gitdir=$(git rev-parse --git-dir); scp -p -P %d %s@%s:hooks/commit-msg ${gitdir}/hooks/";
+ private static final String CHANGE_ID_MISSING_INSTALL_HOOKS = " %s\nor, for http(s):\n %s";
@VisibleForTesting
public static final String CHANGE_ID_MISMATCH_MSG =
@@ -372,14 +378,15 @@ public class CommitValidators {
// If there are no SSH keys, the commit-msg hook must be installed via
// HTTP(S)
Optional<String> webUrl = urlFormatter.getWebUrl();
+
+ String httpHook = String.format(HTTP_INSTALL_HOOK, webUrl.get());
+
if (hostKeys.isEmpty()) {
checkState(webUrl.isPresent());
- return String.format(
- " f=\"$(git rev-parse --git-dir)/hooks/commit-msg\"; curl -o \"$f\" %stools/hooks/commit-msg ; chmod +x \"$f\"",
- webUrl.get());
+ return httpHook;
}
- // SSH keys exist, so the hook can be installed with scp.
+ // SSH keys exist, so the hook might be able to be installed with scp.
String sshHost;
int sshPort;
String host = hostKeys.get(0).getHost();
@@ -397,9 +404,10 @@ public class CommitValidators {
sshPort = 22;
}
- return String.format(
- " gitdir=$(git rev-parse --git-dir); scp -p -P %d %s@%s:hooks/commit-msg ${gitdir}/hooks/",
- sshPort, user.getUserName().orElse("<USERNAME>"), sshHost);
+ String sshHook =
+ String.format(
+ SSH_INSTALL_HOOK, sshPort, user.getUserName().orElse("<USERNAME>"), sshHost);
+ return String.format(CHANGE_ID_MISSING_INSTALL_HOOKS, sshHook, httpHook);
}
}