void deleteBranch(String branchName) throws GitAPIException { try { git.branchDelete().setBranchNames(branchName).setForce(true).call(); } catch (GitAPIException e) { LOGGER.error("[CONFIG_MERGE] Failed to delete branch {}", branchName, e); throw e; } }
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(); logger.info(format("Deleted %s branches from %s branches to delete.", resultList, branchesToDelete)); return resultList; }
git.branchDelete() .setBranchNames("testbranch") .setForce(true) .call();
git.branchDelete() .setBranchNames("testbranch") .setForce(true) .call();
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); } }
private void deleteUnfilteredBranches(Repository repository) throws GitAPIException { final org.eclipse.jgit.api.Git git = org.eclipse.jgit.api.Git.wrap(repository); final String[] toDelete = git.branchList() .call() .stream() .map(ref -> ref.getName()) .map(fullname -> fullname.substring(fullname.lastIndexOf('/') + 1)) .filter(name -> !branches.contains(name)) .toArray(String[]::new); git.branchDelete() .setBranchNames(toDelete) .setForce(true) .call(); }
/** * Delete branch * @param git * @throws GitAPIException */ private void deleteTempBranch(Git git, String branchName) throws Exception { try { git.branchDelete() .setForce(true) .setBranchNames(branchName) .call(); } catch (GitAPIException e) { throw new Exception(DELETING_BRANCH_REASON, e); } }
public void deleteLocalBranch(String branchName) throws Exception { git.branchDelete().setForce(true).setBranchNames(branchName).call(); }
public static boolean removeBranch(Git git, String branch) throws GitAPIException { IllegalStateAssertion.assertFalse("master".equals(branch), "Cannot remove master branch"); if (localBranchExists(git, branch)) { String current = currentBranch(git); if (equals(current, branch)) { checkoutBranch(git, "master"); } List<String> list = git.branchDelete().setBranchNames(branch).setForce(true).call(); LOGGER.debug("Deleted branch {} with results: {}", branch, list); return true; } else { LOGGER.debug("Branch {} not found!", branch); return true; } }
private synchronized void deleteMMBranch(Git git) throws GitAPIException { List<Ref> refs = git.branchList().call(); for (Ref r : refs) { if (r.getName().endsWith(BRANCH_MM)) { git.branchDelete().setBranchNames(BRANCH_MM).setForce(true).call(); break; } } }
public static boolean removeBranch(Git git, String branch) throws GitAPIException { IllegalStateAssertion.assertFalse("master".equals(branch), "Cannot remove master branch"); if (localBranchExists(git, branch)) { String current = currentBranch(git); if (equals(current, branch)) { checkoutBranch(git, "master"); } List<String> list = git.branchDelete().setBranchNames(branch).setForce(true).call(); LOGGER.debug("Deleted branch {} with results: {}", branch, list); return true; } else { LOGGER.debug("Branch {} not found!", branch); return true; } }
public static void deleteBranch( final Git git, final Ref branch ) { try { git.branchDelete().setBranchNames( branch.getName() ).setForce( true ).call(); } catch ( final GitAPIException e ) { throw new IOException( e ); } }
public static void deleteBranch(final Git git, final Ref branch) { try { git.branchDelete().setBranchNames(branch.getName()).setForce(true).call(); } catch (final GitAPIException e) { throw new IOException(e); } }
public void execute() { try { git._branchDelete().setBranchNames(branch.getName()).setForce(true).call(); } catch (final GitAPIException e) { throw new IOException(e); } } }
public synchronized void reset() { try (Git git = openRepository()) { git.checkout().setName(mainBranchName).setForce(true).call(); git.branchDelete().setBranchNames(BRANCH_MM).setForce(true).call(); } catch (Exception e) { throw new RuntimeException(e); } }
/** {@inheritDoc} */ @Override public void deleteBranch(String name) throws GitException { try (Repository repo = getRepository()) { git(repo).branchDelete().setForce(true).setBranchNames(name).call(); } catch (GitAPIException e) { throw new GitException(e); } }
private void cleanupBranches(@NotNull Repository repository) throws IOException { final List<String> branches = new ArrayList<>(); for (Ref ref : repository.getRefDatabase().getRefsByPrefix(Constants.R_HEADS + TEST_BRANCH_PREFIX)) { branches.add(ref.getName().substring(Constants.R_HEADS.length())); } if (!branches.isEmpty()) { for (String branch : branches) { log.info("Cleanup branch: {}", branch); try { new Git(repository) .branchDelete() .setBranchNames(branch) .setForce(true) .call(); } catch (GitAPIException e) { log.error("Cleanup branch: " + branch, e); } } } }
@Override public void close() throws Exception { shutdown(0); if (safeBranch) { new Git(repository) .branchDelete() .setBranchNames(testBranch) .setForce(true) .call(); } for (SvnOperationFactory factory : svnFactories) { factory.dispose(); } svnFactories.clear(); repository.close(); TestHelper.deleteDirectory(tempDirectory); }
@Override public void switchToVersion(String version) throws Exception { try (Git git = new Git(repository)) { if (version == null) { version = REMOTE_BRANCH; // TODO fetch git.fetch().setRemote(REMOTE).call(); } Log.logDebug(LOGGER, "GIT switchToVersion {0} ", version); git.reset().setMode(ResetType.HARD).call(); git.checkout().setName(version).call(); git.branchDelete().setForce(true).setBranchNames(LOCAL_BRANCH).call(); git.checkout().setCreateBranch(true).setName(LOCAL_BRANCH).setStartPoint(version).call(); } catch (TransportException e) { throw new NetworkException(e); } }
protected void cleanupBranchesIfNeeded(String branchToCheckout, String... branchesToDelete) throws GitAPIException, JGitFlowGitAPIException { if (!keepBranch) { git.checkout().setName(branchToCheckout).call(); for (String branchToDelete : branchesToDelete) { if (GitHelper.localBranchExists(git, branchToDelete)) { reporter.infoText(getCommandName(), "deleting local branch: " + branchToDelete); git.branchDelete().setForce(forceDeleteBranch).setBranchNames(branchToDelete).call(); } if (isPush() && GitHelper.remoteBranchExists(git, branchToDelete)) { reporter.infoText(getCommandName(), "pushing deleted branch: :" + branchToDelete); RefSpec deleteSpec = new RefSpec().setSource(null).setDestination(Constants.R_HEADS + branchToDelete); git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(deleteSpec).call(); } } } }