Search in sources :

Example 51 with ChangeNotes

use of com.google.gerrit.server.notedb.ChangeNotes 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 52 with ChangeNotes

use of com.google.gerrit.server.notedb.ChangeNotes 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)

Example 53 with ChangeNotes

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

the class ConsistencyCheckerIT method extensionApiReturnsUpdatedValueAfterFix.

@Test
public void extensionApiReturnsUpdatedValueAfterFix() throws Exception {
    ChangeNotes notes = insertChange();
    ObjectId commitId = psUtil.current(notes).commitId();
    serverSideTestRepo.branch(notes.getChange().getDest().branch()).update(serverSideTestRepo.getRevWalk().parseCommit(commitId));
    ChangeInfo info = gApi.changes().id(notes.getChangeId().get()).info();
    assertThat(info.status).isEqualTo(ChangeStatus.NEW);
    info = gApi.changes().id(notes.getChangeId().get()).check(new FixInput());
    assertThat(info.status).isEqualTo(ChangeStatus.MERGED);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) 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 54 with ChangeNotes

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

the class ConsistencyCheckerIT method patchSetRefMissing.

@Test
public void patchSetRefMissing() throws Exception {
    ChangeNotes notes = insertChange();
    serverSideTestRepo.update("refs/other/foo", psUtil.current(notes).commitId());
    String refName = notes.getChange().currentPatchSetId().toRefName();
    deleteRef(refName);
    assertProblems(notes, null, problem("Ref missing: " + refName));
}
Also used : ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 55 with ChangeNotes

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

the class ConsistencyCheckerIT method newChangeIsMerged.

@Test
public void newChangeIsMerged() throws Exception {
    ChangeNotes notes = insertChange();
    ObjectId commitId = psUtil.current(notes).commitId();
    serverSideTestRepo.branch(notes.getChange().getDest().branch()).update(serverSideTestRepo.getRevWalk().parseCommit(commitId));
    assertProblems(notes, null, problem("Patch set 1 (" + commitId.name() + ") is merged into destination ref" + " refs/heads/master (" + commitId.name() + "), but change status is NEW"));
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)134 Test (org.junit.Test)54 Change (com.google.gerrit.entities.Change)47 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)43 PatchSet (com.google.gerrit.entities.PatchSet)42 ObjectId (org.eclipse.jgit.lib.ObjectId)33 StorageException (com.google.gerrit.exceptions.StorageException)22 Change (com.google.gerrit.reviewdb.client.Change)21 Project (com.google.gerrit.entities.Project)17 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)16 FixInput (com.google.gerrit.extensions.api.changes.FixInput)16 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)14 HumanComment (com.google.gerrit.entities.HumanComment)13 TestChanges.newPatchSet (com.google.gerrit.testing.TestChanges.newPatchSet)12 IOException (java.io.IOException)12 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)11 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)10 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)10 AuthException (com.google.gerrit.extensions.restapi.AuthException)9