Search in sources :

Example 31 with PushResult

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

the class AbstractPushForReview method pushForReview.

private static void pushForReview(TestRepository<?> testRepo, RemoteRefUpdate.Status expectedStatus, String expectedMessage) throws GitAPIException {
    String ref = "refs/for/master";
    PushResult r = pushHead(testRepo, ref);
    RemoteRefUpdate refUpdate = r.getRemoteUpdate(ref);
    assertThat(refUpdate.getStatus()).isEqualTo(expectedStatus);
    if (expectedMessage != null) {
        assertThat(refUpdate.getMessage()).contains(expectedMessage);
    }
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) PushResult(org.eclipse.jgit.transport.PushResult)

Example 32 with PushResult

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

the class SubmoduleSubscriptionsIT method allowedButNotSubscribed.

@Test
public void allowedButNotSubscribed() throws Exception {
    TestRepository<?> superRepo = createProjectWithPush("super-project");
    TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
    allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master", "super-project", "refs/heads/master");
    pushChangeTo(subRepo, "master");
    subRepo.branch("HEAD").commit().insertChangeId().message("some change").add("b.txt", "b contents for testing").create();
    String refspec = "HEAD:refs/heads/master";
    PushResult r = Iterables.getOnlyElement(subRepo.git().push().setRemote("origin").setRefSpecs(new RefSpec(refspec)).call());
    assertThat(r.getMessages()).doesNotContain("error");
    assertThat(r.getRemoteUpdate("refs/heads/master").getStatus()).isEqualTo(RemoteRefUpdate.Status.OK);
    assertThat(hasSubmodule(superRepo, "master", "subscribed-to-project")).isFalse();
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) PushResult(org.eclipse.jgit.transport.PushResult) Test(org.junit.Test)

Example 33 with PushResult

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

the class AbstractSubmoduleSubscription method pushChangeTo.

protected ObjectId pushChangeTo(TestRepository<?> repo, String ref, String file, String content, String message, String topic) throws Exception {
    ObjectId ret = repo.branch("HEAD").commit().insertChangeId().message(message).add(file, content).create();
    String pushedRef = ref;
    if (!topic.isEmpty()) {
        pushedRef += "/" + name(topic);
    }
    String refspec = "HEAD:" + pushedRef;
    Iterable<PushResult> res = repo.git().push().setRemote("origin").setRefSpecs(new RefSpec(refspec)).call();
    RemoteRefUpdate u = Iterables.getOnlyElement(res).getRemoteUpdate(pushedRef);
    assertThat(u).isNotNull();
    assertThat(u.getStatus()).isEqualTo(Status.OK);
    assertThat(u.getNewObjectId()).isEqualTo(ret);
    return ret;
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) RefSpec(org.eclipse.jgit.transport.RefSpec) ObjectId(org.eclipse.jgit.lib.ObjectId) PushResult(org.eclipse.jgit.transport.PushResult)

Example 34 with PushResult

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

the class ExternalIdIT method pushToExternalIdsBranchRejectsExternalIdWithoutAccountId.

@Test
public void pushToExternalIdsBranchRejectsExternalIdWithoutAccountId() throws Exception {
    TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
    fetch(allUsersRepo, RefNames.REFS_EXTERNAL_IDS + ":" + RefNames.REFS_EXTERNAL_IDS);
    allUsersRepo.reset(RefNames.REFS_EXTERNAL_IDS);
    insertExternalIdWithoutAccountId(allUsersRepo.getRepository(), allUsersRepo.getRevWalk(), "foo:bar");
    allUsersRepo.reset(RefNames.REFS_EXTERNAL_IDS);
    allowPushOfExternalIds();
    PushResult r = pushHead(allUsersRepo, RefNames.REFS_EXTERNAL_IDS);
    assertRefUpdateFailure(r.getRemoteUpdate(RefNames.REFS_EXTERNAL_IDS), "invalid external IDs");
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PushResult(org.eclipse.jgit.transport.PushResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 35 with PushResult

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

the class ExternalIdIT method pushToExternalIdsBranchRejectsExternalIdWithEmptyNote.

@Test
public void pushToExternalIdsBranchRejectsExternalIdWithEmptyNote() throws Exception {
    TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
    fetch(allUsersRepo, RefNames.REFS_EXTERNAL_IDS + ":" + RefNames.REFS_EXTERNAL_IDS);
    allUsersRepo.reset(RefNames.REFS_EXTERNAL_IDS);
    insertExternalIdWithEmptyNote(allUsersRepo.getRepository(), allUsersRepo.getRevWalk(), "foo:bar");
    allUsersRepo.reset(RefNames.REFS_EXTERNAL_IDS);
    allowPushOfExternalIds();
    PushResult r = pushHead(allUsersRepo, RefNames.REFS_EXTERNAL_IDS);
    assertRefUpdateFailure(r.getRemoteUpdate(RefNames.REFS_EXTERNAL_IDS), "invalid external IDs");
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PushResult(org.eclipse.jgit.transport.PushResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

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