Search in sources :

Example 21 with BackfillResult

use of com.google.gerrit.server.notedb.CommitRewriter.BackfillResult in project gerrit by GerritCodeReview.

the class CommitRewriterTest method fixAssigneeChangeMessageNoAssigneeFooter.

@Test
public void fixAssigneeChangeMessageNoAssigneeFooter() throws Exception {
    Change c = newChange();
    writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, "Assignee added: " + changeOwner.getName()), getAuthorIdent(changeOwner.getAccount()));
    writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, String.format("Assignee changed from: %s to: %s", changeOwner.getNameEmail(), otherUser.getNameEmail())), getAuthorIdent(otherUser.getAccount()));
    writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, "Assignee deleted: " + otherUser.getName()), getAuthorIdent(changeOwner.getAccount()));
    Account reviewer = Account.builder(Account.id(3), TimeUtil.now()).setFullName("Reviewer User").setPreferredEmail("reviewer@account.com").build();
    accountCache.put(reviewer);
    // Even though account is present in the cache, it won't be used because it does not appear in
    // the history of this change.
    writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, "Assignee added: " + reviewer.getName()), getAuthorIdent(changeOwner.getAccount()));
    writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, "Assignee deleted: Gerrit Account"), getAuthorIdent(changeOwner.getAccount()));
    RunOptions options = new RunOptions();
    options.dryRun = false;
    BackfillResult result = rewriter.backfillProject(project, repo, options);
    assertThat(result.fixedRefDiff.keySet()).containsExactly(RefNames.changeMetaRef(c.getId()));
    List<String> commitHistoryDiff = commitHistoryDiff(result, c.getId());
    assertThat(commitHistoryDiff).containsExactly("@@ -6 +6 @@\n" + "-Assignee added: Change Owner\n" + "+Assignee added: <GERRIT_ACCOUNT_1>\n", "@@ -6 +6 @@\n" + "-Assignee changed from: Change Owner <change@owner.com> to: Other Account <other@account.com>\n" + "+Assignee changed from: <GERRIT_ACCOUNT_1> to: <GERRIT_ACCOUNT_2>\n", "@@ -6 +6 @@\n" + "-Assignee deleted: Other Account\n" + "+Assignee deleted: <GERRIT_ACCOUNT_2>\n", "@@ -6 +6 @@\n" + "-Assignee added: Reviewer User\n" + "+Assignee was added.\n");
    BackfillResult secondRunResult = rewriter.backfillProject(project, repo, options);
    assertThat(secondRunResult.fixedRefDiff.keySet()).isEmpty();
    assertThat(secondRunResult.refsFailedToFix).isEmpty();
}
Also used : Account(com.google.gerrit.entities.Account) BackfillResult(com.google.gerrit.server.notedb.CommitRewriter.BackfillResult) Change(com.google.gerrit.entities.Change) RunOptions(com.google.gerrit.server.notedb.CommitRewriter.RunOptions) Test(org.junit.Test)

Example 22 with BackfillResult

use of com.google.gerrit.server.notedb.CommitRewriter.BackfillResult in project gerrit by GerritCodeReview.

the class CommitRewriterTest method fixRemoveVoteChangeMessageWithUnparsableAuthorIdent.

// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Test
public void fixRemoveVoteChangeMessageWithUnparsableAuthorIdent() throws Exception {
    Change c = newChange();
    PersonIdent invalidAuthorIdent = new PersonIdent(changeOwner.getName(), "server@" + serverId, Date.from(TimeUtil.now()), serverIdent.getTimeZone());
    writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
    "Removed Verified+2 by " + otherUser.getNameEmail(), "Label: -Verified"), invalidAuthorIdent);
    RunOptions options = new RunOptions();
    options.dryRun = false;
    BackfillResult result = rewriter.backfillProject(project, repo, options);
    assertThat(result.fixedRefDiff.keySet()).containsExactly(RefNames.changeMetaRef(c.getId()));
    List<String> commitHistoryDiff = commitHistoryDiff(result, c.getId());
    // Other Account does not applier in any change updates, replaced with default
    assertThat(commitHistoryDiff).containsExactly("@@ -6 +6 @@\n" + "-Removed Verified+2 by Other Account <other@account.com>\n" + "+Removed Verified+2\n");
    BackfillResult secondRunResult = rewriter.backfillProject(project, repo, options);
    assertThat(secondRunResult.fixedRefDiff.keySet()).isEmpty();
    assertThat(secondRunResult.refsFailedToFix).isEmpty();
}
Also used : BackfillResult(com.google.gerrit.server.notedb.CommitRewriter.BackfillResult) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Change(com.google.gerrit.entities.Change) RunOptions(com.google.gerrit.server.notedb.CommitRewriter.RunOptions) Test(org.junit.Test)

