Clean up formatting suggesting to install commit-msg hook
The message line wrapped badly on 80 column wide ttys. Use a shorter
hint text to make the message fit on an 80 column wide terminal
without wrapping.
Add a blank line before the hint so the hint is more easily noticed
from the suggested commit message when a Change-Id is missing.
Make the curl command a single line with ; in between the two
commands, making copy and paste into a shell easier.
Don't use $ before a command name, instead start the command with
two spaces so it offsets from the left margin slightly more than
other text.
Change appends from "\n" to '\n'. Its only a single character.
Change-Id: I8b3d1cc0e45717c5df8dd74204179f2cd4d4427f
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveCommits.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveCommits.java
index 56b24cb..23593e5 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveCommits.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveCommits.java
@@ -2127,8 +2127,10 @@
// If there are no SSH keys, the commit-msg hook must be installed via HTTP(S)
if (hostKeys.isEmpty()) {
- return "$ curl -o .git/hooks/commit-msg " + getGerritUrl() + "/tools/hooks/commit-msg\n"
- + "$ chmod +x .git/hooks/commit-msg";
+ String p = ".git/hooks/commit-msg";
+ return String.format(
+ " curl -o %s %s/tools/hooks/commit-msg ; chmod +x %s",
+ p, getGerritUrl(), p);
}
// SSH keys exist, so the hook can be installed with scp.
@@ -2148,7 +2150,9 @@
sshPort = 22;
}
- return "$ scp -p -P " + sshPort + " " + currentUser.getUserName() + "@" + sshHost + ":hooks/commit-msg .git/hooks/";
+ return String.format(
+ " scp -p -P %d %s@%s:hooks/commit-msg .git/hooks/",
+ sshPort, currentUser.getUserName(), sshHost);
}
private String getFixedCommitMsgWithChangeId(String errMsg, RevCommit c) {
@@ -2159,12 +2163,12 @@
final String changeId = "Change-Id:";
StringBuilder sb = new StringBuilder();
sb.append("ERROR: ").append(errMsg);
- sb.append("\n");
+ sb.append('\n');
sb.append("Suggestion for commit message:\n");
if (c.getFullMessage().indexOf(changeId)==-1) {
sb.append(c.getFullMessage());
- sb.append("\n");
+ sb.append('\n');
sb.append(changeId).append(" I").append(c.name());
} else {
String lines[] = c.getFullMessage().trim().split("\n");
@@ -2173,21 +2177,24 @@
if (lastLine.indexOf(changeId)==0) {
for (int i = 0; i < lines.length - 1; i++) {
sb.append(lines[i]);
- sb.append("\n");
+ sb.append('\n');
}
- sb.append("\n");
+ sb.append('\n');
sb.append(lastLine);
} else {
sb.append(c.getFullMessage());
- sb.append("\n");
+ sb.append('\n');
sb.append(changeId).append(" I").append(c.name());
- sb.append("\nHint: A potential Change-Id was found, but it was not in the footer of the commit message.");
+ sb.append('\n');
+ sb.append("Hint: A potential Change-Id was found, but it was not in the footer of the commit message.");
}
}
- sb.append("\n");
- sb.append("Hint: To automatically add a Change-Id to commit messages, install the commit-msg hook:\n");
- sb.append(getCommitMessageHookInstallationHint());
+ sb.append('\n');
+ sb.append('\n');
+ sb.append("Hint: To automatically insert Change-Id, install the hook:\n");
+ sb.append(getCommitMessageHookInstallationHint()).append('\n');
+ sb.append('\n');
return sb.toString();
}