Class Git


  • public class Git
    extends Object
    The entry point to the Git local and remote service. This is also the main entry point to retrieve Repository instances
    • Method Detail

      • instance

        public static Git instance()
        Returns an instance using default options.
        Returns:
        an instance using default options.
      • 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.
        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:
        NullPointerException - if any of the given objects is null
        IllegalArgumentException - if a given object is illegal for some reason, like referring to an illegal repository
        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.
        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:
        NullPointerException - if any of the given objects is null
        IllegalArgumentException - if a given object is illegal for some reason, like referring to an illegal repository
        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.
        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:
        NullPointerException - if any of the given objects is null
        IllegalArgumentException - if a given object is illegal for some reason, like referring to an illegal repository
        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.
        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:
        NullPointerException - if any of the given objects is null
        IllegalArgumentException - if a given object is illegal for some reason, like referring to an illegal repository
        GitException - in case the operation fails for some reason, including when authentication fails
      • getUser

        public String getUser()
        Returns the user name to be used when connecting to remote repositories.
        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.
        Returns:
        the password to be used when connecting to remote repositories. When 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.
        Parameters:
        directory - the directory where the repository is.
        Returns:
        the new repository object.
        Throws:
        NullPointerException - if the given object is null
        IllegalArgumentException - if the given object is illegal for some reason, like referring to an illegal repository
        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.
        Parameters:
        directory - the directory where the repository is.
        Returns:
        the new repository object.
        Throws:
        NullPointerException - if the given object is null
        IllegalArgumentException - if the given object is illegal for some reason, like referring to an illegal repository
        IOException - in case of any I/O issue accessing the repository
      • 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.
      • 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.