Example 23 with BackfillResult

use of com.google.gerrit.server.notedb.CommitRewriter.BackfillResult in project gerrit by GerritCodeReview.

the class CommitRewriterTest method fixAttentionFooter.

// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Test
public void fixAttentionFooter() throws Exception {
    Change c = newChange();
    ImmutableList.Builder<ObjectId> commitsToFix = new ImmutableList.Builder<>();
    // Only 'reason' fix is required
    ChangeUpdate invalidAttentionSetUpdate = newUpdate(c, changeOwner);
    invalidAttentionSetUpdate.putReviewer(otherUserId, REVIEWER);
    invalidAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(otherUserId, Operation.ADD, String.format("Added by %s using the hovercard menu", otherUser.getName())));
    commitsToFix.add(invalidAttentionSetUpdate.commit());
    ChangeUpdate invalidMultipleAttentionSetUpdate = newUpdate(c, changeOwner);
    invalidMultipleAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(changeOwner.getAccountId(), Operation.ADD, String.format("%s replied on the change", otherUser.getName())));
    invalidMultipleAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(otherUserId, Operation.REMOVE, String.format("Removed by %s using the hovercard menu", otherUser.getName())));
    commitsToFix.add(invalidMultipleAttentionSetUpdate.commit());
    String otherUserIdentToFix = getAccountIdentToFix(otherUser.getAccount());
    String changeOwnerIdentToFix = getAccountIdentToFix(changeOwner.getAccount());
    commitsToFix.add(writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, /*changeMessage=*/
    null, // Only 'person_ident' fix is required
    "Attention: " + gson.toJson(new AttentionStatusInNoteDb(otherUserIdentToFix, Operation.ADD, "Added by someone using the hovercard menu")), // Both 'reason' and 'person_ident' fix is required
    "Attention: " + gson.toJson(new AttentionStatusInNoteDb(changeOwnerIdentToFix, Operation.REMOVE, String.format("%s replied on the change", otherUser.getName())))), getAuthorIdent(changeOwner.getAccount())));
    ChangeUpdate validAttentionSetUpdate = newUpdate(c, changeOwner);
    validAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(otherUserId, Operation.REMOVE, "Removed by someone"));
    validAttentionSetUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(changeOwner.getAccountId(), Operation.ADD, "Added by someone"));
    validAttentionSetUpdate.commit();
    ChangeUpdate invalidRemovedByClickUpdate = newUpdate(c, changeOwner);
    invalidRemovedByClickUpdate.addToPlannedAttentionSetUpdates(AttentionSetUpdate.createForWrite(changeOwner.getAccountId(), Operation.REMOVE, String.format("Removed by %s by clicking the attention icon", otherUser.getName())));
    commitsToFix.add(invalidRemovedByClickUpdate.commit());
    Ref metaRefBeforeRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
    ImmutableList<RevCommit> commitsBeforeRewrite = logMetaRef(repo, metaRefBeforeRewrite);
    ImmutableList<Integer> invalidCommits = commitsToFix.build().stream().map(commit -> commitsBeforeRewrite.indexOf(commit)).collect(toImmutableList());
    ChangeNotes notesBeforeRewrite = newNotes(c);
    RunOptions options = new RunOptions();
    options.dryRun = false;
    BackfillResult result = rewriter.backfillProject(project, repo, options);
    assertThat(result.fixedRefDiff.keySet()).containsExactly(RefNames.changeMetaRef(c.getId()));
    notesBeforeRewrite.getAttentionSetUpdates();
    Instant updateTimestamp = serverIdent.getWhen().toInstant();
    ImmutableList<AttentionSetUpdate> attentionSetUpdatesBeforeRewrite = ImmutableList.of(AttentionSetUpdate.createFromRead(invalidRemovedByClickUpdate.getWhen(), changeOwner.getAccountId(), Operation.REMOVE, String.format("Removed by %s by clicking the attention icon", otherUser.getName())), AttentionSetUpdate.createFromRead(validAttentionSetUpdate.getWhen(), changeOwner.getAccountId(), Operation.ADD, "Added by someone"), AttentionSetUpdate.createFromRead(validAttentionSetUpdate.getWhen(), otherUserId, Operation.REMOVE, "Removed by someone"), AttentionSetUpdate.createFromRead(updateTimestamp, changeOwner.getAccountId(), Operation.REMOVE, String.format("%s replied on the change", otherUser.getName())), AttentionSetUpdate.createFromRead(updateTimestamp, otherUserId, Operation.ADD, "Added by someone using the hovercard menu"), AttentionSetUpdate.createFromRead(invalidMultipleAttentionSetUpdate.getWhen(), otherUserId, Operation.REMOVE, String.format("Removed by %s using the hovercard menu", otherUser.getName())), AttentionSetUpdate.createFromRead(invalidMultipleAttentionSetUpdate.getWhen(), changeOwner.getAccountId(), Operation.ADD, String.format("%s replied on the change", otherUser.getName())), AttentionSetUpdate.createFromRead(invalidAttentionSetUpdate.getWhen(), otherUserId, Operation.ADD, String.format("Added by %s using the hovercard menu", otherUser.getName())));
    ImmutableList<AttentionSetUpdate> attentionSetUpdatesAfterRewrite = ImmutableList.of(AttentionSetUpdate.createFromRead(invalidRemovedByClickUpdate.getWhen(), changeOwner.getAccountId(), Operation.REMOVE, "Removed by someone by clicking the attention icon"), AttentionSetUpdate.createFromRead(validAttentionSetUpdate.getWhen(), changeOwner.getAccountId(), Operation.ADD, "Added by someone"), AttentionSetUpdate.createFromRead(validAttentionSetUpdate.getWhen(), otherUserId, Operation.REMOVE, "Removed by someone"), AttentionSetUpdate.createFromRead(updateTimestamp, changeOwner.getAccountId(), Operation.REMOVE, "Someone replied on the change"), AttentionSetUpdate.createFromRead(updateTimestamp, otherUserId, Operation.ADD, "Added by someone using the hovercard menu"), AttentionSetUpdate.createFromRead(invalidMultipleAttentionSetUpdate.getWhen(), otherUserId, Operation.REMOVE, "Removed by someone using the hovercard menu"), AttentionSetUpdate.createFromRead(invalidMultipleAttentionSetUpdate.getWhen(), changeOwner.getAccountId(), Operation.ADD, "Someone replied on the change"), AttentionSetUpdate.createFromRead(invalidAttentionSetUpdate.getWhen(), otherUserId, Operation.ADD, "Added by someone using the hovercard menu"));
    ChangeNotes notesAfterRewrite = newNotes(c);
    assertThat(notesBeforeRewrite.getAttentionSetUpdates()).containsExactlyElementsIn(attentionSetUpdatesBeforeRewrite);
    assertThat(notesAfterRewrite.getAttentionSetUpdates()).containsExactlyElementsIn(attentionSetUpdatesAfterRewrite);
    Ref metaRefAfterRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
    assertThat(metaRefAfterRewrite.getObjectId()).isNotEqualTo(metaRefBeforeRewrite.getObjectId());
    ImmutableList<RevCommit> commitsAfterRewrite = logMetaRef(repo, metaRefAfterRewrite);
    assertValidCommits(commitsBeforeRewrite, commitsAfterRewrite, invalidCommits);
    assertFixedCommits(commitsToFix.build(), result, c.getId());
    List<String> commitHistoryDiff = commitHistoryDiff(result, c.getId());
    assertThat(commitHistoryDiff).hasSize(4);
    assertThat(commitHistoryDiff.get(0)).isEqualTo("@@ -8 +8 @@\n" + "-Attention: {\"person_ident\":\"Gerrit User 2 \\u003c2@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Added by Other Account using the hovercard menu\"}\n" + "+Attention: {\"person_ident\":\"Gerrit User 2 \\u003c2@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Added by someone using the hovercard menu\"}\n");
    assertThat(Arrays.asList(commitHistoryDiff.get(1).split("\n"))).containsExactly("@@ -7,2 +7,2 @@", "-Attention: {\"person_ident\":\"Gerrit User 1 \\u003c1@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Other Account replied on the change\"}", "-Attention: {\"person_ident\":\"Gerrit User 2 \\u003c2@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Removed by Other Account using the hovercard menu\"}", "+Attention: {\"person_ident\":\"Gerrit User 1 \\u003c1@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Someone replied on the change\"}", "+Attention: {\"person_ident\":\"Gerrit User 2 \\u003c2@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Removed by someone using the hovercard menu\"}");
    assertThat(Arrays.asList(commitHistoryDiff.get(2).split("\n"))).containsExactly("@@ -7,2 +7,2 @@", "-Attention: {\"person_ident\":\"Other Account \\u003c2@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Added by someone using the hovercard menu\"}", "-Attention: {\"person_ident\":\"Change Owner \\u003c1@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Other Account replied on the change\"}", "+Attention: {\"person_ident\":\"Gerrit User 2 \\u003c2@gerrit\\u003e\",\"operation\":\"ADD\",\"reason\":\"Added by someone using the hovercard menu\"}", "+Attention: {\"person_ident\":\"Gerrit User 1 \\u003c1@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Someone replied on the change\"}");
    assertThat(commitHistoryDiff.get(3)).isEqualTo("@@ -7 +7 @@\n" + "-Attention: {\"person_ident\":\"Gerrit User 1 \\u003c1@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Removed by Other Account by clicking the attention icon\"}\n" + "+Attention: {\"person_ident\":\"Gerrit User 1 \\u003c1@gerrit\\u003e\",\"operation\":\"REMOVE\",\"reason\":\"Removed by someone by clicking the attention icon\"}\n");
    BackfillResult secondRunResult = rewriter.backfillProject(project, repo, options);
    assertThat(secondRunResult.fixedRefDiff.keySet()).isEmpty();
    assertThat(secondRunResult.refsFailedToFix).isEmpty();
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) Inject(com.google.inject.Inject) ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) CommitDiff(com.google.gerrit.server.notedb.CommitRewriter.CommitDiff) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) OutputFormat(com.google.gerrit.json.OutputFormat) Gson(com.google.gson.Gson) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) Map(java.util.Map) After(org.junit.After) RefNames(com.google.gerrit.entities.RefNames) RefUpdateUtil(com.google.gerrit.git.RefUpdateUtil) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Account(com.google.gerrit.entities.Account) Set(java.util.Set) RevSort(org.eclipse.jgit.revwalk.RevSort) ReviewerStatusUpdate(com.google.gerrit.server.ReviewerStatusUpdate) Instant(java.time.Instant) SubmitRecord(com.google.gerrit.entities.SubmitRecord) PersonIdent(org.eclipse.jgit.lib.PersonIdent) List(java.util.List) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate) VERIFIED(com.google.gerrit.entities.LabelId.VERIFIED) Ref(org.eclipse.jgit.lib.Ref) IntStream(java.util.stream.IntStream) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) CC(com.google.gerrit.server.notedb.ReviewerStateInternal.CC) HashSet(java.util.HashSet) ChangeMessage(com.google.gerrit.entities.ChangeMessage) ImmutableList(com.google.common.collect.ImmutableList) CODE_REVIEW(com.google.gerrit.entities.LabelId.CODE_REVIEW) Objects.requireNonNull(java.util.Objects.requireNonNull) Change(com.google.gerrit.entities.Change) REVIEWER(com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER) Before(org.junit.Before) Operation(com.google.gerrit.entities.AttentionSetUpdate.Operation) CurrentUser(com.google.gerrit.server.CurrentUser) AttentionStatusInNoteDb(com.google.gerrit.server.notedb.ChangeNoteUtil.AttentionStatusInNoteDb) BackfillResult(com.google.gerrit.server.notedb.CommitRewriter.BackfillResult) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) AccountTemplateUtil(com.google.gerrit.server.util.AccountTemplateUtil) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) REMOVED(com.google.gerrit.server.notedb.ReviewerStateInternal.REMOVED) RunOptions(com.google.gerrit.server.notedb.CommitRewriter.RunOptions) Repository(org.eclipse.jgit.lib.Repository) BackfillResult(com.google.gerrit.server.notedb.CommitRewriter.BackfillResult) ObjectId(org.eclipse.jgit.lib.ObjectId) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) Instant(java.time.Instant) Change(com.google.gerrit.entities.Change) Ref(org.eclipse.jgit.lib.Ref) AttentionStatusInNoteDb(com.google.gerrit.server.notedb.ChangeNoteUtil.AttentionStatusInNoteDb) RunOptions(com.google.gerrit.server.notedb.CommitRewriter.RunOptions) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 24 with BackfillResult

