Search in sources :

Example 26 with PushResult

use of org.eclipse.jgit.transport.PushResult in project gitblit by gitblit.

the class TicketReferenceTest method assertForcePushSuccess.

private void assertForcePushSuccess(String commitSha, String branchName) throws Exception {
    Iterable<PushResult> results = git.push().setForce(true).setRemote("origin").setCredentialsProvider(cp).call();
    for (PushResult result : results) {
        RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/" + branchName);
        assertEquals(Status.OK, ref.getStatus());
        assertEquals(commitSha, ref.getNewObjectId().name());
    }
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) PushResult(org.eclipse.jgit.transport.PushResult)

Example 27 with PushResult

use of org.eclipse.jgit.transport.PushResult in project gitblit by gitblit.

the class TicketReferenceTest method configure.

@BeforeClass
public static void configure() throws Exception {
    File repositoryName = new File("TicketReferenceTest.git");
    ;
    GitBlitSuite.close(repositoryName);
    if (repositoryName.exists()) {
        FileUtils.delete(repositoryName, FileUtils.RECURSIVE | FileUtils.RETRY);
    }
    repo = new RepositoryModel("TicketReferenceTest.git", null, null, null);
    if (gitblit().hasRepository(repo.name)) {
        gitblit().deleteRepositoryModel(repo);
    }
    gitblit().updateRepositoryModel(repo.name, repo, true);
    user = new UserModel(account);
    user.displayName = account;
    user.emailAddress = account + "@example.com";
    user.password = password;
    cp = new UsernamePasswordCredentialsProvider(user.username, user.password);
    if (gitblit().getUserModel(user.username) != null) {
        gitblit().deleteUser(user.username);
    }
    repo.authorizationControl = AuthorizationControl.NAMED;
    repo.accessRestriction = AccessRestrictionType.PUSH;
    gitblit().updateRepositoryModel(repo.name, repo, false);
    // grant user push permission
    user.setRepositoryPermission(repo.name, AccessPermission.REWIND);
    gitblit().updateUserModel(user);
    ticketService = gitblit().getTicketService();
    assertTrue(ticketService.deleteAll(repo));
    GitBlitSuite.close(workingCopy);
    if (workingCopy.exists()) {
        FileUtils.delete(workingCopy, FileUtils.RECURSIVE | FileUtils.RETRY);
    }
    CloneCommand clone = Git.cloneRepository();
    clone.setURI(MessageFormat.format("{0}/{1}", url, repo.name));
    clone.setDirectory(workingCopy);
    clone.setBare(false);
    clone.setBranch("master");
    clone.setCredentialsProvider(cp);
    GitBlitSuite.close(clone.call());
    git = Git.open(workingCopy);
    git.getRepository().getConfig().setString("user", null, "name", user.displayName);
    git.getRepository().getConfig().setString("user", null, "email", user.emailAddress);
    git.getRepository().getConfig().save();
    final RevCommit revCommit1 = makeCommit("initial commit");
    final String initialSha = revCommit1.name();
    Iterable<PushResult> results = git.push().setPushAll().setCredentialsProvider(cp).call();
    GitBlitSuite.close(git);
    for (PushResult result : results) {
        for (RemoteRefUpdate update : result.getRemoteUpdates()) {
            assertEquals(Status.OK, update.getStatus());
            assertEquals(initialSha, update.getNewObjectId().name());
        }
    }
}
Also used : UserModel(com.gitblit.models.UserModel) CloneCommand(org.eclipse.jgit.api.CloneCommand) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) RepositoryModel(com.gitblit.models.RepositoryModel) PushResult(org.eclipse.jgit.transport.PushResult) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) BeforeClass(org.junit.BeforeClass)

Example 28 with PushResult

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

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

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

the class ChangeIT method changeNoParentToOneParent.

@Test
@TestProjectInput(createEmptyCommit = false)
public void changeNoParentToOneParent() throws Exception {
    // create initial commit with no parent and push it as change, so that patch
    // set 1 has no parent
    RevCommit c = testRepo.commit().message("Initial commit").insertChangeId().create();
    String id = GitUtil.getChangeId(testRepo, c).get();
    testRepo.reset(c);
    PushResult pr = pushHead(testRepo, "refs/for/master", false);
    assertPushOk(pr, "refs/for/master");
    ChangeInfo change = gApi.changes().id(id).get();
    assertThat(change.revisions.get(change.currentRevision).commit.parents).isEmpty();
    // create another initial commit with no parent and push it directly into
    // the remote repository
    c = testRepo.amend(c.getId()).message("Initial Empty Commit").create();
    testRepo.reset(c);
    pr = pushHead(testRepo, "refs/heads/master", false);
    assertPushOk(pr, "refs/heads/master");
    // create a successor commit and push it as second patch set to the change,
    // so that patch set 2 has 1 parent
    RevCommit c2 = testRepo.commit().message("Initial commit").parent(c).insertChangeId(id.substring(1)).create();
    testRepo.reset(c2);
    pr = pushHead(testRepo, "refs/for/master", false);
    assertPushOk(pr, "refs/for/master");
    change = gApi.changes().id(id).get();
    RevisionInfo rev = change.revisions.get(change.currentRevision);
    assertThat(rev.commit.parents).hasSize(1);
    assertThat(rev.commit.parents.get(0).commit).isEqualTo(c.name());
    // check that change kind is correctly detected as REWORK
    assertThat(rev.kind).isEqualTo(ChangeKind.REWORK);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) 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)

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