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

The following examples show how to use org.eclipse.jgit.lib.RefUpdate.Result. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeleteTagCommand.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void run () throws GitException {
    Repository repository = getRepository();
    Ref currentRef = repository.getTags().get(tagName);
    if (currentRef == null) {
        throw new GitException.MissingObjectException(tagName, GitObjectType.TAG);
    }
    String fullName = currentRef.getName();
    try {
        RefUpdate update = repository.updateRef(fullName);
        update.setRefLogMessage("tag deleted", false);
        update.setForceUpdate(true);
        Result deleteResult = update.delete();

        switch (deleteResult) {
            case IO_FAILURE:
            case LOCK_FAILURE:
            case REJECTED:
                throw new GitException.RefUpdateException("Cannot delete tag " + tagName, GitRefUpdateResult.valueOf(deleteResult.name()));
        }
    } catch (IOException ex) {
        throw new GitException(ex);
    }
    
}
 
Example #2
Source File: GitRepository.java    From centraldogma with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
static void doRefUpdate(org.eclipse.jgit.lib.Repository jGitRepository, RevWalk revWalk,
                        String ref, ObjectId commitId) throws IOException {

    if (ref.startsWith(Constants.R_TAGS)) {
        final Ref oldRef = jGitRepository.exactRef(ref);
        if (oldRef != null) {
            throw new StorageException("tag ref exists already: " + ref);
        }
    }

    final RefUpdate refUpdate = jGitRepository.updateRef(ref);
    refUpdate.setNewObjectId(commitId);

    final Result res = refUpdate.update(revWalk);
    switch (res) {
        case NEW:
        case FAST_FORWARD:
            // Expected
            break;
        default:
            throw new StorageException("unexpected refUpdate state: " + res);
    }
}
 
Example #3
Source File: FetchJob.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
static IStatus handleFetchResult(FetchResult fetchResult) {
	// handle result
	for (TrackingRefUpdate updateRes : fetchResult.getTrackingRefUpdates()) {
		Result res = updateRes.getResult();
		switch (res) {
		case NOT_ATTEMPTED:
		case NO_CHANGE:
		case NEW:
		case FORCED:
		case FAST_FORWARD:
		case RENAMED:
			// do nothing, as these statuses are OK
			break;
		case REJECTED:
			return new Status(IStatus.WARNING, GitActivator.PI_GIT, "Fetch rejected, not a fast-forward.");
		case REJECTED_CURRENT_BRANCH:
			return new Status(IStatus.WARNING, GitActivator.PI_GIT, "Rejected because trying to delete the current branch.");
		default:
			return new Status(IStatus.ERROR, GitActivator.PI_GIT, res.name());
		}
	}
	return Status.OK_STATUS;
}
 
Example #4
Source File: GitNoteWriter.java    From git-appraise-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
private void updateRef() throws IOException, InterruptedException, RuntimeException,
                                MissingObjectException, IncorrectObjectTypeException,
                                CorruptObjectException {
  if (baseCommit != null && oursCommit.getTree().equals(baseCommit.getTree())) {
    // If the trees are identical, there is no change in the notes.
    // Avoid saving this commit as it has no new information.
    return;
  }

  int remainingLockFailureCalls = JgitUtils.MAX_LOCK_FAILURE_CALLS;
  RefUpdate refUpdate = JgitUtils.updateRef(repo, oursCommit, baseCommit, ref);

  for (;;) {
    Result result = refUpdate.update();

    if (result == Result.LOCK_FAILURE) {
      if (--remainingLockFailureCalls > 0) {
        Thread.sleep(JgitUtils.SLEEP_ON_LOCK_FAILURE_MS);
      } else {
        throw new RuntimeException("Failed to lock the ref: " + ref);
      }

    } else if (result == Result.REJECTED) {
      RevCommit theirsCommit = revWalk.parseCommit(refUpdate.getOldObjectId());
      NoteMap theirs = NoteMap.read(revWalk.getObjectReader(), theirsCommit);
      NoteMapMerger merger = new NoteMapMerger(repo);
      NoteMap merged = merger.merge(base, ours, theirs);
      RevCommit mergeCommit =
          createCommit(merged, author, "Merged note records\n", theirsCommit, oursCommit);
      refUpdate = JgitUtils.updateRef(repo, mergeCommit, theirsCommit, ref);
      remainingLockFailureCalls = JgitUtils.MAX_LOCK_FAILURE_CALLS;

    } else if (result == Result.IO_FAILURE) {
      throw new RuntimeException("Couldn't create notes because of IO_FAILURE");
    } else {
      break;
    }
  }
}