RemoteListCommand.java

  1. /*
  2.  * Copyright (C) 2015, Kaloyan Raev <kaloyan.r@zend.com> and others
  3.  *
  4.  * This program and the accompanying materials are made available under the
  5.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  6.  * https://www.eclipse.org/org/documents/edl-v10.php.
  7.  *
  8.  * SPDX-License-Identifier: BSD-3-Clause
  9.  */
  10. package org.eclipse.jgit.api;

  11. import java.net.URISyntaxException;
  12. import java.util.List;

  13. import org.eclipse.jgit.api.errors.GitAPIException;
  14. import org.eclipse.jgit.api.errors.JGitInternalException;
  15. import org.eclipse.jgit.lib.Repository;
  16. import org.eclipse.jgit.transport.RemoteConfig;

  17. /**
  18.  * Used to obtain the list of remotes.
  19.  *
  20.  * This class has setters for all supported options and arguments of this
  21.  * command and a {@link #call()} method to finally execute the command.
  22.  *
  23.  * @see <a href=
  24.  *      "http://www.kernel.org/pub/software/scm/git/docs/git-remote.html" > Git
  25.  *      documentation about Remote</a>
  26.  * @since 4.2
  27.  */
  28. public class RemoteListCommand extends GitCommand<List<RemoteConfig>> {

  29.     /**
  30.      * <p>
  31.      * Constructor for RemoteListCommand.
  32.      * </p>
  33.      *
  34.      * @param repo
  35.      *            the {@link org.eclipse.jgit.lib.Repository}
  36.      */
  37.     protected RemoteListCommand(Repository repo) {
  38.         super(repo);
  39.     }

  40.     /**
  41.      * {@inheritDoc}
  42.      * <p>
  43.      * Executes the {@code remote} command with all the options and parameters
  44.      * collected by the setter methods of this class.
  45.      */
  46.     @Override
  47.     public List<RemoteConfig> call() throws GitAPIException {
  48.         checkCallable();

  49.         try {
  50.             return RemoteConfig.getAllRemoteConfigs(repo.getConfig());
  51.         } catch (URISyntaxException e) {
  52.             throw new JGitInternalException(e.getMessage(), e);
  53.         }
  54.     }

  55. }