Search in sources :

Example 46 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.

the class CreateChangeIT method cherryPickCommitWithoutChangeId.

@Test
public void cherryPickCommitWithoutChangeId() throws Exception {
    // This test is a little superfluous, since the current cherry-pick code ignores
    // the commit message of the to-be-cherry-picked change, using the one in
    // CherryPickInput instead.
    CherryPickInput input = new CherryPickInput();
    input.destination = "foo";
    input.message = "it goes to foo branch";
    gApi.projects().name(project.get()).branch(input.destination).create(new BranchInput());
    RevCommit revCommit = createNewCommitWithoutChangeId();
    ChangeInfo changeInfo = gApi.projects().name(project.get()).commit(revCommit.getName()).cherryPick(input).get();
    assertThat(changeInfo.messages).hasSize(1);
    Iterator<ChangeMessageInfo> messageIterator = changeInfo.messages.iterator();
    String expectedMessage = String.format("Patch Set 1: Cherry Picked from commit %s.", revCommit.getName());
    assertThat(messageIterator.next().message).isEqualTo(expectedMessage);
    RevisionInfo revInfo = changeInfo.revisions.get(changeInfo.currentRevision);
    assertThat(revInfo).isNotNull();
    CommitInfo commitInfo = revInfo.commit;
    assertThat(commitInfo.message).isEqualTo(input.message + "\n\nChange-Id: " + changeInfo.changeId + "\n");
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 47 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.

the class CreateChangeIT method cherryPickCommitWithChangeId.

@Test
public void cherryPickCommitWithChangeId() throws Exception {
    CherryPickInput input = new CherryPickInput();
    input.destination = "foo";
    RevCommit revCommit = createChange().getCommit();
    List<String> footers = revCommit.getFooterLines("Change-Id");
    assertThat(footers).hasSize(1);
    String changeId = footers.get(0);
    input.message = "it goes to foo branch\n\nChange-Id: " + changeId;
    gApi.projects().name(project.get()).branch(input.destination).create(new BranchInput());
    ChangeInfo changeInfo = gApi.projects().name(project.get()).commit(revCommit.getName()).cherryPick(input).get();
    assertThat(changeInfo.messages).hasSize(1);
    Iterator<ChangeMessageInfo> messageIterator = changeInfo.messages.iterator();
    String expectedMessage = String.format("Patch Set 1: Cherry Picked from commit %s.", revCommit.getName());
    assertThat(messageIterator.next().message).isEqualTo(expectedMessage);
    RevisionInfo revInfo = changeInfo.revisions.get(changeInfo.currentRevision);
    assertThat(revInfo).isNotNull();
    assertThat(revInfo.commit.message).isEqualTo(input.message + "\n");
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 48 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.

the class CreateChangeIT method createNewCommitWithoutChangeId.

private RevCommit createNewCommitWithoutChangeId() throws Exception {
    try (Repository repo = repoManager.openRepository(project);
        RevWalk walk = new RevWalk(repo)) {
        Ref ref = repo.exactRef("refs/heads/master");
        RevCommit tip = null;
        if (ref != null) {
            tip = walk.parseCommit(ref.getObjectId());
        }
        TestRepository<?> testSrcRepo = new TestRepository<>(repo);
        TestRepository<?>.BranchBuilder<?> builder = testSrcRepo.branch("refs/heads/master");
        RevCommit revCommit = tip == null ? builder.commit().message("commit 1").add("a.txt", "content").create() : builder.commit().parent(tip).message("commit 1").add("a.txt", "content").create();
        assertThat(GitUtil.getChangeId(testSrcRepo, revCommit)).isEmpty();
        return revCommit;
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) RefNames.changeMetaRef(com.google.gerrit.reviewdb.client.RefNames.changeMetaRef) Ref(org.eclipse.jgit.lib.Ref) TestRepository(org.eclipse.jgit.junit.TestRepository) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 49 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.

the class PatchListCacheIT method listPatchesAgainstOtherPatchSetWithRebase.

@Test
public void listPatchesAgainstOtherPatchSetWithRebase() 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 a = commitBuilder().add(FILE_A, "1").rm(FILE_D).message(SUBJECT_2).create();
    pushHead(testRepo, "refs/for/master", false);
    // Change 2,1 (+FILE_B)
    testRepo.reset("HEAD~1");
    commitBuilder().add(FILE_B, "2").message(SUBJECT_3).create();
    pushHead(testRepo, "refs/for/master", false);
    // Change 1,2 (+FILE_A, +FILE_C, -FILE_D)
    testRepo.cherryPick(a);
    RevCommit b = amendBuilder().add(FILE_C, "2").create();
    pushHead(testRepo, "refs/for/master", false);
    // Compare Change 1,1 with Change 1,2 (+FILE_C)
    List<PatchListEntry> entries = getPatches(a, b);
    assertThat(entries).hasSize(2);
    assertModified(Patch.COMMIT_MSG, entries.get(0));
    assertAdded(FILE_C, entries.get(1));
    // Compare Change 1,2 with Change 1,1 (-FILE_C)
    List<PatchListEntry> entriesReverse = getPatches(b, a);
    assertThat(entriesReverse).hasSize(2);
    assertModified(Patch.COMMIT_MSG, entriesReverse.get(0));
    assertDeleted(FILE_C, entriesReverse.get(1));
}
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 50 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.

the class PatchListCacheIT method listPatchesAgainstOtherPatchSet.

@Test
public void listPatchesAgainstOtherPatchSet() throws Exception {
    commitBuilder().add(FILE_D, "4").message(SUBJECT_1).create();
    pushHead(testRepo, "refs/heads/master", false);
    // Change 1,1 (+FILE_A, +FILE_C, -FILE_D)
    RevCommit a = commitBuilder().add(FILE_A, "1").add(FILE_C, "3").rm(FILE_D).message(SUBJECT_2).create();
    pushHead(testRepo, "refs/for/master", false);
    // Change 1,2 (+FILE_A, +FILE_B, -FILE_D)
    RevCommit b = amendBuilder().add(FILE_B, "2").rm(FILE_C).create();
    pushHead(testRepo, "refs/for/master", false);
    // Compare Change 1,1 with Change 1,2 (+FILE_B, -FILE_C)
    List<PatchListEntry> entries = getPatches(a, b);
    assertThat(entries).hasSize(3);
    assertModified(Patch.COMMIT_MSG, entries.get(0));
    assertAdded(FILE_B, entries.get(1));
    assertDeleted(FILE_C, entries.get(2));
    // Compare Change 1,2 with Change 1,1 (-FILE_B, +FILE_C)
    List<PatchListEntry> entriesReverse = getPatches(b, a);
    assertThat(entriesReverse).hasSize(3);
    assertModified(Patch.COMMIT_MSG, entriesReverse.get(0));
    assertDeleted(FILE_B, entriesReverse.get(1));
    assertAdded(FILE_C, entriesReverse.get(2));
}
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)

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