Example usage for org.eclipse.jgit.api RemoteRemoveCommand call

List of usage examples for org.eclipse.jgit.api RemoteRemoveCommand call

Introduction

In this page you can find the example usage for org.eclipse.jgit.api RemoteRemoveCommand call.

Prototype

@Override
public RemoteConfig call() throws GitAPIException 

Source Link

Document

Executes the remote command with all the options and parameters collected by the setter methods of this class.

Usage

From source file:com.chungkwong.jgitgui.RemoteTreeItem.java

License:Open Source License

private void gitRemoteRemove() {
    try {/*from w w w .  j  a v  a 2 s . c  o  m*/
        RemoteRemoveCommand command = ((Git) getParent().getValue()).remoteRemove();
        command.setName(((RemoteConfig) getValue()).getName());
        command.call();
        getParent().getChildren().remove(this);
    } catch (Exception ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        Util.informUser(ex);
    }
}

From source file:com.mangosolutions.rcloud.rawgist.repository.git.ForkGistOperation.java

private void removeRemotes(Grgit git) throws GitAPIException {
    Git jgit = git.getRepository().getJgit();
    Collection<String> remotes = jgit.getRepository().getRemoteNames();
    for (String remote : remotes) {
        RemoteRemoveCommand remoteRemoveCommand = jgit.remoteRemove();
        remoteRemoveCommand.setName(remote);
        remoteRemoveCommand.call();
    }//from w  ww.  jav a 2s.c o  m
}

From source file:io.jenkins.blueocean.blueocean_git_pipeline.GitCacheCloneReadSaveRequest.java

License:Open Source License

private @Nonnull Git getActiveRepository(Repository repository) throws IOException {
    try {/*from   ww  w.  j a  va  2  s . c  o  m*/
        // Clone the bare repository
        File cloneDir = File.createTempFile("clone", "");

        if (cloneDir.exists()) {
            if (cloneDir.isDirectory()) {
                FileUtils.deleteDirectory(cloneDir);
            } else {
                if (!cloneDir.delete()) {
                    throw new ServiceException.UnexpectedErrorException("Unable to delete repository clone");
                }
            }
        }
        if (!cloneDir.mkdirs()) {
            throw new ServiceException.UnexpectedErrorException("Unable to create repository clone directory");
        }

        String url = repository.getConfig().getString("remote", "origin", "url");
        Git gitClient = Git.cloneRepository().setCloneAllBranches(false)
                .setProgressMonitor(new CloneProgressMonitor(url))
                .setURI(repository.getDirectory().getCanonicalPath()).setDirectory(cloneDir).call();

        RemoteRemoveCommand remove = gitClient.remoteRemove();
        remove.setName("origin");
        remove.call();

        RemoteAddCommand add = gitClient.remoteAdd();
        add.setName("origin");
        add.setUri(new URIish(gitSource.getRemote()));
        add.call();

        if (GitUtils.isSshUrl(gitSource.getRemote())) {
            // Get committer info and credentials
            User user = User.current();
            if (user == null) {
                throw new ServiceException.UnauthorizedException("Not authenticated");
            }
            BasicSSHUserPrivateKey privateKey = UserSSHKeyManager.getOrCreate(user);

            // Make sure up-to-date and credentials work
            GitUtils.fetch(repository, privateKey);
        } else {
            FetchCommand fetch = gitClient.fetch();
            fetch.call();
        }

        if (!StringUtils.isEmpty(sourceBranch) && !sourceBranch.equals(branch)) {
            CheckoutCommand checkout = gitClient.checkout();
            checkout.setStartPoint("origin/" + sourceBranch);
            checkout.setName(sourceBranch);
            checkout.setCreateBranch(true); // to create a new local branch
            checkout.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.NOTRACK);
            checkout.call();

            checkout = gitClient.checkout();
            checkout.setName(branch);
            checkout.setCreateBranch(true); // this *should* be a new branch
            checkout.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.NOTRACK);
            checkout.call();
        } else {
            CheckoutCommand checkout = gitClient.checkout();
            checkout.setStartPoint("origin/" + branch);
            checkout.setName(branch);
            checkout.setCreateBranch(true); // to create a new local branch
            checkout.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.NOTRACK);
            checkout.call();
        }

        return gitClient;
    } catch (GitAPIException | URISyntaxException ex) {
        throw new ServiceException.UnexpectedErrorException("Unable to get working repository directory", ex);
    }
}

From source file:org.uberfire.java.nio.fs.jgit.util.commands.SubdirectoryClone.java

License:Apache License

private void removeOriginRemote(Repository repository) throws GitAPIException {
    final org.eclipse.jgit.api.Git git = org.eclipse.jgit.api.Git.wrap(repository);
    final RemoteRemoveCommand cmd = git.remoteRemove();
    cmd.setName(origin);/*from w w w  .  j  a va 2  s .co  m*/
    cmd.call();
}