Search in sources :

Example 21 with RemoteRefUpdate

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

the class TicketReferenceTest method assertPushSuccess.

private void assertPushSuccess(String commitSha, String branchName) throws Exception {
    Iterable<PushResult> results = git.push().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 22 with RemoteRefUpdate

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

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

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

the class GitUtil method assertPushOk.

public static void assertPushOk(PushResult result, String ref) {
    RemoteRefUpdate rru = result.getRemoteUpdate(ref);
    assertThat(rru.getStatus()).named(rru.toString()).isEqualTo(RemoteRefUpdate.Status.OK);
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate)

Example 25 with RemoteRefUpdate

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

the class GitUtil method assertPushRejected.

public static void assertPushRejected(PushResult result, String ref, String expectedMessage) {
    RemoteRefUpdate rru = result.getRemoteUpdate(ref);
    assertThat(rru.getStatus()).named(rru.toString()).isEqualTo(RemoteRefUpdate.Status.REJECTED_OTHER_REASON);
    assertThat(rru.getMessage()).isEqualTo(expectedMessage);
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate)

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