org.eclipse.jgit.api.DeleteBranchCommand Java Examples

The following examples show how to use org.eclipse.jgit.api.DeleteBranchCommand. 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: GitBranchHandlerV1.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected boolean handleDelete(RequestInfo requestInfo) throws ServletException {
	String gitSegment = requestInfo.gitSegment;
	HttpServletRequest request = requestInfo.request;
	HttpServletResponse response = requestInfo.response;
	Git git = requestInfo.git;
	try {
		if (gitSegment != null) {
			DeleteBranchCommand cc = git.branchDelete();
			cc.setBranchNames(gitSegment);
			// TODO: the force flag should be passed in the API call
			cc.setForce(true);
			cc.call();

			// TODO: do something with the result
			return true;
		}
		return false;
	} catch (Exception e) {
		return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
				"An error occured when removing a branch.", e));
	}
}
 
Example #2
Source File: JGitOperator.java    From verigreen with Apache License 2.0 5 votes vote down vote up
public void deleteBranch(boolean force, String... branchesToDelete) {
	 DeleteBranchCommand branchDelete = _git.branchDelete();
	 branchDelete.setForce(force);
     try {
         List<String> call = branchDelete.setBranchNames(branchesToDelete).call();
         call.toString();
         for (String currBranch : branchesToDelete) {
             push(null, REFS_HEADS + currBranch);
         }
     } catch (Throwable e) {
         throw new RuntimeException(String.format(
                 "Failed to delete branches [%s]",
                 Arrays.toString(branchesToDelete)), e);
     }
}
 
Example #3
Source File: JGitEnvironmentRepository.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
private List<String> deleteBranches(Git git, Collection<String> branchesToDelete)
		throws GitAPIException {
	DeleteBranchCommand deleteBranchCommand = git.branchDelete()
			.setBranchNames(branchesToDelete.toArray(new String[0]))
			// local branch can contain data which is not merged to HEAD - force
			// delete it anyway, since local copy should be R/O
			.setForce(true);
	List<String> resultList = deleteBranchCommand.call();
	this.logger.info(format("Deleted %s branches from %s branches to delete.",
			resultList, branchesToDelete));
	return resultList;
}