Merge branch 'stable-2.15'

* stable-2.15:
  Add action_env flag to bazel.rc
  CreateChange: Strip comment lines out of input commit message

Change-Id: I20d84ce716cc2455a04c64729039250f7221f846
This commit is contained in:
David Pursehouse
2018-06-09 10:53:23 +09:00
5 changed files with 34 additions and 13 deletions

View File

@@ -171,7 +171,8 @@ public class CreateChange
throw new BadRequestException("branch must be non-empty");
}
if (Strings.isNullOrEmpty(input.subject)) {
String subject = clean(Strings.nullToEmpty(input.subject));
if (Strings.isNullOrEmpty(subject)) {
throw new BadRequestException("commit message must be non-empty");
}
@@ -264,7 +265,7 @@ public class CreateChange
GeneralPreferencesInfo info = accountState.getGeneralPreferences();
// Add a Change-Id line if there isn't already one
String commitMessage = input.subject;
String commitMessage = subject;
if (ChangeIdUtil.indexOfChangeId(commitMessage, "\n") == -1) {
ObjectId treeId = mergeTip == null ? emptyTreeId(oi) : mergeTip.getTree();
ObjectId id = ChangeIdUtil.computeChangeId(treeId, mergeTip, author, author, commitMessage);
@@ -388,4 +389,16 @@ public class CreateChange
private static ObjectId emptyTreeId(ObjectInserter inserter) throws IOException {
return inserter.insert(new TreeFormatter());
}
/**
* Remove comment lines from a commit message.
*
* <p>Based on {@link org.eclipse.jgit.util.ChangeIdUtil#clean}.
*
* @param msg
* @return message without comment lines, possibly empty.
*/
private String clean(String msg) {
return msg.replaceAll("(?m)^#.*$\n?", "").trim();
}
}