Search in sources :

Example 11 with PushResult

use of org.eclipse.jgit.transport.PushResult in project gerrit by GerritCodeReview.

the class PushTagIT method pushTagDeletion.

private void pushTagDeletion(TagType tagType, String tagName, Status expectedStatus) throws Exception {
    String tagRef = tagRef(tagName);
    PushResult r = deleteRef(testRepo, tagRef);
    RemoteRefUpdate refUpdate = r.getRemoteUpdate(tagRef);
    assertThat(refUpdate.getStatus()).named(tagType.name()).isEqualTo(expectedStatus);
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) PushResult(org.eclipse.jgit.transport.PushResult)

Example 12 with PushResult

use of org.eclipse.jgit.transport.PushResult in project gerrit by GerritCodeReview.

the class AbstractPushForReview method pushSameCommitTwiceUsingMagicBranchBaseOption.

@Test
public void pushSameCommitTwiceUsingMagicBranchBaseOption() throws Exception {
    grant(project, "refs/heads/master", Permission.PUSH);
    PushOneCommit.Result rBase = pushTo("refs/heads/master");
    rBase.assertOkStatus();
    gApi.projects().name(project.get()).branch("foo").create(new BranchInput());
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "b.txt", "anotherContent");
    PushOneCommit.Result r = push.to("refs/for/master");
    r.assertOkStatus();
    PushResult pr = GitUtil.pushHead(testRepo, "refs/for/foo%base=" + rBase.getCommit().name(), false, false);
    // BatchUpdate implementations differ in how they hook into progress monitors. We mostly just
    // care that there is a new change.
    assertThat(pr.getMessages()).containsMatch("changes: new: 1,( refs: 1)? done");
    assertTwoChangesWithSameRevision(r);
}
Also used : BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushResult(org.eclipse.jgit.transport.PushResult) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 13 with PushResult

use of org.eclipse.jgit.transport.PushResult in project gerrit by GerritCodeReview.

the class AbstractPushForReview method pushInitialCommitForMasterBranch.

@Test
@TestProjectInput(createEmptyCommit = false)
public void pushInitialCommitForMasterBranch() throws Exception {
    RevCommit c = testRepo.commit().message("Initial commit").insertChangeId().create();
    String id = GitUtil.getChangeId(testRepo, c).get();
    testRepo.reset(c);
    String r = "refs/for/master";
    PushResult pr = pushHead(testRepo, r, false);
    assertPushOk(pr, r);
    ChangeInfo change = gApi.changes().id(id).info();
    assertThat(change.branch).isEqualTo("master");
    assertThat(change.status).isEqualTo(ChangeStatus.NEW);
    try (Repository repo = repoManager.openRepository(project)) {
        assertThat(repo.resolve("master")).isNull();
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushResult(org.eclipse.jgit.transport.PushResult) RevCommit(org.eclipse.jgit.revwalk.RevCommit) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 14 with PushResult

use of org.eclipse.jgit.transport.PushResult in project gerrit by GerritCodeReview.

the class AbstractPushForReview method mergedOptionWithNewCommitWithSameChangeIdFails.

@Test
public void mergedOptionWithNewCommitWithSameChangeIdFails() throws Exception {
    PushOneCommit.Result r = pushTo("refs/for/master");
    r.assertOkStatus();
    gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
    gApi.changes().id(r.getChangeId()).current().submit();
    RevCommit c2 = testRepo.amend(r.getCommit()).message("New subject").insertChangeId(r.getChangeId().substring(1)).create();
    testRepo.reset(c2);
    String ref = "refs/for/master%merged";
    PushResult pr = pushHead(testRepo, ref, false);
    RemoteRefUpdate rru = pr.getRemoteUpdate(ref);
    assertThat(rru.getStatus()).isEqualTo(RemoteRefUpdate.Status.REJECTED_OTHER_REASON);
    assertThat(rru.getMessage()).contains("not merged into branch");
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) PushResult(org.eclipse.jgit.transport.PushResult) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 15 with PushResult

use of org.eclipse.jgit.transport.PushResult in project gerrit by GerritCodeReview.

the class GitUtil method pushOne.

public static PushResult pushOne(TestRepository<?> testRepo, String source, String target, boolean pushTags, boolean force, List<String> pushOptions) throws GitAPIException {
    PushCommand pushCmd = testRepo.git().push();
    pushCmd.setForce(force);
    pushCmd.setPushOptions(pushOptions);
    pushCmd.setRefSpecs(new RefSpec(source + ":" + target));
    if (pushTags) {
        pushCmd.setPushTags();
    }
    Iterable<PushResult> r = pushCmd.call();
    return Iterables.getOnlyElement(r);
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) PushResult(org.eclipse.jgit.transport.PushResult) PushCommand(org.eclipse.jgit.api.PushCommand)

Aggregations

PushResult (org.eclipse.jgit.transport.PushResult)43 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)28 Test (org.junit.Test)24 File (java.io.File)14 CloneCommand (org.eclipse.jgit.api.CloneCommand)13 Git (org.eclipse.jgit.api.Git)13 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)12 BufferedWriter (java.io.BufferedWriter)11 FileOutputStream (java.io.FileOutputStream)11 OutputStreamWriter (java.io.OutputStreamWriter)11 Date (java.util.Date)11 RepositoryModel (com.gitblit.models.RepositoryModel)10 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)10 RefSpec (org.eclipse.jgit.transport.RefSpec)9 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)8 RevCommit (org.eclipse.jgit.revwalk.RevCommit)8 PushCommand (org.eclipse.jgit.api.PushCommand)5 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)5 UserModel (com.gitblit.models.UserModel)4 Repository (org.eclipse.jgit.lib.Repository)4