use of com.google.gerrit.server.notedb.CommitRewriter.BackfillResult in project gerrit by GerritCodeReview.

the class CommitRewriterTest method singleRunFixesAll.

// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Test
public void singleRunFixesAll() throws Exception {
    Change c = newChange();
    Instant when = TimeUtil.now();
    String assigneeIdentToFix = getAccountIdentToFix(otherUser.getAccount());
    PersonIdent authorIdentToFix = new PersonIdent(changeOwner.getName(), changeNoteUtil.getAccountIdAsEmailAddress(changeOwner.getAccountId()), Date.from(when), serverIdent.getTimeZone());
    RevCommit invalidUpdateCommit = writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, "Assignee added: Other Account <other@account.com>", "Assignee: " + assigneeIdentToFix), authorIdentToFix);
    Ref metaRefBeforeRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
    ImmutableList<RevCommit> commitsBeforeRewrite = logMetaRef(repo, metaRefBeforeRewrite);
    int invalidCommitIndex = commitsBeforeRewrite.indexOf(invalidUpdateCommit);
    ChangeNotes notesBeforeRewrite = newNotes(c);
    RunOptions options = new RunOptions();
    options.dryRun = false;
    BackfillResult result = rewriter.backfillProject(project, repo, options);
    assertThat(result.fixedRefDiff.keySet()).containsExactly(RefNames.changeMetaRef(c.getId()));
    ChangeNotes notesAfterRewrite = newNotes(c);
    assertThat(notesBeforeRewrite.getChange().getAssignee()).isEqualTo(otherUserId);
    assertThat(notesAfterRewrite.getChange().getAssignee()).isEqualTo(otherUserId);
    Ref metaRefAfterRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
    assertThat(metaRefAfterRewrite.getObjectId()).isNotEqualTo(metaRefBeforeRewrite.getObjectId());
    ImmutableList<RevCommit> commitsAfterRewrite = logMetaRef(repo, metaRefAfterRewrite);
    assertValidCommits(commitsBeforeRewrite, commitsAfterRewrite, ImmutableList.of(invalidCommitIndex));
    assertFixedCommits(ImmutableList.of(invalidUpdateCommit.getId()), result, c.getId());
    RevCommit fixedUpdateCommit = commitsAfterRewrite.get(invalidCommitIndex);
    assertThat(invalidUpdateCommit.getAuthorIdent()).isNotEqualTo(fixedUpdateCommit.getAuthorIdent());
    assertThat(invalidUpdateCommit.getFullMessage()).contains(otherUser.getName());
    assertThat(fixedUpdateCommit.getFullMessage()).doesNotContain(changeOwner.getName());
    assertThat(fixedUpdateCommit.getFullMessage()).doesNotContain(otherUser.getName());
    List<String> commitHistoryDiff = commitHistoryDiff(result, c.getId());
    assertThat(commitHistoryDiff).hasSize(1);
    assertThat(commitHistoryDiff.get(0)).contains("-author Change Owner <1@gerrit>");
    assertThat(commitHistoryDiff.get(0)).contains("+author Gerrit User 1 <1@gerrit>");
    assertThat(commitHistoryDiff.get(0)).contains("@@ -6 +6 @@\n" + "-Assignee added: Other Account <other@account.com>\n" + "+Assignee added: <GERRIT_ACCOUNT_2>\n" + "@@ -9 +9 @@\n" + "-Assignee: Other Account <2@gerrit>\n" + "+Assignee: Gerrit User 2 <2@gerrit>");
    BackfillResult secondRunResult = rewriter.backfillProject(project, repo, options);
    assertThat(secondRunResult.fixedRefDiff.keySet()).isEmpty();
    assertThat(secondRunResult.refsFailedToFix).isEmpty();
}
Also used : Ref(org.eclipse.jgit.lib.Ref) BackfillResult(com.google.gerrit.server.notedb.CommitRewriter.BackfillResult) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Instant(java.time.Instant) Change(com.google.gerrit.entities.Change) RunOptions(com.google.gerrit.server.notedb.CommitRewriter.RunOptions) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 25 with BackfillResult

