Search in sources :

Example 26 with RemoteRefUpdate

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

the class AccountIT method deleteUserBranchWithAccessDatabaseCapability.

@Test
@Sandboxed
public void deleteUserBranchWithAccessDatabaseCapability() throws Exception {
    allowGlobalCapabilities(REGISTERED_USERS, GlobalCapability.ACCESS_DATABASE);
    grant(allUsers, RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}", Permission.DELETE, true, REGISTERED_USERS);
    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();
    }
// TODO(ekempin): assert that account was deleted from cache and index
}
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) Sandboxed(com.google.gerrit.acceptance.Sandboxed)

Example 27 with RemoteRefUpdate

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

the class AccountIT method cannotDeleteUserBranch.

@Test
@Sandboxed
public void cannotDeleteUserBranch() throws Exception {
    grant(allUsers, RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}", Permission.DELETE, true, REGISTERED_USERS);
    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) Sandboxed(com.google.gerrit.acceptance.Sandboxed)

Example 28 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 29 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 += "/" + 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 30 with RemoteRefUpdate

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

Aggregations

RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)32 PushResult (org.eclipse.jgit.transport.PushResult)28 Test (org.junit.Test)15 File (java.io.File)13 CloneCommand (org.eclipse.jgit.api.CloneCommand)13 Git (org.eclipse.jgit.api.Git)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)9 RevCommit (org.eclipse.jgit.revwalk.RevCommit)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)6 RefSpec (org.eclipse.jgit.transport.RefSpec)6 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)5 UserModel (com.gitblit.models.UserModel)4 CredentialsProvider (org.eclipse.jgit.transport.CredentialsProvider)4 Status (org.eclipse.jgit.transport.RemoteRefUpdate.Status)4 PushCommand (org.eclipse.jgit.api.PushCommand)3