Search in sources :

Example 76 with RemoteRefUpdate

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

the class AbstractPushForReview method errorMessageFormat.

@Test
public void errorMessageFormat() throws Exception {
    RevCommit c = createCommit(testRepo, "Message without Change-Id");
    assertThat(GitUtil.getChangeId(testRepo, c)).isEmpty();
    String ref = "refs/for/master";
    PushResult r = pushHead(testRepo, ref);
    RemoteRefUpdate refUpdate = r.getRemoteUpdate(ref);
    assertThat(refUpdate.getStatus()).isEqualTo(RemoteRefUpdate.Status.REJECTED_OTHER_REASON);
    String reason = String.format("commit %s: missing Change-Id in message footer", abbreviateName(c));
    assertThat(refUpdate.getMessage()).isEqualTo(reason);
    assertThat(r.getMessages()).contains("\nERROR: " + reason);
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) PushResult(org.eclipse.jgit.transport.PushResult) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 77 with RemoteRefUpdate

use of org.eclipse.jgit.transport.RemoteRefUpdate 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 78 with RemoteRefUpdate

use of org.eclipse.jgit.transport.RemoteRefUpdate 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 += "%topic=" + 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) AnyObjectId(org.eclipse.jgit.lib.AnyObjectId) ObjectId(org.eclipse.jgit.lib.ObjectId) PushResult(org.eclipse.jgit.transport.PushResult)

Example 79 with RemoteRefUpdate

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

the class AccountIT method deleteUserBranchWithAccessDatabaseCapability.

@Test
public void deleteUserBranchWithAccessDatabaseCapability() throws Exception {
    projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.ACCESS_DATABASE).group(REGISTERED_USERS)).update();
    projectOperations.project(allUsers).forUpdate().add(allow(Permission.DELETE).ref(RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}").group(REGISTERED_USERS).force(true)).update();
    TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
    String userRef = RefNames.refsUsers(admin.id());
    PushResult r = deleteRef(allUsersRepo, userRef);
    RemoteRefUpdate refUpdate = r.getRemoteUpdate(userRef);
    assertThat(refUpdate.getStatus()).isEqualTo(RemoteRefUpdate.Status.OK);
    try (Repository repo = repoManager.openRepository(allUsers)) {
        assertThat(repo.exactRef(userRef)).isNull();
    }
    assertThat(accountCache.get(admin.id())).isEmpty();
    assertThat(accountQueryProvider.get().byDefault(admin.id().toString(), true)).isEmpty();
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) PushResult(org.eclipse.jgit.transport.PushResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 80 with RemoteRefUpdate

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

the class AccountIT method cannotDeleteUserBranch.

@Test
public void cannotDeleteUserBranch() throws Exception {
    projectOperations.project(allUsers).forUpdate().add(allow(Permission.DELETE).ref(RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}").group(REGISTERED_USERS).force(true)).update();
    TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
    String userRef = RefNames.refsUsers(admin.id());
    PushResult r = deleteRef(allUsersRepo, userRef);
    RemoteRefUpdate refUpdate = r.getRemoteUpdate(userRef);
    assertThat(refUpdate.getStatus()).isEqualTo(RemoteRefUpdate.Status.REJECTED_OTHER_REASON);
    assertThat(refUpdate.getMessage()).contains("Not allowed to delete user branch.");
    try (Repository repo = repoManager.openRepository(allUsers)) {
        assertThat(repo.exactRef(userRef)).isNotNull();
    }
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) PushResult(org.eclipse.jgit.transport.PushResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)82 PushResult (org.eclipse.jgit.transport.PushResult)59 Git (org.eclipse.jgit.api.Git)23 RefSpec (org.eclipse.jgit.transport.RefSpec)20 Test (org.junit.Test)19 File (java.io.File)18 IOException (java.io.IOException)17 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)15 URIish (org.eclipse.jgit.transport.URIish)15 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)15 CloneCommand (org.eclipse.jgit.api.CloneCommand)14 PushCommand (org.eclipse.jgit.api.PushCommand)13 ArrayList (java.util.ArrayList)12 BufferedWriter (java.io.BufferedWriter)11 FileOutputStream (java.io.FileOutputStream)11 OutputStreamWriter (java.io.OutputStreamWriter)11 Date (java.util.Date)11 Repository (org.eclipse.jgit.lib.Repository)11 RepositoryModel (com.gitblit.models.RepositoryModel)10 RevCommit (org.eclipse.jgit.revwalk.RevCommit)10