use of com.google.gerrit.server.notedb.CommitRewriter.BackfillResult in project gerrit by GerritCodeReview.

the class CommitRewriterTest method failedVerification.

@Test
public void failedVerification() throws Exception {
    String tag = "jenkins";
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.setChangeMessage("Unknown commit " + changeOwner.getName());
    update.setTag(tag);
    update.commit();
    ChangeUpdate updateWithSubject = newUpdate(c, changeOwner);
    updateWithSubject.setSubjectForCommit("Update with subject");
    updateWithSubject.commit();
    ChangeNotes notesBeforeRewrite = newNotes(c);
    Ref metaRefBefore = repo.exactRef(RefNames.changeMetaRef(c.getId()));
    RunOptions options = new RunOptions();
    options.dryRun = false;
    BackfillResult backfillResult = rewriter.backfillProject(project, repo, options);
    assertThat(backfillResult.fixedRefDiff).isEmpty();
    assertThat(backfillResult.refsStillInvalidAfterFix).containsExactly(RefNames.changeMetaRef(c.getId()));
    ChangeNotes notesAfterRewrite = newNotes(c);
    Ref metaRefAfter = repo.exactRef(RefNames.changeMetaRef(c.getId()));
    assertThat(notesBeforeRewrite.getMetaId()).isEqualTo(notesAfterRewrite.getMetaId());
    assertThat(metaRefBefore.getObjectId()).isEqualTo(metaRefAfter.getObjectId());
}
Also used : Ref(org.eclipse.jgit.lib.Ref) BackfillResult(com.google.gerrit.server.notedb.CommitRewriter.BackfillResult) Change(com.google.gerrit.entities.Change) RunOptions(com.google.gerrit.server.notedb.CommitRewriter.RunOptions) Test(org.junit.Test)

Aggregations

Change (com.google.gerrit.entities.Change)30 BackfillResult (com.google.gerrit.server.notedb.CommitRewriter.BackfillResult)30 RunOptions (com.google.gerrit.server.notedb.CommitRewriter.RunOptions)30 Test (org.junit.Test)29 Ref (org.eclipse.jgit.lib.Ref)21 RevCommit (org.eclipse.jgit.revwalk.RevCommit)15 PersonIdent (org.eclipse.jgit.lib.PersonIdent)14 ObjectId (org.eclipse.jgit.lib.ObjectId)13 ImmutableMap (com.google.common.collect.ImmutableMap)12 Account (com.google.gerrit.entities.Account)12 Instant (java.time.Instant)12 ImmutableList (com.google.common.collect.ImmutableList)11 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)11 AttentionSetUpdate (com.google.gerrit.entities.AttentionSetUpdate)11 SubmitRecord (com.google.gerrit.entities.SubmitRecord)11 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)11 HashSet (java.util.HashSet)11 Map (java.util.Map)11 Truth.assertThat (com.google.common.truth.Truth.assertThat)10 Operation (com.google.gerrit.entities.AttentionSetUpdate.Operation)10