Class RemoteConfig

  • All Implemented Interfaces:
    Serializable

    public class RemoteConfig
    extends Object
    implements Serializable
    A remembered remote repository, including URLs and RefSpecs.

    A remote configuration remembers one or more URLs for a frequently accessed remote repository as well as zero or more fetch and push specifications describing how refs should be transferred between this repository and the remote repository.

    See Also:
    Serialized Form
    • Constructor Detail

      • RemoteConfig

        public RemoteConfig​(Config rc,
                            String remoteName)
                     throws URISyntaxException
        Parse a remote block from an existing configuration file.

        This constructor succeeds even if the requested remote is not defined within the supplied configuration file. If that occurs then there will be no URIs and no ref specifications known to the new instance.

        Parameters:
        rc - the existing configuration to get the remote settings from. The configuration must already be loaded into memory.
        remoteName - subsection key indicating the name of this remote.
        Throws:
        URISyntaxException - one of the URIs within the remote's configuration is invalid.
    • Method Detail

      • getAllRemoteConfigs

        public static List<RemoteConfig> getAllRemoteConfigs​(Config rc)
                                                      throws URISyntaxException
        Parse all remote blocks in an existing configuration file, looking for remotes configuration.
        Parameters:
        rc - the existing configuration to get the remote settings from. The configuration must already be loaded into memory.
        Returns:
        all remotes configurations existing in provided repository configuration. Returned configurations are ordered lexicographically by names.
        Throws:
        URISyntaxException - one of the URIs within the remote's configuration is invalid.
      • update

        public void update​(Config rc)
        Update this remote's definition within the configuration.
        Parameters:
        rc - the configuration file to store ourselves into.
      • getName

        public String getName()
        Get the local name this remote configuration is recognized as.
        Returns:
        name assigned by the user to this configuration block.
      • getURIs

        public List<URIish> getURIs()
        Get all configured URIs under this remote.
        Returns:
        the set of URIs known to this remote.
      • addURI

        public boolean addURI​(URIish toAdd)
        Add a new URI to the end of the list of URIs.
        Parameters:
        toAdd - the new URI to add to this remote.
        Returns:
        true if the URI was added; false if it already exists.
      • removeURI

        public boolean removeURI​(URIish toRemove)
        Remove a URI from the list of URIs.
        Parameters:
        toRemove - the URI to remove from this remote.
        Returns:
        true if the URI was added; false if it already exists.
      • getPushURIs

        public List<URIish> getPushURIs()
        Get all configured push-only URIs under this remote.
        Returns:
        the set of URIs known to this remote.
      • addPushURI

        public boolean addPushURI​(URIish toAdd)
        Add a new push-only URI to the end of the list of URIs.
        Parameters:
        toAdd - the new URI to add to this remote.
        Returns:
        true if the URI was added; false if it already exists.
      • removePushURI

        public boolean removePushURI​(URIish toRemove)
        Remove a push-only URI from the list of URIs.
        Parameters:
        toRemove - the URI to remove from this remote.
        Returns:
        true if the URI was added; false if it already exists.
      • getFetchRefSpecs

        public List<RefSpec> getFetchRefSpecs()
        Remembered specifications for fetching from a repository.
        Returns:
        set of specs used by default when fetching.
      • addFetchRefSpec

        public boolean addFetchRefSpec​(RefSpec s)
        Add a new fetch RefSpec to this remote.
        Parameters:
        s - the new specification to add.
        Returns:
        true if the specification was added; false if it already exists.
      • setFetchRefSpecs

        public void setFetchRefSpecs​(List<RefSpec> specs)
        Override existing fetch specifications with new ones.
        Parameters:
        specs - list of fetch specifications to set. List is copied, it can be modified after this call.
      • setPushRefSpecs

        public void setPushRefSpecs​(List<RefSpec> specs)
        Override existing push specifications with new ones.
        Parameters:
        specs - list of push specifications to set. List is copied, it can be modified after this call.
      • removeFetchRefSpec

        public boolean removeFetchRefSpec​(RefSpec s)
        Remove a fetch RefSpec from this remote.
        Parameters:
        s - the specification to remove.
        Returns:
        true if the specification existed and was removed.
      • getPushRefSpecs

        public List<RefSpec> getPushRefSpecs()
        Remembered specifications for pushing to a repository.
        Returns:
        set of specs used by default when pushing.
      • addPushRefSpec

        public boolean addPushRefSpec​(RefSpec s)
        Add a new push RefSpec to this remote.
        Parameters:
        s - the new specification to add.
        Returns:
        true if the specification was added; false if it already exists.
      • removePushRefSpec

        public boolean removePushRefSpec​(RefSpec s)
        Remove a push RefSpec from this remote.
        Parameters:
        s - the specification to remove.
        Returns:
        true if the specification existed and was removed.
      • getUploadPack

        public String getUploadPack()
        Override for the location of 'git-upload-pack' on the remote system.

        This value is only useful for an SSH style connection, where Git is asking the remote system to execute a program that provides the necessary network protocol.

        Returns:
        location of 'git-upload-pack' on the remote system. If no location has been configured the default of 'git-upload-pack' is returned instead.
      • getReceivePack

        public String getReceivePack()
        Override for the location of 'git-receive-pack' on the remote system.

        This value is only useful for an SSH style connection, where Git is asking the remote system to execute a program that provides the necessary network protocol.

        Returns:
        location of 'git-receive-pack' on the remote system. If no location has been configured the default of 'git-receive-pack' is returned instead.
      • getTagOpt

        public TagOpt getTagOpt()
        Get the description of how annotated tags should be treated during fetch.
        Returns:
        option indicating the behavior of annotated tags in fetch.
      • setTagOpt

        public void setTagOpt​(TagOpt option)
        Set the description of how annotated tags should be treated on fetch.
        Parameters:
        option - method to use when handling annotated tags.
      • isMirror

        public boolean isMirror()
        Whether pushing to the remote automatically deletes remote refs which don't exist on the source side.
        Returns:
        true if pushing to the remote automatically deletes remote refs which don't exist on the source side.
      • setMirror

        public void setMirror​(boolean m)
        Set the mirror flag to automatically delete remote refs.
        Parameters:
        m - true to automatically delete remote refs during push.
      • getTimeout

        public int getTimeout()
        Get timeout (in seconds) before aborting an IO operation.
        Returns:
        timeout (in seconds) before aborting an IO operation.
      • setTimeout

        public void setTimeout​(int seconds)
        Set the timeout before willing to abort an IO call.
        Parameters:
        seconds - number of seconds to wait (with no data transfer occurring) before aborting an IO read or write operation with this remote. A timeout of 0 will block indefinitely.