Print only one hint about Change-Ids at a time

Change-Id: Idd6b5f63c71000c660a0167510d47fdd55904e92
This commit is contained in:
Han-Wen Nienhuys
2018-07-05 17:00:04 +02:00
committed by David Pursehouse
parent c7a57dc797
commit c1656bd8d2

View File

@@ -335,25 +335,26 @@ public class CommitValidators {
StringBuilder sb = new StringBuilder();
sb.append("ERROR: ").append(errMsg);
boolean hinted = false;
if (c.getFullMessage().contains(CHANGE_ID_PREFIX)) {
String lastLine = Iterables.getLast(Splitter.on('\n').split(c.getFullMessage()), "");
if (!lastLine.contains(CHANGE_ID_PREFIX)) {
hinted = true;
sb.append("\n\n")
.append("Hint: run\n")
.append(" git commit --amend\n")
.append("and move 'Change-Id: Ixxx..' to the bottom on a separate line\n");
}
}
sb.append('\n');
sb.append('\n');
sb.append("Hint: To automatically insert ");
sb.append(FooterConstants.CHANGE_ID.getName());
sb.append(", install the hook:\n");
sb.append(getCommitMessageHookInstallationHint());
sb.append('\n');
sb.append("And then amend the commit:\n");
sb.append(" git commit --amend\n");
// Print only one hint to avoid overwhelming the user.
if (!hinted) {
sb.append("Hint: to automatically insert a Change-Id, install the hook:\n")
.append(getCommitMessageHookInstallationHint())
.append("\n")
.append("and then amend the commit:\n")
.append(" git commit --amend\n");
}
return new CommitValidationMessage(sb.toString(), false);
}