use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class MergeListIT method setup.
@Before
public void setup() throws Exception {
ObjectId initial = repo().exactRef(HEAD).getLeaf().getObjectId();
PushOneCommit.Result gp1 = pushFactory.create(db, admin.getIdent(), testRepo, "grand parent 1", ImmutableMap.of("foo", "foo-1.1", "bar", "bar-1.1")).to("refs/for/master");
grandParent1 = gp1.getCommit();
PushOneCommit.Result p1 = pushFactory.create(db, admin.getIdent(), testRepo, "parent 1", ImmutableMap.of("foo", "foo-1.2", "bar", "bar-1.2")).to("refs/for/master");
parent1 = p1.getCommit();
// reset HEAD in order to create a sibling of the first change
testRepo.reset(initial);
PushOneCommit.Result gp2 = pushFactory.create(db, admin.getIdent(), testRepo, "grand parent 2", ImmutableMap.of("foo", "foo-2.1", "bar", "bar-2.1")).to("refs/for/master");
grandParent2 = gp2.getCommit();
PushOneCommit.Result p2 = pushFactory.create(db, admin.getIdent(), testRepo, "parent 2", ImmutableMap.of("foo", "foo-2.2", "bar", "bar-2.2")).to("refs/for/master");
parent2 = p2.getCommit();
PushOneCommit m = pushFactory.create(db, admin.getIdent(), testRepo, "merge", ImmutableMap.of("foo", "foo-1", "bar", "bar-2"));
m.setParents(ImmutableList.of(p1.getCommit(), p2.getCommit()));
PushOneCommit.Result result = m.to("refs/for/master");
result.assertOkStatus();
merge = result.getCommit();
changeId = result.getChangeId();
}
use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class StickyApprovalsIT method createChangeForMergeCommit.
private String createChangeForMergeCommit() throws Exception {
ObjectId initial = repo().exactRef(HEAD).getLeaf().getObjectId();
PushOneCommit.Result parent1 = createChange("parent 1", "p1.txt", "content 1");
testRepo.reset(initial);
PushOneCommit.Result parent2 = createChange("parent 2", "p2.txt", "content 2");
testRepo.reset(parent1.getCommit());
PushOneCommit merge = pushFactory.create(db, admin.getIdent(), testRepo);
merge.setParents(ImmutableList.of(parent1.getCommit(), parent2.getCommit()));
PushOneCommit.Result result = merge.to("refs/for/master");
result.assertOkStatus();
return result.getChangeId();
}
use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class AbstractSubmit method getLatestRemoteDiff.
private String getLatestRemoteDiff() throws Exception {
try (Repository repo = repoManager.openRepository(project);
RevWalk rw = new RevWalk(repo)) {
ObjectId oldTreeId = repo.resolve("refs/heads/master~1^{tree}");
ObjectId newTreeId = repo.resolve("refs/heads/master^{tree}");
return getLatestDiff(repo, oldTreeId, newTreeId);
}
}
use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class AbstractSubmit method submitMultipleChangesPreview.
@Test
public void submitMultipleChangesPreview() throws Exception {
RevCommit initialHead = getRemoteHead();
PushOneCommit.Result change2 = createChange("Change 2", "a.txt", "other content");
PushOneCommit.Result change3 = createChange("Change 3", "d", "d");
PushOneCommit.Result change4 = createChange("Change 4", "e", "e");
// change 2 is not approved, but we ignore labels
approve(change3.getChangeId());
Map<Branch.NameKey, ObjectId> actual = fetchFromSubmitPreview(change4.getChangeId());
Map<String, Map<String, Integer>> expected = new HashMap<>();
expected.put(project.get(), new HashMap<>());
expected.get(project.get()).put("refs/heads/master", 3);
assertThat(actual).containsKey(new Branch.NameKey(project, "refs/heads/master"));
if (getSubmitType() == SubmitType.CHERRY_PICK) {
// CherryPick ignores dependencies, thus only change and destination
// branch refs are modified.
assertThat(actual).hasSize(2);
} else if (getSubmitType() == SubmitType.REBASE_ALWAYS) {
// RebaseAlways takes care of dependencies, therefore Change{2,3,4} and
// destination branch will be modified.
assertThat(actual).hasSize(4);
} else {
assertThat(actual).hasSize(1);
}
// check that the submit preview did not actually submit
RevCommit headAfterSubmit = getRemoteHead();
assertThat(headAfterSubmit).isEqualTo(initialHead);
assertRefUpdatedEvents();
assertChangeMergedEvents();
// now check we actually have the same content:
approve(change2.getChangeId());
submit(change4.getChangeId());
assertTrees(project, actual);
}
use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class AbstractSubmitByMerge method repairChangeStateAfterFailure.
@Test
public void repairChangeStateAfterFailure() throws Exception {
// In NoteDb-only mode, repo and meta updates are atomic (at least in InMemoryRepository).
assume().that(notesMigration.disableChangeReviewDb()).isFalse();
RevCommit initialHead = getRemoteHead();
PushOneCommit.Result change = createChange("Change 1", "a.txt", "content");
submit(change.getChangeId());
RevCommit afterChange1Head = getRemoteHead();
testRepo.reset(initialHead);
PushOneCommit.Result change2 = createChange("Change 2", "b.txt", "other content");
Change.Id id2 = change2.getChange().getId();
SubmitInput failAfterRefUpdates = new TestSubmitInput(new SubmitInput(), true);
submit(change2.getChangeId(), failAfterRefUpdates, ResourceConflictException.class, "Failing after ref updates");
// Bad: ref advanced but change wasn't updated.
PatchSet.Id psId1 = new PatchSet.Id(id2, 1);
ChangeInfo info = gApi.changes().id(id2.get()).get();
assertThat(info.status).isEqualTo(ChangeStatus.NEW);
assertThat(info.revisions.get(info.currentRevision)._number).isEqualTo(1);
RevCommit tip;
try (Repository repo = repoManager.openRepository(project);
RevWalk rw = new RevWalk(repo)) {
ObjectId rev1 = repo.exactRef(psId1.toRefName()).getObjectId();
assertThat(rev1).isNotNull();
tip = rw.parseCommit(repo.exactRef("refs/heads/master").getObjectId());
assertThat(tip.getParentCount()).isEqualTo(2);
assertThat(tip.getParent(0)).isEqualTo(afterChange1Head);
assertThat(tip.getParent(1)).isEqualTo(change2.getCommit());
}
submit(change2.getChangeId(), new SubmitInput(), null, null);
// Change status and patch set entities were updated, and branch tip stayed
// the same.
info = gApi.changes().id(id2.get()).get();
assertThat(info.status).isEqualTo(ChangeStatus.MERGED);
assertThat(info.revisions.get(info.currentRevision)._number).isEqualTo(1);
assertThat(Iterables.getLast(info.messages).message).isEqualTo("Change has been successfully merged by Administrator");
try (Repository repo = repoManager.openRepository(project)) {
assertThat(repo.exactRef("refs/heads/master").getObjectId()).isEqualTo(tip);
}
}
Aggregations