Search in sources :

Example 36 with PushResult

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

the class ExternalIdIT method testPushToExternalIdsBranchRejectsInvalidExternalId.

private void testPushToExternalIdsBranchRejectsInvalidExternalId(ExternalId invalidExtId) throws Exception {
    TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
    fetch(allUsersRepo, RefNames.REFS_EXTERNAL_IDS + ":" + RefNames.REFS_EXTERNAL_IDS);
    allUsersRepo.reset(RefNames.REFS_EXTERNAL_IDS);
    addExtId(allUsersRepo, invalidExtId);
    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)

Example 37 with PushResult

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

the class ExternalIdIT method pushToExternalIdsBranch.

@Test
public void pushToExternalIdsBranch() throws Exception {
    TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
    fetch(allUsersRepo, RefNames.REFS_EXTERNAL_IDS + ":" + RefNames.REFS_EXTERNAL_IDS);
    allUsersRepo.reset(RefNames.REFS_EXTERNAL_IDS);
    // different case email is allowed
    ExternalId newExtId = createExternalIdWithOtherCaseEmail("foo:bar");
    addExtId(allUsersRepo, newExtId);
    allUsersRepo.reset(RefNames.REFS_EXTERNAL_IDS);
    List<AccountExternalIdInfo> extIdsBefore = gApi.accounts().self().getExternalIds();
    allowPushOfExternalIds();
    PushResult r = pushHead(allUsersRepo, RefNames.REFS_EXTERNAL_IDS);
    assertThat(r.getRemoteUpdate(RefNames.REFS_EXTERNAL_IDS).getStatus()).isEqualTo(Status.OK);
    List<AccountExternalIdInfo> extIdsAfter = gApi.accounts().self().getExternalIds();
    assertThat(extIdsAfter).containsExactlyElementsIn(Iterables.concat(extIdsBefore, ImmutableSet.of(toExternalIdInfo(newExtId))));
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) PushResult(org.eclipse.jgit.transport.PushResult) AccountExternalIdInfo(com.google.gerrit.extensions.common.AccountExternalIdInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 38 with PushResult

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

the class SubmitByFastForwardIT method submitSameCommitsAsInExperimentalBranch.

@Test
public void submitSameCommitsAsInExperimentalBranch() throws Exception {
    RevCommit initialHead = getRemoteHead();
    grant(project, "refs/heads/*", Permission.CREATE);
    grant(project, "refs/heads/experimental", Permission.PUSH);
    RevCommit c1 = commitBuilder().add("b.txt", "1").message("commit at tip").create();
    String id1 = GitUtil.getChangeId(testRepo, c1).get();
    PushResult r1 = pushHead(testRepo, "refs/for/master", false);
    assertThat(r1.getRemoteUpdate("refs/for/master").getNewObjectId()).isEqualTo(c1.getId());
    PushResult r2 = pushHead(testRepo, "refs/heads/experimental", false);
    assertThat(r2.getRemoteUpdate("refs/heads/experimental").getNewObjectId()).isEqualTo(c1.getId());
    submit(id1);
    RevCommit headAfterSubmit = getRemoteHead();
    assertThat(getRemoteHead().getId()).isEqualTo(c1.getId());
    assertSubmitter(id1, 1);
    assertRefUpdatedEvents(initialHead, headAfterSubmit);
    assertChangeMergedEvents(id1, headAfterSubmit.name());
}
Also used : PushResult(org.eclipse.jgit.transport.PushResult) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 39 with PushResult

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

the class PushTagIT method pushTag.

private String pushTag(TagType tagType, String tagName, boolean newCommit, boolean force, Status expectedStatus) throws Exception {
    if (force) {
        testRepo.reset(initialHead);
    }
    commit(user.getIdent(), "subject");
    boolean createTag = tagName == null;
    tagName = MoreObjects.firstNonNull(tagName, "v1_" + System.nanoTime());
    switch(tagType) {
        case LIGHTWEIGHT:
            break;
        case ANNOTATED:
            if (createTag) {
                createAnnotatedTag(testRepo, tagName, user.getIdent());
            } else {
                updateAnnotatedTag(testRepo, tagName, user.getIdent());
            }
            break;
        default:
            throw new IllegalStateException("unexpected tag type: " + tagType);
    }
    if (!newCommit) {
        grant(project, "refs/for/refs/heads/master", Permission.SUBMIT, false, REGISTERED_USERS);
        pushHead(testRepo, "refs/for/master%submit");
    }
    String tagRef = tagRef(tagName);
    PushResult r = tagType == LIGHTWEIGHT ? pushHead(testRepo, tagRef, false, force) : GitUtil.pushTag(testRepo, tagName, !createTag);
    RemoteRefUpdate refUpdate = r.getRemoteUpdate(tagRef);
    assertThat(refUpdate.getStatus()).named(tagType.name()).isEqualTo(expectedStatus);
    return tagName;
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) PushResult(org.eclipse.jgit.transport.PushResult)

Example 40 with PushResult

use of org.eclipse.jgit.transport.PushResult in project camel by apache.

the class GitRemoteProducerTest method pushTest.

@Ignore("Require a remote git repository")
@Test
public void pushTest() throws Exception {
    Repository repository = getTestRepository();
    File fileToAdd = new File(gitLocalRepo, filenameToAdd);
    fileToAdd.createNewFile();
    template.send("direct:add", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, filenameToAdd);
        }
    });
    File gitDir = new File(gitLocalRepo, ".git");
    assertEquals(gitDir.exists(), true);
    Status status = new Git(repository).status().call();
    assertTrue(status.getAdded().contains(filenameToAdd));
    template.send("direct:commit", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
        }
    });
    Iterable<PushResult> result = template.requestBody("direct:push", "", Iterable.class);
    repository.close();
}
Also used : Exchange(org.apache.camel.Exchange) Status(org.eclipse.jgit.api.Status) Repository(org.eclipse.jgit.lib.Repository) Processor(org.apache.camel.Processor) Git(org.eclipse.jgit.api.Git) PushResult(org.eclipse.jgit.transport.PushResult) File(java.io.File) Ignore(org.junit.Ignore) 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