List of usage examples for org.eclipse.jgit.api DeleteBranchCommand call
@Override public List<String> call() throws GitAPIException, NotMergedException, CannotDeleteCurrentBranchException
From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java
License:Open Source License
@Secured({ Role.User }) @Override//from www . j a v a2s . c om public void deleteBranch(String repoName, String branchName) throws EntityNotFoundException { try { Repository r = findRepositoryByName(repoName); Git git = Git.wrap(r); DeleteBranchCommand command = git.branchDelete(); command.setBranchNames(branchName); command.setForce(true); command.call(); r.close(); } catch (IOException e) { throw new RuntimeException(e); } catch (GitAPIException e) { throw new RuntimeException(e); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
From source file:com.worldline.easycukes.scm.utils.GitHelper.java
License:Open Source License
/** * Delete a branch in the local git repository * (git branch -d branchname) and finally pushes new branch on the remote repository (git push) * * @param directory the directory in which the local git repository is located * @param username the username to be used while pushing * @param password the password matching with the provided username to be used * for authentication/* w w w . j av a 2s. c om*/ * @param message the commit message to be used */ public static void deleteBranch(@NonNull File directory, String branchName, String username, String password, String message) { try { final Git git = Git.open(directory); final UsernamePasswordCredentialsProvider userCredential = new UsernamePasswordCredentialsProvider( username, password); DeleteBranchCommand deleteBranchCommand = git.branchDelete(); deleteBranchCommand.setBranchNames(branchName); deleteBranchCommand.call(); log.info("Develop branch deleted"); // and then commit final PersonIdent author = new PersonIdent(username, ""); git.commit().setCommitter(author).setMessage(message).setAuthor(author).call(); log.info(message); git.push().setCredentialsProvider(userCredential).call(); log.info("Pushed the changes in remote Git repository..."); } catch (final GitAPIException | IOException e) { log.error(e.getMessage(), e); } }
From source file:org.eclipse.orion.server.git.servlets.GitBranchHandlerV1.java
License:Open Source License
private boolean handleDelete(HttpServletRequest request, HttpServletResponse response, String path) throws IOException, JSONException, ServletException, URISyntaxException, CoreException, JGitInternalException, GitAPIException { // FIXME: what if there is a branch named "file"? Path p = new Path(path); if (p.segment(1).equals("file")) { //$NON-NLS-1$ // branch details: expected path /git/branch/{name}/file/{path} File gitDir = GitUtils.getGitDir(p.removeFirstSegments(1)); Repository db = new FileRepository(gitDir); Git git = new Git(db); DeleteBranchCommand cc = git.branchDelete(); cc.setBranchNames(p.segment(0)); // TODO: the force flag should be passed in the API call cc.setForce(true);/*from ww w .j a va2 s . c o m*/ cc.call(); // TODO: do something with the result, and handle any exceptions return true; } return false; }
From source file:org.mule.module.git.GitConnector.java
License:Open Source License
/** * Delete local branch//ww w . j a va 2 s . com * * {@sample.xml ../../../doc/mule-module-git.xml.sample git:delete-branch} * * @param branchName Name of the branch to delete * @param force If false a check will be performed whether the branch to be deleted is already merged into the current branch and deletion will be refused in this case * @param overrideDirectory Name of the directory to use for git repository */ @Processor public void deleteBranch(String branchName, boolean force, @Optional String overrideDirectory) { try { Git git = new Git(getGitRepo(overrideDirectory)); DeleteBranchCommand deleteBranch = git.branchDelete(); deleteBranch.setBranchNames(branchName); deleteBranch.setForce(force); deleteBranch.call(); } catch (Exception e) { throw new RuntimeException("Unable to create branch " + branchName, e); } }