Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.RefUpdate


        monitor.beginTask(MessageFormat.format(
            JGitText.get().resettingHead, headName),
            ProgressMonitor.UNKNOWN);

        // update the HEAD
        RefUpdate refUpdate = repo.updateRef(Constants.HEAD, false);
        Result res = refUpdate.link(headName);
        switch (res) {
        case FAST_FORWARD:
        case FORCED:
        case NO_CHANGE:
          break;
View Full Code Here


      DirCacheCheckout dco = new DirCacheCheckout(repo, head.getTree(),
          repo.lockDirCache(), commit.getTree());
      dco.setFailOnConflict(true);
      dco.checkout();
      // update the HEAD
      RefUpdate refUpdate = repo.updateRef(Constants.HEAD, true);
      refUpdate.setExpectedOldObjectId(head);
      refUpdate.setNewObjectId(commit);
      Result res = refUpdate.forceUpdate();
      switch (res) {
      case FAST_FORWARD:
      case NO_CHANGE:
      case FORCED:
        break;
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);
            ru.setRefLogMessage("commit : "
                + revCommit.getShortMessage(), false);

            ru.setExpectedOldObjectId(headId);
            Result rc = ru.update();
            switch (rc) {
            case NEW:
            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);
              }
              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

          throw new CannotDeleteCurrentBranchException(
              MessageFormat
                  .format(
                      JGitText.get().cannotDeleteCheckedOutBranch,
                      branchName));
        RefUpdate update = repo.updateRef(fullName);
        update.setRefLogMessage("branch deleted", false);
        update.setForceUpdate(true);
        Result deleteResult = update.delete();

        boolean ok = true;
        switch (deleteResult) {
        case IO_FAILURE:
        case LOCK_FAILURE:
View Full Code Here

        RevWalk revWalk = new RevWalk(repo);
        try {
          RevTag revTag = revWalk.parseTag(tagId);
          String refName = Constants.R_TAGS + newTag.getTag();
          RefUpdate tagRef = repo.updateRef(refName);
          tagRef.setNewObjectId(tagId);
          tagRef.setForceUpdate(forceUpdate);
          tagRef.setRefLogMessage("tagged " + name, false);
          Result updateResult = tagRef.update(revWalk);
          switch (updateResult) {
          case NEW:
          case FORCED:
            return revTag;
          case LOCK_FAILURE:
            throw new ConcurrentRefUpdateException(
                JGitText.get().couldNotLockHEAD,
                tagRef.getRef(), updateResult);
          default:
            throw new JGitInternalException(MessageFormat.format(
                JGitText.get().updatingRefFailed, refName,
                newTag.toString(), updateResult));
          }
View Full Code Here

    }
  }

  protected void createBranch(ObjectId objectId, String branchName)
      throws IOException {
    RefUpdate updateRef = db.updateRef(branchName);
    updateRef.setNewObjectId(objectId);
    updateRef.update();
  }
View Full Code Here

        db.lockDirCache(), branch.getTree().getId());
    dco.setFailOnConflict(true);
    dco.checkout();
    walk.release();
    // update the HEAD
    RefUpdate refUpdate = db.updateRef(Constants.HEAD);
    refUpdate.setRefLogMessage("checkout: moving to " + branchName, false);
    refUpdate.link(branchName);
  }
View Full Code Here

    refs.create();
    objectDatabase.create();

    FileUtils.mkdir(new File(getDirectory(), "branches"));

    RefUpdate head = updateRef(Constants.HEAD);
    head.disableRefLog();
    head.link(Constants.R_HEADS + Constants.MASTER);

    final boolean fileMode;
    if (getFS().supportsExecute()) {
      File tmp = File.createTempFile("try", "execute", getDirectory());
View Full Code Here

        return Result.IO_FAILURE;

      // If HEAD has to be updated, link it now to destination.
      // We have to link before we delete, otherwise the delete
      // fails because its the current branch.
      RefUpdate dst = destination;
      if (updateHEAD) {
        if (!linkHEAD(destination)) {
          renameLog(tmp, source);
          return Result.LOCK_FAILURE;
        }

        // Replace the update operation so HEAD will log the rename.
        dst = refdb.newUpdate(Constants.HEAD, false);
        dst.setRefLogIdent(destination.getRefLogIdent());
        dst.setRefLogMessage(destination.getRefLogMessage(), false);
      }

      // Delete the source name so its path is free for replacement.
      source.setExpectedOldObjectId(objId);
      source.setForceUpdate(true);
      source.disableRefLog();
      if (source.delete(rw) != Result.FORCED) {
        renameLog(tmp, source);
        if (updateHEAD)
          linkHEAD(source);
        return source.getResult();
      }

      // Move the log to the destination.
      if (!renameLog(tmp, destination)) {
        renameLog(tmp, source);
        source.setExpectedOldObjectId(ObjectId.zeroId());
        source.setNewObjectId(objId);
        source.update(rw);
        if (updateHEAD)
          linkHEAD(source);
        return Result.IO_FAILURE;
      }

      // Create the destination, logging the rename during the creation.
      dst.setExpectedOldObjectId(ObjectId.zeroId());
      dst.setNewObjectId(objId);
      if (dst.update(rw) != Result.NEW) {
        // If we didn't create the destination we have to undo
        // our work. Put the log back and restore source.
        if (renameLog(destination, tmp))
          renameLog(tmp, source);
        source.setExpectedOldObjectId(ObjectId.zeroId());
        source.setNewObjectId(objId);
        source.update(rw);
        if (updateHEAD)
          linkHEAD(source);
        return dst.getResult();
      }

      return Result.RENAMED;
    } finally {
      // Always try to free the temporary name.
View Full Code Here

    return src.renameTo(dst);
  }

  private boolean linkHEAD(RefUpdate target) {
    try {
      RefUpdate u = refdb.newUpdate(Constants.HEAD, false);
      u.disableRefLog();
      switch (u.link(target.getName())) {
      case NEW:
      case FORCED:
      case NO_CHANGE:
        return true;
      default:
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.