Search in sources :

Example 11 with FixInput

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

the class ConsistencyCheckerIT method patchSetObjectAndRefMissingWithFix.

@Test
public void patchSetObjectAndRefMissingWithFix() throws Exception {
    String rev = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
    ChangeNotes notes = insertChange();
    PatchSet ps = insertMissingPatchSet(notes, rev);
    notes = reload(notes);
    String refName = ps.id().toRefName();
    assertProblems(notes, new FixInput(), problem("Ref missing: " + refName), problem("Object missing: patch set 2: " + rev));
}
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) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with FixInput

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

the class ConsistencyCheckerIT method onlyPatchSetObjectMissingWithFix.

@Test
public void onlyPatchSetObjectMissingWithFix() throws Exception {
    Change c = TestChanges.newChange(project, admin.id(), sequences.nextChangeId());
    PatchSet.Id psId = c.currentPatchSetId();
    String rev = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
    PatchSet ps = newPatchSet(psId, rev, adminId);
    addNoteDbCommit(c.getId(), "Create change\n" + "\n" + "Patch-set: 1\n" + "Branch: " + c.getDest().branch() + "\n" + "Change-id: " + c.getKey().get() + "\n" + "Subject: Bogus subject\n" + "Commit: " + rev + "\n" + "Groups: " + rev + "\n");
    ChangeNotes notes = changeNotesFactory.create(c.getProject(), c.getId());
    FixInput fix = new FixInput();
    fix.deletePatchSetIfCommitMissing = true;
    assertProblems(notes, fix, problem("Ref missing: " + ps.id().toRefName()), problem("Object missing: patch set 1: " + rev, FIX_FAILED, "Cannot delete patch set; no patch sets would remain"));
    notes = reload(notes);
    assertThat(notes.getChange().currentPatchSetId().get()).isEqualTo(1);
    assertThat(psUtil.current(notes)).isNotNull();
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) TestChanges.newPatchSet(com.google.gerrit.testing.TestChanges.newPatchSet) Change(com.google.gerrit.entities.Change) 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 13 with FixInput

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

the class ConsistencyCheckerIT method patchSetRefMissingWithFix.

@Test
public void patchSetRefMissingWithFix() throws Exception {
    ChangeNotes notes = insertChange();
    ObjectId commitId = psUtil.current(notes).commitId();
    serverSideTestRepo.update("refs/other/foo", commitId);
    String refName = notes.getChange().currentPatchSetId().toRefName();
    deleteRef(refName);
    assertProblems(notes, new FixInput(), problem("Ref missing: " + refName, FIXED, "Repaired patch set ref"));
    assertThat(serverSideTestRepo.getRepository().exactRef(refName).getObjectId()).isEqualTo(commitId);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) 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 14 with FixInput

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

the class ConsistencyCheckerIT method createNewPatchSetForExpectedMergeCommitWithChangeId.

@Test
public void createNewPatchSetForExpectedMergeCommitWithChangeId() 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() + "\n" + "\n" + "Change-Id: " + notes.getChange().getKey().get() + "\n").create();
    serverSideTestRepo.getRevWalk().parseBody(mergedAs);
    assertThat(mergedAs.getFooterLines(FooterConstants.CHANGE_ID)).containsExactly(notes.getChange().getKey().get());
    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 15 with FixInput

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

the class ConsistencyCheckerIT method expectedMergedCommitMatchesMultiplePatchSets.

@Test
public void expectedMergedCommitMatchesMultiplePatchSets() throws Exception {
    ChangeNotes notes1 = insertChange();
    PatchSet.Id psId1 = psUtil.current(notes1).id();
    String dest = notes1.getChange().getDest().branch();
    RevCommit commit = serverSideTestRepo.getRevWalk().parseCommit(psUtil.current(notes1).commitId());
    serverSideTestRepo.branch(dest).update(commit);
    ChangeNotes notes2 = insertChange();
    notes2 = incrementPatchSet(notes2, commit);
    PatchSet.Id psId2 = psUtil.current(notes2).id();
    ChangeNotes notes3 = insertChange();
    notes3 = incrementPatchSet(notes3, commit);
    PatchSet.Id psId3 = psUtil.current(notes3).id();
    FixInput fix = new FixInput();
    fix.expectMergedAs = commit.name();
    assertProblems(notes1, fix, problem("Multiple patch sets for expected merged commit " + commit.name() + ": [" + psId1 + ", " + psId2 + ", " + psId3 + "]"));
}
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