Class Git

    • Field Detail

      • REMOTES_OPTION_NAME

        public static final String REMOTES_OPTION_NAME
        The name of the option used to pass the list of supported remotes to this object instance. This is the value of the key inside the options passed to get a new instance of this class. If this option is not passed the service will not be able to perform some of its operations. Value: "REMOTES"
        See Also:
        Constant Field Values
      • USER_OPTION_NAME

        public static final String USER_OPTION_NAME
        The name of the option used to pass the user name to this object instance. This is the value of the key inside the options passed to get a new instance of this class. If this option is not passed the service will not be able to authenticate and perform any of the authentication protected operations. Value: "USER"
        See Also:
        Constant Field Values
      • PASSWORD_OPTION_NAME

        public static final String PASSWORD_OPTION_NAME
        The name of the option used to pass the password to this object instance. This is the value of the key inside the options passed to get a new instance of this class. If this option is not passed the service will not be able to authenticate and perform any of the authentication protected operations. Value: "PASSWORD"
        See Also:
        Constant Field Values
    • Method Detail

      • instance

        public static Git instance()
        Returns an instance using default options.
        Returns:
        an instance using default options.
      • instance

        public static Git instance​(Map<String,​String> options)
        Returns an instance using the given options.
        Parameters:
        options - the map of options for the requested service. It can't be null. Valid options are documented as constants on this class.
        Returns:
        an instance using the given options.
        Throws:
        NullPointerException - if the given options map is null
        IllegalArgumentException - if some entries in the given options map are missing or illegal for some reason
      • clone

        public Repository clone​(File directory,
                                URI uri)
                         throws GitException
        Returns a repository instance working in the given directory after cloning from the given URI. If the instance has some credentials set, those are used to perform the operation, otherwise anonymous access will be used.
        Specified by:
        clone in interface GitLocalService
        Parameters:
        directory - the directory where the repository has to be cloned. It is created if it doesn't exist.
        uri - the URI of the remote repository to clone.
        Returns:
        the new repository object.
        Throws:
        GitException - in case the operation fails for some reason, including when authentication fails
      • clone

        public Repository clone​(File directory,
                                URI uri,
                                String user,
                                String password)
                         throws GitException
        Returns a repository instance working in the given directory after cloning from the given URI.
        Specified by:
        clone in interface GitLocalService
        Parameters:
        directory - the directory where the repository has to be cloned. It is created if it doesn't exist.
        uri - the URI of the remote repository to clone.
        user - the user name to use when credentials are required. If this and password are both null then no credentials is used. When using single token authentication (i.e. OAuth or Personal Access Tokens) this value may be the token or something other than a token, depending on the remote provider.
        password - the password to use when credentials are required. If this and user are both null then no credentials is used. When using single token authentication (i.e. OAuth or Personal Access Tokens) this value may be the token or something other than a token, depending on the remote provider.
        Returns:
        the new repository object.
        Throws:
        GitException - in case the operation fails for some reason, including when authentication fails
      • clone

        public Repository clone​(String directory,
                                String uri)
                         throws GitException
        Returns a repository instance working in the given directory after cloning from the given URI. If the instance has some credentials set, those are used to perform the operation, otherwise anonymous access will be used.
        Specified by:
        clone in interface GitLocalService
        Parameters:
        directory - the directory where the repository has to be cloned. It is created if it doesn't exist.
        uri - the URI of the remote repository to clone.
        Returns:
        the new repository object.
        Throws:
        GitException - in case the operation fails for some reason, including when authentication fails
      • clone

        public Repository clone​(String directory,
                                String uri,
                                String user,
                                String password)
                         throws GitException
        Returns a repository instance working in the given directory after cloning from the given URI.
        Specified by:
        clone in interface GitLocalService
        Parameters:
        directory - the directory where the repository has to be cloned. It is created if it doesn't exist.
        uri - the URI of the remote repository to clone.
        user - the user name to use when credentials are required. If this and password are both null then no credentials is used. When using single token authentication (i.e. OAuth or Personal Access Tokens) this value may be the token or something other than a token, depending on the remote provider.
        password - the password to use when credentials are required. If this and user are both null then no credentials is used. When using single token authentication (i.e. OAuth or Personal Access Tokens) this value may be the token or something other than a token, depending on the remote provider.
        Returns:
        the new repository object.
        Throws:
        GitException - in case the operation fails for some reason, including when authentication fails
      • getSupportedRemoteNames

        public List<String> getSupportedRemoteNames()
        Returns the list of the remote repositories supported by this service. The names returned are simple names like those returned by a git remote command.
        The returned list is meant to be used as a filter so when it's null it means that any remote is supported.
        Specified by:
        getSupportedRemoteNames in interface GitRemoteService
        Returns:
        the list of the remote repositories supported by this service. When null or empty any remote is supported by this service.
      • getUser

        public String getUser()
        Returns the user name to be used when connecting to remote repositories.
        Specified by:
        getUser in interface GitRemoteService
        Returns:
        the user name to be used when connecting to remote repositories. When null the remote repositories are meant to allow anonymous access and, in this case, also the password is null.
      • getPassword

        public String getPassword()
        Returns the password to be used when connecting to remote repositories.
        Specified by:
        getPassword in interface GitRemoteService
        Returns:
        the password to be used when connecting to remote repositories. When GitRemoteService.getUser() returns null this method also returns null amd the remote repositories are meant to allow anonymous access.
      • open

        public Repository open​(File directory)
                        throws IOException
        Returns a repository instance working in the given directory.
        Specified by:
        open in interface GitLocalService
        Parameters:
        directory - the directory where the repository is.
        Returns:
        the new repository object.
        Throws:
        IOException - in case of any I/O issue accessing the repository
      • open

        public Repository open​(String directory)
                        throws IOException
        Returns a repository instance working in the given directory.
        Specified by:
        open in interface GitLocalService
        Parameters:
        directory - the directory where the repository is.
        Returns:
        the new repository object.
        Throws:
        IOException - in case of any I/O issue accessing the repository
      • setSupportedRemoteNames

        public void setSupportedRemoteNames​(List<String> remotes)
        Sets the list of the remote repositories supported by this service. The names returned are simple names like those returned by a git remote command.
        The given list is meant to be used as a filter so when it's null it means that any remote is supported.
        Parameters:
        remotes - the list of the remote repositories supported by this service. When null or empty any remote is supported by this service.
        Throws:
        UnsupportedOperationException - if the underlying implementation does not support the Service.Feature.GIT_REMOTE feature.
      • setUser

        public void setUser​(String user)
        Sets the user name to be used when connecting to remote repositories.
        Parameters:
        user - the user name to be used when connecting to remote repositories. When null the remote repositories are meant to allow anonymous access.
        Throws:
        UnsupportedOperationException - if the underlying implementation does not support the Service.Feature.GIT_REMOTE feature.
      • setPassword

        public void setPassword​(String password)
        Sets the password to be used when connecting to remote repositories.
        Parameters:
        password - the password to be used when connecting to remote repositories.
        Throws:
        UnsupportedOperationException - if the underlying implementation does not support the Service.Feature.GIT_REMOTE feature.
      • supports

        public boolean supports​(Service.Feature feature)
        Safely checks if the underlying implementation supports the given operation. If this method returns true then the underlying class will not raise any UnsupportedOperationException when invoking the specific methods.
        Specified by:
        supports in interface Service
        Parameters:
        feature - the feature to check for support.
        Returns:
        true if the operation is supported, false otherwise