Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.RefUpdate


          continue;
        Ref currentRef = repo.getRef(tagName);
        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:
View Full Code Here


        else
          refLogMessage = "branch: Created from tag "
              + startPointFullName;
      }

      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) {
View Full Code Here

        revWalk.parseHeaders(srcCommit);
        dco = new DirCacheCheckout(repo,
            repo.lockDirCache(), srcCommit.getTree());
        dco.setFailOnConflict(true);
        dco.checkout();
        RefUpdate refUpdate = repo
            .updateRef(head.getTarget().getName());
        refUpdate.setNewObjectId(objectId);
        refUpdate.setExpectedOldObjectId(null);
        refUpdate.setRefLogMessage("initial pull", false);
        if (refUpdate.update() != Result.NEW)
          throw new NoHeadException(
              JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
        setCallable(false);
        return new MergeResult(srcCommit, srcCommit, new ObjectId[] {
            null, srcCommit }, MergeStatus.FAST_FORWARD,
View Full Code Here

  }

  private void updateHead(StringBuilder refLogMessage, ObjectId newHeadId,
      ObjectId oldHeadID) throws IOException,
      ConcurrentRefUpdateException {
    RefUpdate refUpdate = repo.updateRef(Constants.HEAD);
    refUpdate.setNewObjectId(newHeadId);
    refUpdate.setRefLogMessage(refLogMessage.toString(), false);
    refUpdate.setExpectedOldObjectId(oldHeadID);
    Result rc = refUpdate.update();
    switch (rc) {
    case NEW:
    case FAST_FORWARD:
      return;
    case REJECTED:
    case LOCK_FAILURE:
      throw new ConcurrentRefUpdateException(
          JGitText.get().couldNotLockHEAD, refUpdate.getRef(), rc);
    default:
      throw new JGitInternalException(MessageFormat.format(
          JGitText.get().updatingRefFailed, Constants.HEAD,
          newHeadId.toString(), rc));
    }
View Full Code Here

        setCallable(false);
        return repo.getRef(Constants.HEAD);
      }

      // write the ref
      final RefUpdate ru = repo.updateRef(Constants.HEAD);
      ru.setNewObjectId(commitId);

      String refName = Repository.shortenRefName(ref);
      String message = refName + ": updating " + Constants.HEAD; //$NON-NLS-1$
      ru.setRefLogMessage(message, false);
      if (ru.forceUpdate() == RefUpdate.Result.LOCK_FAILURE)
        throw new JGitInternalException(MessageFormat.format(
            JGitText.get().cannotLock, ru.getName()));

      switch (mode) {
        case HARD:
          checkoutIndex(commit);
          break;
        case MIXED:
          resetIndex(commit);
          break;
        case SOFT: // do nothing, only the ref was changed
          break;
        case KEEP: // TODO
        case MERGE: // TODO
          throw new UnsupportedOperationException();

      }

      if (mode != ResetType.SOFT) {
        if (merging)
          resetMerge();
        else if (cherryPicking)
          resetCherryPick();
      }

      setCallable(false);
      r = ru.getRef();
    } catch (IOException e) {
      throw new JGitInternalException(
          JGitText.get().exceptionCaughtDuringExecutionOfResetCommand,
          e);
    }
View Full Code Here

    updating.endTask();
  }

  private void execute(final ReceiveCommand cmd) {
    try {
      final RefUpdate ru = db.updateRef(cmd.getRefName());
      ru.setRefLogIdent(getRefLogIdent());
      switch (cmd.getType()) {
      case DELETE:
        if (!ObjectId.zeroId().equals(cmd.getOldId())) {
          // We can only do a CAS style delete if the client
          // didn't bork its delete request by sending the
          // wrong zero id rather than the advertised one.
          //
          ru.setExpectedOldObjectId(cmd.getOldId());
        }
        ru.setForceUpdate(true);
        status(cmd, ru.delete(walk));
        break;

      case CREATE:
      case UPDATE:
      case UPDATE_NONFASTFORWARD:
        ru.setForceUpdate(isAllowNonFastForwards());
        ru.setExpectedOldObjectId(cmd.getOldId());
        ru.setNewObjectId(cmd.getNewId());
        ru.setRefLogMessage("push", true);
        status(cmd, ru.update(walk));
        break;
      }
    } catch (IOException err) {
      cmd.setResult(Result.REJECTED_OTHER_REASON, MessageFormat.format(
          JGitText.get().lockError, err.getMessage()));
View Full Code Here

    if (head == null || head.getObjectId() == null)
      return; // throw exception?

    if (head.getName().startsWith(Constants.R_HEADS)) {
      final RefUpdate newHead = clonedRepo.updateRef(Constants.HEAD);
      newHead.disableRefLog();
      newHead.link(head.getName());
      addMergeConfig(clonedRepo, head);
    }

    final RevCommit commit = parseCommit(clonedRepo, head);

    boolean detached = !head.getName().startsWith(Constants.R_HEADS);
    RefUpdate u = clonedRepo.updateRef(Constants.HEAD, detached);
    u.setNewObjectId(commit.getId());
    u.forceUpdate();

    if (!bare) {
      DirCache dc = clonedRepo.lockDirCache();
      DirCacheCheckout co = new DirCacheCheckout(clonedRepo, dc,
          commit.getTree());
View Full Code Here

          odi.flush();

          RevWalk revWalk = new RevWalk(repo);
          try {
            RevCommit revCommit = revWalk.parseCommit(commitId);
            RefUpdate ru = repo.updateRef(Constants.HEAD);
            ru.setNewObjectId(commitId);
            if (reflogComment != null) {
              ru.setRefLogMessage(reflogComment, false);
            } else {
              String prefix = amend ? "commit (amend): "
                  : "commit: ";
              ru.setRefLogMessage(
                  prefix + revCommit.getShortMessage(), false);
            }
            if (headId != null)
              ru.setExpectedOldObjectId(headId);
            else
              ru.setExpectedOldObjectId(ObjectId.zeroId());
            Result rc = ru.forceUpdate();
            switch (rc) {
            case NEW:
            case FORCED:
            case FAST_FORWARD: {
              setCallable(false);
              if (state == RepositoryState.MERGING_RESOLVED) {
                // Commit was successful. Now delete the files
                // used for merge commits
                repo.writeMergeCommitMsg(null);
                repo.writeMergeHeads(null);
              } else if (state == RepositoryState.CHERRY_PICKING_RESOLVED) {
                repo.writeMergeCommitMsg(null);
                repo.writeCherryPickHead(null);
              }
              return revCommit;
            }
            case REJECTED:
            case LOCK_FAILURE:
              throw new ConcurrentRefUpdateException(JGitText
                  .get().couldNotLockHEAD, ru.getRef(), rc);
            default:
              throw new JGitInternalException(MessageFormat
                  .format(JGitText.get().updatingRefFailed,
                      Constants.HEAD,
                      commitId.toString(), rc));
View Full Code Here

      }
      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);
      Result updateResult;
      if (ref != null)
        updateResult = refUpdate.link(ref.getName());
      else {
        refUpdate.setNewObjectId(newCommit);
        updateResult = refUpdate.forceUpdate();
      }

      setCallable(false);

      boolean ok = false;
View Full Code Here

          // as a detached HEAD
          DirCacheCheckout co = new DirCacheCheckout(submoduleRepo,
              submoduleRepo.lockDirCache(), commit.getTree());
          co.setFailOnConflict(true);
          co.checkout();
          RefUpdate refUpdate = submoduleRepo.updateRef(
              Constants.HEAD, true);
          refUpdate.setNewObjectId(commit);
          refUpdate.forceUpdate();
        }
        updated.add(generator.getPath());
      }
      return updated;
    } catch (IOException e) {
View Full Code Here

TOP

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

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.