Package org.eclipse.jgit.transport

Examples of org.eclipse.jgit.transport.RemoteRefUpdate


    git.add().addFilepattern(file.getName()).call();
    git.commit().setMessage("push test").call();
    Iterable<PushResult> results = git.push().setCredentialsProvider(cp).setRemote("origin").call();

    for (PushResult result : results) {
      RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/master");
      Status status = ref.getStatus();
      if (expectedSuccess) {
        assertTrue("Verification failed! User was NOT able to push commit! " + status.name(), Status.OK.equals(status));
      } else {
        assertTrue("Verification failed! User was able to push commit! " + status.name(), Status.REJECTED_OTHER_REASON.equals(status));
      }
View Full Code Here


    // push the merged master to the origin
    Iterable<PushResult> results = git.push().setCredentialsProvider(cp).setRemote("origin").call();

    for (PushResult result : results) {
      RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/master");
      Status status = ref.getStatus();
      if (expectedSuccess) {
        assertTrue("Verification failed! User was NOT able to push commit! " + status.name(), Status.OK.equals(status));
      } else {
        assertTrue("Verification failed! User was able to push commit! " + status.name(), Status.REJECTED_OTHER_REASON.equals(status));
      }
View Full Code Here

        return;
      }
    }

    for (PushResult result : results) {
      RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/master");
      Status status = ref.getStatus();
      if (permission.atLeast(AccessPermission.PUSH)) {
        assertTrue("User failed to push commit?! " + status.name(), Status.OK.equals(status));
      } else {
        // close serving repository
        GitBlitSuite.close(refChecks);

        assertTrue("User was able to push commit! " + status.name(), Status.REJECTED_OTHER_REASON.equals(status));
        GitBlitSuite.close(git);
        // skip delete test
        return;
      }
    }

    // create a local branch and push the new branch back to the origin
    git.branchCreate().setName("protectme").call();
    RefSpec refSpec = new RefSpec("refs/heads/protectme:refs/heads/protectme");
    results = git.push().setCredentialsProvider(cp).setRefSpecs(refSpec).setRemote("origin").call();
    for (PushResult result : results) {
      RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/protectme");
      Status status = ref.getStatus();
      if (Status.OK.equals(expectedCreate)) {
        assertTrue("User failed to push creation?! " + status.name(), status.equals(expectedCreate));
      } else {
        // close serving repository
        GitBlitSuite.close(refChecks);

        assertTrue("User was able to push ref creation! " + status.name(), status.equals(expectedCreate));
        GitBlitSuite.close(git);
        // skip delete test
        return;
      }
    }

    // delete the branch locally
    git.branchDelete().setBranchNames("protectme").call();

    // push a delete ref command
    refSpec = new RefSpec(":refs/heads/protectme");
    results = git.push().setCredentialsProvider(cp).setRefSpecs(refSpec).setRemote("origin").call();
    for (PushResult result : results) {
      RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/protectme");
      Status status = ref.getStatus();
      if (Status.OK.equals(expectedDelete)) {
        assertTrue("User failed to push ref deletion?! " + status.name(), status.equals(Status.OK));
      } else {
        // close serving repository
        GitBlitSuite.close(refChecks);

        assertTrue("User was able to push ref deletion?! " + status.name(), status.equals(expectedDelete));
        GitBlitSuite.close(git);
        // skip rewind test
        return;
      }
    }

    // rewind master by two commits
    git.reset().setRef("HEAD~2").setMode(ResetType.HARD).call();

    // commit a change on this detached HEAD
    file = new File(local, "REWINDCHK");
    os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET);
    w = new BufferedWriter(os);
    w.write("// " + new Date().toString() + "\n");
    w.close();
    git.add().addFilepattern(file.getName()).call();
    RevCommit commit = git.commit().setMessage("rewind master and new commit").call();

    // Reset master to our new commit now we our local branch tip is no longer
    // upstream of the remote branch tip.  It is an alternate tip of the branch.
    JGitUtils.setBranchRef(git.getRepository(), "refs/heads/master", commit.getName());

    // Try pushing our new tip to the origin.
    // This requires the server to "rewind" it's master branch and update it
    // to point to our alternate tip.  This leaves the original master tip
    // unreferenced.
    results = git.push().setCredentialsProvider(cp).setRemote("origin").setForce(true).call();
    for (PushResult result : results) {
      RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/master");
      Status status = ref.getStatus();
      if (Status.OK.equals(expectedRewind)) {
        assertTrue("User failed to rewind master?! " + status.name(), status.equals(expectedRewind));
      } else {
        assertTrue("User was able to rewind master?! " + status.name(), status.equals(expectedRewind));
      }
View Full Code Here

    // push to non-existent user repository
    try {
      Iterable<PushResult> results = git.push().setRemote("user").setPushAll().setCredentialsProvider(cp).call();

      for (PushResult result : results) {
        RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/master");
        Status status = ref.getStatus();
        assertTrue("User failed to create repository?! " + status.name(), Status.OK.equals(status));
      }

      assertTrue("User canAdmin:" + user.canAdmin + " canCreate:" + user.canCreate, user.canAdmin || user.canCreate);

      // confirm default personal repository permissions
      RepositoryModel model = repositories().getRepositoryModel(MessageFormat.format("~{0}/ticgit.git", user.username));
      assertEquals("Unexpected owner", user.username, ArrayUtils.toString(model.owners));
      assertEquals("Unexpected authorization control", AuthorizationControl.NAMED, model.authorizationControl);
      assertEquals("Unexpected access restriction", AccessRestrictionType.VIEW, model.accessRestriction);

    } catch (GitAPIException e) {
      assertTrue(e.getMessage(), e.getMessage().contains("git-receive-pack not found"));
      assertFalse("User canAdmin:" + user.canAdmin + " canCreate:" + user.canCreate, user.canAdmin || user.canCreate);
    }

    // push to non-existent project repository
    try {
      Iterable<PushResult> results = git.push().setRemote("project").setPushAll().setCredentialsProvider(cp).call();
      GitBlitSuite.close(git);

      for (PushResult result : results) {
        RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/master");
        Status status = ref.getStatus();
        assertTrue("User failed to create repository?! " + status.name(), Status.OK.equals(status));
      }

      assertTrue("User canAdmin:" + user.canAdmin, user.canAdmin);
View Full Code Here

      final String srcExpr = Q.name();
      final boolean forceUpdate = false;
      final String localName = null;
      final ObjectId oldId = null;

      RemoteRefUpdate update = new RemoteRefUpdate(src.getRepository(),
          srcExpr, dstName, forceUpdate, localName, oldId);
      result = t.push(NullProgressMonitor.INSTANCE, Collections
          .singleton(update));
    } finally {
      t.close();
View Full Code Here

      final String srcExpr = Q.name();
      final boolean forceUpdate = false;
      final String localName = null;
      final ObjectId oldId = null;

      RemoteRefUpdate update = new RemoteRefUpdate(src.getRepository(),
          srcExpr, dstName, forceUpdate, localName, oldId);
      result = t.push(NullProgressMonitor.INSTANCE,
          Collections.singleton(update), out);
    } finally {
      t.close();
View Full Code Here

      final String srcExpr = Q.name();
      final boolean forceUpdate = false;
      final String localName = null;
      final ObjectId oldId = null;

      RemoteRefUpdate update = new RemoteRefUpdate(src.getRepository(),
          srcExpr, dstName, forceUpdate, localName, oldId);
      try {
        t.push(NullProgressMonitor.INSTANCE, Collections
            .singleton(update));
        fail("push completed without throwing exception");
View Full Code Here

    final String dstName = master;
    final boolean forceUpdate = true;
    final String localName = null;
    final ObjectId oldId = null;

    RemoteRefUpdate u = new RemoteRefUpdate(db, srcExpr, dstName,
        forceUpdate, localName, oldId);
    return Collections.singleton(u);
  }
View Full Code Here

      final String srcExpr = Q.name();
      final boolean forceUpdate = false;
      final String localName = null;
      final ObjectId oldId = null;

      RemoteRefUpdate u = new RemoteRefUpdate(src.getRepository(),
          srcExpr, dstName, forceUpdate, localName, oldId);
      try {
        t.push(NullProgressMonitor.INSTANCE, Collections.singleton(u));
        fail("anonymous push incorrectly accepted without error");
      } catch (TransportException e) {
View Full Code Here

      final String srcExpr = Q.name();
      final boolean forceUpdate = false;
      final String localName = null;
      final ObjectId oldId = null;

      RemoteRefUpdate u = new RemoteRefUpdate(src.getRepository(),
          srcExpr, dstName, forceUpdate, localName, oldId);
      t.push(NullProgressMonitor.INSTANCE, Collections.singleton(u));
    } finally {
      t.close();
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.transport.RemoteRefUpdate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.