Search in sources :

Example 51 with RevCommit

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));
}
Also used : PatchListEntry(com.google.gerrit.server.patch.PatchListEntry) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 52 with RevCommit

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);
    }
}
Also used : SubmittedTogetherInfo(com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 53 with RevCommit

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);
    }
}
Also used : SubmittedTogetherInfo(com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 54 with RevCommit

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();
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 55 with RevCommit

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;
    }
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ObjectId(org.eclipse.jgit.lib.ObjectId) CodeReviewRevWalk(com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

RevCommit (org.eclipse.jgit.revwalk.RevCommit)1302 Test (org.junit.Test)650 RevWalk (org.eclipse.jgit.revwalk.RevWalk)333 ObjectId (org.eclipse.jgit.lib.ObjectId)295 Repository (org.eclipse.jgit.lib.Repository)273 IOException (java.io.IOException)222 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)190 Ref (org.eclipse.jgit.lib.Ref)174 File (java.io.File)134 ArrayList (java.util.ArrayList)134 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)133 Git (org.eclipse.jgit.api.Git)133 PersonIdent (org.eclipse.jgit.lib.PersonIdent)105 Change (com.google.gerrit.entities.Change)87 TestRepository (org.eclipse.jgit.junit.TestRepository)72 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)70 ObjectReader (org.eclipse.jgit.lib.ObjectReader)64 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)61 List (java.util.List)61 HashMap (java.util.HashMap)57