use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.
the class PatchListCacheIT method listPatchesAgainstBase.
@Test
public void listPatchesAgainstBase() throws Exception {
commitBuilder().add(FILE_D, "4").message(SUBJECT_1).create();
pushHead(testRepo, "refs/heads/master", false);
// Change 1, 1 (+FILE_A, -FILE_D)
RevCommit c = commitBuilder().add(FILE_A, "1").rm(FILE_D).message(SUBJECT_2).insertChangeId().create();
String id = getChangeId(testRepo, c).get();
pushHead(testRepo, "refs/for/master", false);
// Compare Change 1,1 with Base (+FILE_A, -FILE_D)
List<PatchListEntry> entries = getCurrentPatches(id);
assertThat(entries).hasSize(3);
assertAdded(Patch.COMMIT_MSG, entries.get(0));
assertAdded(FILE_A, entries.get(1));
assertDeleted(FILE_D, entries.get(2));
// Change 1,2 (+FILE_A, +FILE_B, -FILE_D)
c = amendBuilder().add(FILE_B, "2").create();
pushHead(testRepo, "refs/for/master", false);
entries = getCurrentPatches(id);
// Compare Change 1,2 with Base (+FILE_A, +FILE_B, -FILE_D)
assertThat(entries).hasSize(4);
assertAdded(Patch.COMMIT_MSG, entries.get(0));
assertAdded(FILE_A, entries.get(1));
assertAdded(FILE_B, entries.get(2));
assertDeleted(FILE_D, entries.get(3));
}
use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.
the class SubmittedTogetherIT method hiddenDraftInTopic.
@Test
public void hiddenDraftInTopic() throws Exception {
RevCommit initialHead = getRemoteHead();
RevCommit a = commitBuilder().add("a", "1").message("change 1").create();
pushHead(testRepo, "refs/for/master/" + name("topic"), false);
String id1 = getChangeId(a);
testRepo.reset(initialHead);
commitBuilder().add("b", "2").message("invisible change").create();
pushHead(testRepo, "refs/drafts/master/" + name("topic"), false);
setApiUser(user);
SubmittedTogetherInfo result = gApi.changes().id(id1).submittedTogether(EnumSet.of(NON_VISIBLE_CHANGES));
if (isSubmitWholeTopicEnabled()) {
assertThat(result.changes).hasSize(1);
assertThat(result.changes.get(0).changeId).isEqualTo(id1);
assertThat(result.nonVisibleChanges).isEqualTo(1);
} else {
assertThat(result.changes).isEmpty();
assertThat(result.nonVisibleChanges).isEqualTo(0);
}
}
use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.
the class SubmittedTogetherIT method doNotRevealVisibleAncestorOfHiddenDraft.
@Test
public void doNotRevealVisibleAncestorOfHiddenDraft() throws Exception {
RevCommit initialHead = getRemoteHead();
commitBuilder().message("parent").create();
pushHead(testRepo, "refs/for/master", false);
commitBuilder().message("draft").create();
pushHead(testRepo, "refs/drafts/master/" + name("topic"), false);
testRepo.reset(initialHead);
RevCommit change = commitBuilder().message("same topic").create();
pushHead(testRepo, "refs/for/master/" + name("topic"), false);
String id = getChangeId(change);
setApiUser(user);
SubmittedTogetherInfo result = gApi.changes().id(id).submittedTogether(EnumSet.of(NON_VISIBLE_CHANGES));
if (isSubmitWholeTopicEnabled()) {
assertThat(result.changes).hasSize(1);
assertThat(result.changes.get(0).changeId).isEqualTo(id);
assertThat(result.nonVisibleChanges).isEqualTo(2);
} else {
assertThat(result.changes).isEmpty();
assertThat(result.nonVisibleChanges).isEqualTo(0);
}
}
use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.
the class SubmittedTogetherIT method hiddenDraftInTopicOldApi.
@Test
public void hiddenDraftInTopicOldApi() throws Exception {
RevCommit initialHead = getRemoteHead();
RevCommit a = commitBuilder().add("a", "1").message("change 1").create();
pushHead(testRepo, "refs/for/master/" + name("topic"), false);
String id1 = getChangeId(a);
testRepo.reset(initialHead);
commitBuilder().add("b", "2").message("invisible change").create();
pushHead(testRepo, "refs/drafts/master/" + name("topic"), false);
setApiUser(user);
if (isSubmitWholeTopicEnabled()) {
exception.expect(AuthException.class);
exception.expectMessage("change would be submitted with a change that you cannot see");
gApi.changes().id(id1).submittedTogether();
} else {
List<ChangeInfo> result = gApi.changes().id(id1).submittedTogether();
assertThat(result).isEmpty();
}
}
use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.
the class MergeabilityCacheImpl method get.
@Override
public boolean get(ObjectId commit, Ref intoRef, SubmitType submitType, String mergeStrategy, Branch.NameKey dest, Repository repo) {
ObjectId into = intoRef != null ? intoRef.getObjectId() : ObjectId.zeroId();
EntryKey key = new EntryKey(commit, into, submitType, mergeStrategy);
try {
return cache.get(key, () -> {
if (key.into.equals(ObjectId.zeroId())) {
// Assume yes on new branch.
return true;
}
try (CodeReviewRevWalk rw = CodeReviewCommit.newRevWalk(repo)) {
Set<RevCommit> accepted = SubmitDryRun.getAlreadyAccepted(repo, rw);
accepted.add(rw.parseCommit(key.into));
accepted.addAll(Arrays.asList(rw.parseCommit(key.commit).getParents()));
return submitDryRun.run(key.submitType, repo, rw, dest, key.into, key.commit, accepted);
}
});
} catch (ExecutionException | UncheckedExecutionException e) {
log.error(String.format("Error checking mergeability of %s into %s (%s)", key.commit.name(), key.into.name(), key.submitType.name()), e.getCause());
return false;
}
}
Aggregations