Search in sources :

Example 1 with FixInput

use of com.google.gerrit.extensions.api.changes.FixInput in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method createNewPatchSetForExpectedMergeCommitWithNoChangeId.

@Test
public void createNewPatchSetForExpectedMergeCommitWithNoChangeId() throws Exception {
    ChangeNotes notes = insertChange();
    String dest = notes.getChange().getDest().branch();
    RevCommit commit = serverSideTestRepo.getRevWalk().parseCommit(psUtil.current(notes).commitId());
    RevCommit mergedAs = serverSideTestRepo.commit().parent(commit.getParent(0)).message(commit.getShortMessage()).create();
    serverSideTestRepo.getRevWalk().parseBody(mergedAs);
    assertThat(mergedAs.getFooterLines(FooterConstants.CHANGE_ID)).isEmpty();
    serverSideTestRepo.update(dest, mergedAs);
    assertNoProblems(notes, null);
    FixInput fix = new FixInput();
    fix.expectMergedAs = mergedAs.name();
    assertProblems(notes, fix, problem("No patch set found for merged commit " + mergedAs.name(), FIXED, "Marked change as merged"), problem("Expected merged commit " + mergedAs.name() + " has no associated patch set", FIXED, "Inserted as patch set 2"));
    notes = reload(notes);
    PatchSet.Id psId2 = PatchSet.id(notes.getChangeId(), 2);
    assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId2);
    assertThat(psUtil.get(notes, psId2).commitId()).isEqualTo(mergedAs);
    assertNoProblems(notes, null);
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) TestChanges.newPatchSet(com.google.gerrit.testing.TestChanges.newPatchSet) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) FixInput(com.google.gerrit.extensions.api.changes.FixInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with FixInput

use of com.google.gerrit.extensions.api.changes.FixInput in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method expectedMergedCommitIsOldPatchSetOfSameChange.

@Test
public void expectedMergedCommitIsOldPatchSetOfSameChange() throws Exception {
    ChangeNotes notes = insertChange();
    ObjectId commitId1 = psUtil.current(notes).commitId();
    notes = incrementPatchSet(notes);
    PatchSet ps2 = psUtil.current(notes);
    serverSideTestRepo.branch(notes.getChange().getDest().branch()).update(serverSideTestRepo.getRevWalk().parseCommit(commitId1));
    FixInput fix = new FixInput();
    fix.expectMergedAs = commitId1.name();
    assertProblems(notes, fix, problem("No patch set found for merged commit " + commitId1.name(), FIXED, "Marked change as merged"), problem("Expected merge commit " + commitId1.name() + " corresponds to patch set 1," + " not the current patch set 2", FIXED, "Deleted patch set"), problem("Expected merge commit " + commitId1.name() + " corresponds to patch set 1," + " not the current patch set 2", FIXED, "Inserted as patch set 3"));
    notes = reload(notes);
    PatchSet.Id psId3 = PatchSet.id(notes.getChangeId(), 3);
    assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId3);
    assertThat(notes.getChange().isMerged()).isTrue();
    assertThat(psUtil.byChangeAsMap(notes).keySet()).containsExactly(ps2.id(), psId3);
    assertThat(psUtil.get(notes, psId3).commitId()).isEqualTo(commitId1);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.entities.PatchSet) TestChanges.newPatchSet(com.google.gerrit.testing.TestChanges.newPatchSet) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) FixInput(com.google.gerrit.extensions.api.changes.FixInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with FixInput

use of com.google.gerrit.extensions.api.changes.FixInput in project gerrit by GerritCodeReview.

the class ProjectsConsistencyChecker method changeJson.

private ChangeJson changeJson(Boolean fix, ObjectId mergedAs) {
    ChangeJson changeJson = changeJsonFactory.create(ListChangesOption.CHECK);
    if (fix != null && fix.booleanValue()) {
        FixInput fixInput = new FixInput();
        fixInput.expectMergedAs = mergedAs.name();
        changeJson.fix(fixInput);
    }
    return changeJson;
}
Also used : ChangeJson(com.google.gerrit.server.change.ChangeJson) FixInput(com.google.gerrit.extensions.api.changes.FixInput)

Example 4 with FixInput

use of com.google.gerrit.extensions.api.changes.FixInput in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method expectedMergedCommitWithMismatchedChangeId.

@Test
public void expectedMergedCommitWithMismatchedChangeId() throws Exception {
    ChangeNotes notes = insertChange();
    String dest = notes.getChange().getDest().branch();
    RevCommit parent = serverSideTestRepo.branch(dest).commit().message("parent").create();
    RevCommit commit = serverSideTestRepo.getRevWalk().parseCommit(psUtil.current(notes).commitId());
    serverSideTestRepo.branch(dest).update(commit);
    String badId = "I0000000000000000000000000000000000000000";
    RevCommit mergedAs = serverSideTestRepo.commit().parent(parent).message(commit.getShortMessage() + "\n\nChange-Id: " + badId + "\n").create();
    serverSideTestRepo.getRevWalk().parseBody(mergedAs);
    assertThat(mergedAs.getFooterLines(FooterConstants.CHANGE_ID)).containsExactly(badId);
    serverSideTestRepo.update(dest, mergedAs);
    assertNoProblems(notes, null);
    FixInput fix = new FixInput();
    fix.expectMergedAs = mergedAs.name();
    assertProblems(notes, fix, problem("Expected merged commit " + mergedAs.name() + " has Change-Id: " + badId + ", but expected " + notes.getChange().getKey().get()));
}
Also used : ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) FixInput(com.google.gerrit.extensions.api.changes.FixInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with FixInput

use of com.google.gerrit.extensions.api.changes.FixInput in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method expectedMergedCommitIsDanglingPatchSetNewerThanCurrent.

@Test
public void expectedMergedCommitIsDanglingPatchSetNewerThanCurrent() throws Exception {
    ChangeNotes notes = insertChange();
    PatchSet ps1 = psUtil.current(notes);
    // Create dangling ref with no patch set.
    PatchSet.Id psId2 = PatchSet.id(notes.getChangeId(), 2);
    RevCommit commit2 = patchSetCommit(psId2);
    serverSideTestRepo.branch(psId2.toRefName()).update(commit2);
    serverSideTestRepo.branch(notes.getChange().getDest().branch()).update(commit2);
    FixInput fix = new FixInput();
    fix.expectMergedAs = commit2.name();
    assertProblems(notes, fix, problem("No patch set found for merged commit " + commit2.name(), FIXED, "Marked change as merged"), problem("Expected merge commit " + commit2.name() + " corresponds to patch set 2," + " not the current patch set 1", FIXED, "Inserted as patch set 2"));
    notes = reload(notes);
    assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId2);
    assertThat(notes.getChange().isMerged()).isTrue();
    assertThat(psUtil.byChangeAsMap(notes).keySet()).containsExactly(ps1.id(), psId2);
    assertThat(psUtil.get(notes, psId2).commitId()).isEqualTo(commit2);
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) TestChanges.newPatchSet(com.google.gerrit.testing.TestChanges.newPatchSet) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) FixInput(com.google.gerrit.extensions.api.changes.FixInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

FixInput (com.google.gerrit.extensions.api.changes.FixInput)17 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)16 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)16 Test (org.junit.Test)16 PatchSet (com.google.gerrit.entities.PatchSet)10 TestChanges.newPatchSet (com.google.gerrit.testing.TestChanges.newPatchSet)10 RevCommit (org.eclipse.jgit.revwalk.RevCommit)7 ObjectId (org.eclipse.jgit.lib.ObjectId)5 Change (com.google.gerrit.entities.Change)1 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)1 ChangeJson (com.google.gerrit.server.change.ChangeJson)1