Package org.eclipse.jgit.lib.RefUpdate

Examples of org.eclipse.jgit.lib.RefUpdate.Result


        if (currentRef == null)
          continue;
        String fullName = currentRef.getName();
        RefUpdate update = repo.updateRef(fullName);
        update.setForceUpdate(true);
        Result deleteResult = update.delete();

        boolean ok = true;
        switch (deleteResult) {
        case IO_FAILURE:
        case LOCK_FAILURE:
        case REJECTED:
          ok = false;
          break;
        default:
          break;
        }

        if (ok) {
          result.add(fullName);
        } else
          throw new JGitInternalException(MessageFormat.format(
              JGitText.get().deleteTagUnexpectedResult,
              deleteResult.name()));
      }
      return result;
    } catch (IOException ioe) {
      throw new JGitInternalException(ioe.getMessage(), ioe);
    }
View Full Code Here


      }

      RefUpdate updateRef = repo.updateRef(Constants.R_HEADS + name);
      updateRef.setNewObjectId(startAt);
      updateRef.setRefLogMessage(refLogMessage, false);
      Result updateResult;
      if (exists && force)
        updateResult = updateRef.forceUpdate();
      else
        updateResult = updateRef.update();

      setCallable(false);

      boolean ok = false;
      switch (updateResult) {
      case NEW:
        ok = !exists;
        break;
      case NO_CHANGE:
      case FAST_FORWARD:
      case FORCED:
        ok = exists;
        break;
      default:
        break;
      }

      if (!ok)
        throw new JGitInternalException(MessageFormat.format(JGitText
            .get().createBranchUnexpectedResult, updateResult
            .name()));

      Ref result = repo.getRef(name);
      if (result == null)
        throw new JGitInternalException(
View Full Code Here

  public void testReadSymRefToLoosePacked() throws IOException {
    ObjectId pid = db.resolve("refs/heads/master^");
    RefUpdate updateRef = db.updateRef("refs/heads/master");
    updateRef.setNewObjectId(pid);
    updateRef.setForceUpdate(true);
    Result update = updateRef.update();
    assertEquals(Result.FORCED, update); // internal

    writeSymref("HEAD", "refs/heads/master");
    Ref ref = db.getRef("HEAD");
    assertEquals(Ref.Storage.LOOSE, ref.getStorage());
View Full Code Here

  @Test
  public void testReadLooseRef() throws IOException {
    RefUpdate updateRef = db.updateRef("ref/heads/new");
    updateRef.setNewObjectId(db.resolve("refs/heads/master"));
    Result update = updateRef.update();
    assertEquals(Result.NEW, update);
    Ref ref = db.getRef("ref/heads/new");
    assertEquals(Storage.LOOSE, ref.getStorage());
  }
View Full Code Here

    ObjectId pid = db.resolve("refs/heads/master^");
    assertEquals(Storage.PACKED, ref.getStorage());
    RefUpdate updateRef = db.updateRef("refs/heads/master");
    updateRef.setNewObjectId(pid);
    updateRef.setForceUpdate(true);
    Result update = updateRef.update();
    assertEquals(Result.FORCED, update);

    ref = db.getRef("refs/heads/master");
    assertEquals(Storage.LOOSE, ref.getStorage());
  }
View Full Code Here

      if (!Repository.isValidRefName(fullNewName))
        throw new InvalidRefNameException(MessageFormat.format(JGitText
            .get().branchNameInvalid, fullNewName));

      RefRename rename = repo.renameRef(fullOldName, fullNewName);
      Result renameResult = rename.rename();

      setCallable(false);

      if (Result.RENAMED != renameResult)
        throw new JGitInternalException(MessageFormat.format(JGitText
            .get().renameBranchUnexpectedResult, renameResult
            .name()));

      if (fullNewName.startsWith(Constants.R_HEADS)) {
        String shortOldName = fullOldName.substring(Constants.R_HEADS
            .length());
View Full Code Here

      String shortHeadRef = getShortBranchName(headRef);
      String refLogMessage = "checkout: moving from " + shortHeadRef; //$NON-NLS-1$
      ObjectId branch;
      if (orphan) {
        if (startPoint == null && startCommit == null) {
          Result r = repo.updateRef(Constants.HEAD).link(
              getBranchName());
          if (!EnumSet.of(Result.NEW, Result.FORCED).contains(r))
            throw new JGitInternalException(MessageFormat.format(
                JGitText.get().checkoutUnexpectedResult,
                r.name()));
          this.status = CheckoutResult.NOT_TRIED_RESULT;
          return repo.getRef(Constants.HEAD);
        }
        branch = getStartPointObjectId();
      } else {
        branch = repo.resolve(name);
        if (branch == null)
          throw new RefNotFoundException(MessageFormat.format(
              JGitText.get().refNotResolved, name));
      }

      RevWalk revWalk = new RevWalk(repo);
      AnyObjectId headId = headRef.getObjectId();
      RevCommit headCommit = headId == null ? null : revWalk
          .parseCommit(headId);
      RevCommit newCommit = revWalk.parseCommit(branch);
      RevTree headTree = headCommit == null ? null : headCommit.getTree();
      DirCacheCheckout dco;
      DirCache dc = repo.lockDirCache();
      try {
        dco = new DirCacheCheckout(repo, headTree, dc,
            newCommit.getTree());
        dco.setFailOnConflict(true);
        try {
          dco.checkout();
        } catch (org.eclipse.jgit.errors.CheckoutConflictException e) {
          status = new CheckoutResult(Status.CONFLICTS,
              dco.getConflicts());
          throw new CheckoutConflictException(dco.getConflicts(), e);
        }
      } finally {
        dc.unlock();
      }
      Ref ref = repo.getRef(name);
      if (ref != null && !ref.getName().startsWith(Constants.R_HEADS))
        ref = null;
      String toName = Repository.shortenRefName(name);
      RefUpdate refUpdate = repo.updateRef(Constants.HEAD, ref == null);
      refUpdate.setForceUpdate(force);
      refUpdate.setRefLogMessage(refLogMessage + " to " + toName, false); //$NON-NLS-1$
      Result updateResult;
      if (ref != null)
        updateResult = refUpdate.link(ref.getName());
      else if (orphan) {
        updateResult = refUpdate.link(getBranchName());
        ref = repo.getRef(Constants.HEAD);
      } else {
        refUpdate.setNewObjectId(newCommit);
        updateResult = refUpdate.forceUpdate();
      }

      setCallable(false);

      boolean ok = false;
      switch (updateResult) {
      case NEW:
        ok = true;
        break;
      case NO_CHANGE:
      case FAST_FORWARD:
      case FORCED:
        ok = true;
        break;
      default:
        break;
      }

      if (!ok)
        throw new JGitInternalException(MessageFormat.format(JGitText
            .get().checkoutUnexpectedResult, updateResult.name()));


      if (!dco.getToBeDeleted().isEmpty()) {
        status = new CheckoutResult(Status.NONDELETED,
            dco.getToBeDeleted());
View Full Code Here

    return update;
  }

  private void deleteRef(final Ref stashRef) {
    try {
      Result result = createRefUpdate(stashRef).delete();
      if (Result.FORCED != result)
        throw new JGitInternalException(MessageFormat.format(
            JGitText.get().stashDropDeleteRefFailed, result));
    } catch (IOException e) {
      throw new JGitInternalException(JGitText.get().stashDropFailed, e);
View Full Code Here

  private void updateRef(Ref stashRef, ObjectId newId) {
    try {
      RefUpdate update = createRefUpdate(stashRef);
      update.setNewObjectId(newId);
      Result result = update.update();
      switch (result) {
      case FORCED:
      case NEW:
      case NO_CHANGE:
        return;
View Full Code Here

    if (headName.startsWith(Constants.R_REFS)) {
      RefUpdate rup = repo.updateRef(headName);
      rup.setNewObjectId(aNewHead);
      rup.setRefLogMessage("rebase finished: " + headName + " onto " //$NON-NLS-1$ //$NON-NLS-2$
          + onto.getName(), false);
      Result res = rup.forceUpdate();
      switch (res) {
      case FAST_FORWARD:
      case FORCED:
      case NO_CHANGE:
        break;
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.lib.RefUpdate.Result

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.