Add Change-Id on cherry-picked commits
If a change is cherry-picked in the Web UI, it is possible for the user to edit the commit message and remove the Change-Id line. In this case, the cherry-pick change will be created without the Change-Id line. Since commits created by Gerrit have less strict validation, the commit will be accepted even if the project's configuration has the "require Change-Id" option enabled. When creating the cherry-pick commit, add the Change-Id, if not present in the commit message received from the UI. Bug: Issue 2130 Change-Id: I688bcd582d0bee9332a7f061e92a65341927e455
This commit is contained in:
@@ -129,13 +129,19 @@ public class CherryPickChange {
|
||||
currentUser.newCommitterIdent(myIdent.getWhen(),
|
||||
myIdent.getTimeZone());
|
||||
|
||||
final ObjectId computedChangeId =
|
||||
ChangeIdUtil
|
||||
.computeChangeId(commitToCherryPick.getTree(), mergeTip,
|
||||
commitToCherryPick.getAuthorIdent(), myIdent, message);
|
||||
String commitMessage = ChangeIdUtil.insertId(message, computedChangeId);
|
||||
|
||||
RevCommit cherryPickCommit;
|
||||
ObjectInserter oi = git.newObjectInserter();
|
||||
try {
|
||||
ProjectState projectState = refControl.getProjectControl().getProjectState();
|
||||
cherryPickCommit =
|
||||
mergeUtilFactory.create(projectState).createCherryPickFromCommit(git, oi, mergeTip,
|
||||
commitToCherryPick, committerIdent, message, revWalk);
|
||||
commitToCherryPick, committerIdent, commitMessage, revWalk);
|
||||
} finally {
|
||||
oi.release();
|
||||
}
|
||||
@@ -151,11 +157,6 @@ public class CherryPickChange {
|
||||
final String idStr = idList.get(idList.size() - 1).trim();
|
||||
changeKey = new Change.Key(idStr);
|
||||
} else {
|
||||
final ObjectId computedChangeId =
|
||||
ChangeIdUtil
|
||||
.computeChangeId(cherryPickCommit.getTree(), mergeTip,
|
||||
cherryPickCommit.getAuthorIdent(), myIdent, message);
|
||||
|
||||
changeKey = new Change.Key("I" + computedChangeId.name());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user