Implement MatchAuthorToCommitterDate for applicable strategies
Bug: https://crbug.com/732968 Change-Id: I0408d3c871d9120855c180d849cafc791f872b23
This commit is contained in:
@@ -42,6 +42,7 @@ import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.extensions.api.changes.SubmitInput;
|
||||
import com.google.gerrit.extensions.api.projects.BranchInput;
|
||||
import com.google.gerrit.extensions.api.projects.ConfigInput;
|
||||
import com.google.gerrit.extensions.api.projects.ProjectInput;
|
||||
import com.google.gerrit.extensions.client.ChangeStatus;
|
||||
import com.google.gerrit.extensions.client.InheritableBoolean;
|
||||
@@ -989,6 +990,31 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
||||
assertThat(input.generateLockFailures).containsExactly(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void authorAndCommitDateAreEqual() throws Exception {
|
||||
assume().that(getSubmitType()).isNotEqualTo(SubmitType.FAST_FORWARD_ONLY);
|
||||
|
||||
ConfigInput ci = new ConfigInput();
|
||||
ci.matchAuthorToCommitterDate = InheritableBoolean.TRUE;
|
||||
gApi.projects().name(project.get()).config(ci);
|
||||
|
||||
RevCommit initialHead = getRemoteHead();
|
||||
testRepo.reset(initialHead);
|
||||
PushOneCommit.Result change = createChange("Change 1", "b", "b");
|
||||
|
||||
testRepo.reset(initialHead);
|
||||
PushOneCommit.Result change2 = createChange("Change 2", "c", "c");
|
||||
|
||||
if (getSubmitType() == SubmitType.MERGE_IF_NECESSARY
|
||||
|| getSubmitType() == SubmitType.REBASE_IF_NECESSARY) {
|
||||
// Merge another change so that change2 is not a fast-forward
|
||||
submit(change.getChangeId());
|
||||
}
|
||||
|
||||
submit(change2.getChangeId());
|
||||
assertAuthorAndCommitDateEquals(getRemoteHead());
|
||||
}
|
||||
|
||||
private void setChangeStatusToNew(PushOneCommit.Result... changes) throws Exception {
|
||||
for (PushOneCommit.Result change : changes) {
|
||||
try (BatchUpdate bu =
|
||||
@@ -1142,6 +1168,12 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
||||
assertThat(actual.getTimeZone()).isEqualTo(expected.getTimeZone());
|
||||
}
|
||||
|
||||
protected void assertAuthorAndCommitDateEquals(RevCommit commit) {
|
||||
assertThat(commit.getAuthorIdent().getWhen()).isEqualTo(commit.getCommitterIdent().getWhen());
|
||||
assertThat(commit.getAuthorIdent().getTimeZone())
|
||||
.isEqualTo(commit.getCommitterIdent().getTimeZone());
|
||||
}
|
||||
|
||||
protected void assertSubmitter(String changeId, int psId) throws Exception {
|
||||
assertSubmitter(changeId, psId, admin);
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ public class RebaseChangeOp implements BatchUpdateOp {
|
||||
private boolean copyApprovals = true;
|
||||
private boolean detailedCommitMessage;
|
||||
private boolean postMessage = true;
|
||||
private boolean matchAuthorToCommitterDate = false;
|
||||
|
||||
private RevCommit rebasedCommit;
|
||||
private PatchSet.Id rebasedPatchSetId;
|
||||
@@ -131,6 +132,11 @@ public class RebaseChangeOp implements BatchUpdateOp {
|
||||
return this;
|
||||
}
|
||||
|
||||
public RebaseChangeOp setMatchAuthorToCommitterDate(boolean matchAuthorToCommitterDate) {
|
||||
this.matchAuthorToCommitterDate = matchAuthorToCommitterDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRepo(RepoContext ctx)
|
||||
throws MergeConflictException, InvalidChangeOperationException, RestApiException, IOException,
|
||||
@@ -263,6 +269,11 @@ public class RebaseChangeOp implements BatchUpdateOp {
|
||||
} else {
|
||||
cb.setCommitter(ctx.getIdentifiedUser().newCommitterIdent(ctx.getWhen(), ctx.getTimeZone()));
|
||||
}
|
||||
if (matchAuthorToCommitterDate) {
|
||||
cb.setAuthor(
|
||||
new PersonIdent(
|
||||
cb.getAuthor(), cb.getCommitter().getWhen(), cb.getCommitter().getTimeZone()));
|
||||
}
|
||||
ObjectId objectId = ctx.getInserter().insert(cb);
|
||||
ctx.getInserter().flush();
|
||||
return ctx.getRevWalk().parseCommit(objectId);
|
||||
|
||||
@@ -248,6 +248,7 @@ public class MergeUtil {
|
||||
mergeCommit.setAuthor(originalCommit.getAuthorIdent());
|
||||
mergeCommit.setCommitter(cherryPickCommitterIdent);
|
||||
mergeCommit.setMessage(commitMsg);
|
||||
matchAuthorToCommitterDate(project, mergeCommit);
|
||||
return rw.parseCommit(inserter.insert(mergeCommit));
|
||||
}
|
||||
throw new MergeConflictException("merge conflict");
|
||||
@@ -857,4 +858,14 @@ public class MergeUtil {
|
||||
throw new ResourceNotFoundException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void matchAuthorToCommitterDate(ProjectState project, CommitBuilder commit) {
|
||||
if (project.isMatchAuthorToCommitterDate()) {
|
||||
commit.setAuthor(
|
||||
new PersonIdent(
|
||||
commit.getAuthor(),
|
||||
commit.getCommitter().getWhen(),
|
||||
commit.getCommitter().getTimeZone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@ class MergeOneOp extends SubmitStrategyOp {
|
||||
@Override
|
||||
public void updateRepoImpl(RepoContext ctx) throws IntegrationException, IOException {
|
||||
PersonIdent caller =
|
||||
ctx.getIdentifiedUser().newCommitterIdent(ctx.getWhen(), ctx.getTimeZone());
|
||||
ctx.getIdentifiedUser()
|
||||
.newCommitterIdent(args.serverIdent.getWhen(), args.serverIdent.getTimeZone());
|
||||
if (args.mergeTip.getCurrentTip() == null) {
|
||||
throw new IllegalStateException(
|
||||
"cannot merge commit "
|
||||
|
||||
@@ -179,7 +179,8 @@ public class RebaseSubmitStrategy extends SubmitStrategy {
|
||||
.setDetailedCommitMessage(rebaseAlways)
|
||||
// Do not post message after inserting new patchset because there
|
||||
// will be one about change being merged already.
|
||||
.setPostMessage(false);
|
||||
.setPostMessage(false)
|
||||
.setMatchAuthorToCommitterDate(args.project.isMatchAuthorToCommitterDate());
|
||||
try {
|
||||
rebaseOp.updateRepo(ctx);
|
||||
} catch (MergeConflictException | NoSuchChangeException e) {
|
||||
|
||||
Reference in New Issue
Block a user