Java 类org.eclipse.jgit.api.DeleteBranchCommand 实例源码

项目:verigreen    文件:JGitOperator.java   
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);
     }
}
项目:easycukes    文件:GitHelper.java   
/**
 * 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
 * @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);
    }
}
项目:fabric8poc    文件:ProfileRegistry.java   
List<String> deleteBranch(Version version) {
    String branch = version.toString();
    try {
        DeleteBranchCommand deleteCmd = git.branchDelete().setBranchNames(branch).setForce(true);
        return deleteCmd.call();
    } catch (GitAPIException ex) {
        throw new IllegalStateException("Cannot checkout branch: " + version, ex);
    }
}
项目:appformer    文件:GitImpl.java   
public DeleteBranchCommand _branchDelete() {
    return git.branchDelete();
}
项目:pretested-integration-plugin    文件:EnvVarsIT.java   
private void createRepository() throws IOException, GitAPIException {
    File repo = new File(TestUtilsFactory.WORKDIR,"EnvVar - " + UUID.randomUUID().toString().substring(0, 6) + "/.git");
    if (repo.getAbsoluteFile().exists()) {
        FileUtils.deleteDirectory(repo.getParentFile());
    }

    FileRepositoryBuilder builder = new FileRepositoryBuilder();

    repository = builder.setGitDir(repo.getAbsoluteFile())
            .readEnvironment() // scan environment GIT_* variables
            .findGitDir() // scan up the file system tree
            .build();

    if (!repository.isBare() && repository.getBranch() == null) {
        repository.create();
    }

    Git git = new Git(repository);

    File readme = new File(repository.getDirectory().getParent().concat("/" + "readme"));
    FileUtils.writeStringToFile(readme, "commit 1\n");
    git.add().addFilepattern(readme.getName()).call();
    git.commit().setMessage("commit message 1").call();

    CreateBranchCommand createBranchCommand = git.branchCreate();
    createBranchCommand.setName(INTEGRATION_BRANCH);
    createBranchCommand.call();

    createBranchCommand = git.branchCreate();
    createBranchCommand.setName(READY_BRANCH);
    createBranchCommand.call();

    CheckoutCommand checkout = git.checkout();
    checkout.setName(READY_BRANCH);
    checkout.call();

    FileUtils.writeStringToFile(readme, "commit 2\n");
    git.add().addFilepattern(readme.getName()).call();
    git.commit().setMessage("commit message 2").call();

    checkout = git.checkout();
    checkout.setName(INTEGRATION_BRANCH);
    checkout.call();

    DeleteBranchCommand deleteBranchCommand = git.branchDelete();
    deleteBranchCommand.setBranchNames("master");
    deleteBranchCommand.call();

    REPOSITORY = repository.getDirectory().getAbsolutePath();
}