Java Code Examples for org.eclipse.jgit.lib.RefUpdate#Result

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: GitUtils.java    From onedev with MIT License 6 votes vote down vote up
public static void deleteRef(RefUpdate refUpdate) {
	try {
		refUpdate.setForceUpdate(true);
		RefUpdate.Result result = refUpdate.delete();
        if (result == RefUpdate.Result.LOCK_FAILURE
        		&& refUpdate.getExpectedOldObjectId() != null
        		&& !refUpdate.getExpectedOldObjectId().equals(refUpdate.getOldObjectId())) {
        	throw new ObsoleteCommitException(refUpdate.getOldObjectId());
        } else if (result != RefUpdate.Result.FAST_FORWARD && result != RefUpdate.Result.FORCED
        		&& result != RefUpdate.Result.NEW && result != RefUpdate.Result.NO_CHANGE) {
        	throw new RefUpdateException(result);
        } 
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example 2
Source File: GitPushEmbedded.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean push(@NotNull Repository repository, @NotNull ObjectId ReceiveId, @NotNull String branch, @NotNull User userInfo) throws SVNException, IOException {
  final RefUpdate refUpdate = repository.updateRef(branch);
  refUpdate.getOldObjectId();
  refUpdate.setNewObjectId(ReceiveId);
  runReceiveHook(repository, refUpdate, SVNErrorCode.REPOS_HOOK_FAILURE, "pre-receive", userInfo);
  runUpdateHook(repository, refUpdate, "update", userInfo);
  final RefUpdate.Result result = refUpdate.update();
  switch (result) {
    case REJECTED:
    case LOCK_FAILURE:
      return false;
    case NEW:
    case FAST_FORWARD:
      runReceiveHook(repository, refUpdate, SVNErrorCode.REPOS_POST_COMMIT_HOOK_FAILED, "post-receive", userInfo);
      return true;
    default:
      log.error("Unexpected push error: {}", result);
      throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_WRITE_ERROR, result.name()));
  }
}
 
Example 3
Source File: GitUtils.java    From onedev with MIT License 5 votes vote down vote up
public static void updateRef(RefUpdate refUpdate) {
	try {
		RefUpdate.Result result = refUpdate.forceUpdate();
        if (result == RefUpdate.Result.LOCK_FAILURE 
        		&& refUpdate.getExpectedOldObjectId() != null 
        		&& !refUpdate.getExpectedOldObjectId().equals(refUpdate.getOldObjectId())) {
        	throw new ObsoleteCommitException(refUpdate.getOldObjectId());
        } else if (result != RefUpdate.Result.FAST_FORWARD && result != RefUpdate.Result.FORCED
        		&& result != RefUpdate.Result.NEW && result != RefUpdate.Result.NO_CHANGE) {
        	throw new RefUpdateException(result);
        } 
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example 4
Source File: GitUtils.java    From onedev with MIT License 5 votes vote down vote up
public static void linkRef(RefUpdate refUpdate, String target) {
	try {
		RefUpdate.Result result = refUpdate.link(target);
		if (result != RefUpdate.Result.FORCED && result != RefUpdate.Result.NEW && result != RefUpdate.Result.NO_CHANGE)
			throw new RefUpdateException(result);
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example 5
Source File: RefUpdateValidator.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
public static void validate(RefUpdate.Result result) {
  switch(result) {
    case REJECTED_CURRENT_BRANCH:
      throw new RefUpdateRejectedCurrentBranchException(result.name());
    case REJECTED:
      throw new RefUpdateRejectedException(result.name());
    case LOCK_FAILURE:
      throw new RefUpdateLockFailureException(result.name());
    case IO_FAILURE:
      throw new RefUpdateIOFailureException(result.name());
  }
}
 
Example 6
Source File: RefUpdateValidator.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
public static void validate(RefUpdate.Result result) {
  switch(result) {
    case REJECTED_CURRENT_BRANCH:
      throw new RefUpdateRejectedCurrentBranchException(result.name());
    case REJECTED:
      throw new RefUpdateRejectedException(result.name());
    case LOCK_FAILURE:
      throw new RefUpdateLockFailureException(result.name());
    case IO_FAILURE:
      throw new RefUpdateIOFailureException(result.name());
  }
}
 
Example 7
Source File: GitTaskUtils.java    From ant-git-tasks with Apache License 2.0 5 votes vote down vote up
/**
 * Check references updates for any errors
 *
 * @param errorPrefix The error prefix for any error message
 * @param refUpdates A collection of tracking references updates
 */
public static void validateTrackingRefUpdates(String errorPrefix, Collection<TrackingRefUpdate> refUpdates) {
        for (TrackingRefUpdate refUpdate : refUpdates) {
                RefUpdate.Result result = refUpdate.getResult();

                if (result == RefUpdate.Result.IO_FAILURE ||
                    result == RefUpdate.Result.LOCK_FAILURE ||
                    result == RefUpdate.Result.REJECTED ||
                    result == RefUpdate.Result.REJECTED_CURRENT_BRANCH ) {
                        throw new BuildException(String.format("%s - Status '%s'", errorPrefix, result.name()));
                }
        }
}
 
Example 8
Source File: RefUpdateException.java    From onedev with MIT License 4 votes vote down vote up
public RefUpdateException(RefUpdate.Result result) {
	super(result.name());
	this.result = result;
}
 
Example 9
Source File: RefUpdateException.java    From onedev with MIT License 4 votes vote down vote up
public RefUpdate.Result getResult() {
	return result;
}
 
Example 10
Source File: GitEnumsStateTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testUpdateResult () {
    for (RefUpdate.Result result : RefUpdate.Result.values()) {
        assertNotNull(GitRefUpdateResult.valueOf(result.name()));
    }
}