/** * Switch to the main branch and delete the temporary branch. * * @throws GitAPIException * @throws RefAlreadyExistsException * @throws RefNotFoundException * @throws InvalidRefNameException * @throws CheckoutConflictException * @throws NotMergedException * @throws CannotDeleteCurrentBranchException */ private void switchToMainAndDeleteFrom(final String tempBranch) throws GitAPIException, RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException, CheckoutConflictException, NotMergedException, CannotDeleteCurrentBranchException { try { repository.reset().setMode(ResetType.HARD).call(); } finally { try { repository.checkout().setCreateBranch(false) .setName(mainBranchName).setForce(true).call(); } finally { try { repository.reset().setMode(ResetType.HARD).call(); } finally { repository.branchDelete().setForce(true) .setBranchNames(tempBranch).call(); } } } }
private void removeAllLocalBranches( final Git repository ) throws GitAPIException, NotMergedException, CannotDeleteCurrentBranchException { final String[] localBranches = repository.branchList() // .call().stream() // .filter( r -> r.getName() // .startsWith( "refs/heads/" ) ) // .map( r -> r.getName() ) // .toArray( String[]::new ); // repository.branchDelete() // .setForce( true ) // .setBranchNames( localBranches ) // .call(); // }