Example usage for org.eclipse.jgit.api DeleteBranchCommand setBranchNames

List of usage examples for org.eclipse.jgit.api DeleteBranchCommand setBranchNames

Introduction

In this page you can find the example usage for org.eclipse.jgit.api DeleteBranchCommand setBranchNames.

Prototype

public DeleteBranchCommand setBranchNames(String... branchnames) 

Source Link

Document

Set the names of the branches to delete

Usage

From source file:com.door43.translationstudio.tasks.PullTargetTranslationTask.java

private void createBackupBranch(Repo repo) {
    try {//from   w w  w. ja  v a2s . c o m
        Git git = repo.getGit();
        DeleteBranchCommand deleteBranchCommand = git.branchDelete();
        deleteBranchCommand.setBranchNames("backup-master").setForce(true).call();
        CreateBranchCommand createBranchCommand = git.branchCreate();
        createBranchCommand.setName("backup-master").setForce(true).call();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java

License:Open Source License

@Secured({ Role.User })
@Override//from  w  w  w.j a  v a  2  s  .  c  o m
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.verigreen.jgit.JGitOperator.java

License:Apache License

public void deleteBranch(boolean force, String... branchesToDelete) {
    DeleteBranchCommand branchDelete = _git.branchDelete();
    branchDelete.setForce(force);//from  ww w. j  ava  2s .c o  m
    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);
    }
}

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 .  java2s  . 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);/*  w w w . j a  v  a  2s.co 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/*from   w  w w . ja  va  2s . c  om*/
 *
 * {@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);
    }
}