Class GitUtils


  • public abstract class GitUtils
    extends org.craftercms.commons.git.utils.GitUtils
    Utility methods for Git operations.
    Author:
    avasquez
    • Method Detail

      • openRepository

        public static org.eclipse.jgit.api.Git openRepository​(File localRepositoryFolder)
                                                       throws IOException
        Opens the Git repository at the specified location.
        Parameters:
        localRepositoryFolder - the folder where the Git repository is
        Returns:
        the Git instance used to handle the repository
        Throws:
        IOException - if an error occurs
      • cloneRemoteRepository

        public static org.eclipse.jgit.api.Git cloneRemoteRepository​(String remoteName,
                                                                     String remoteUrl,
                                                                     String branch,
                                                                     org.craftercms.commons.git.auth.GitAuthenticationConfigurator authConfigurator,
                                                                     File localFolder,
                                                                     String bigFileThreshold,
                                                                     Integer compression,
                                                                     Boolean fileMode)
                                                              throws org.eclipse.jgit.api.errors.GitAPIException,
                                                                     IOException
        Clones a remote repository into a specific local folder.
        Parameters:
        remoteName - the name of the remote
        remoteUrl - the URL of the remote. This should be a legal Git URL.
        branch - the branch which should be cloned
        authConfigurator - the GitAuthenticationConfigurator class used to configure the authentication with the remote repository
        localFolder - the local folder into which the remote repository should be cloned
        bigFileThreshold - the value of the Git core.bigFileThreshold config property
        compression - the value of the Git core.compression config property
        fileMode - the value of the Git core.fileMode config property
        Returns:
        the Git instance used to handle the cloned repository
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException - if a Git related error occurs
        IOException - if an IO error occurs
      • pull

        public static org.eclipse.jgit.api.PullResult pull​(org.eclipse.jgit.api.Git git,
                                                           String remoteName,
                                                           String remoteUrl,
                                                           String branch,
                                                           org.eclipse.jgit.merge.MergeStrategy mergeStrategy,
                                                           org.craftercms.commons.git.auth.GitAuthenticationConfigurator authConfigurator)
                                                    throws org.eclipse.jgit.api.errors.GitAPIException,
                                                           URISyntaxException
        Execute a Git pull.
        Parameters:
        git - the Git instance used to handle the repository
        remoteName - the name of the remote where to pull from
        remoteUrl - the URL of the remote (remote will be set to the URL)
        branch - the branch to pull
        mergeStrategy - the merge strategy to use
        authConfigurator - the GitAuthenticationConfigurator class used to configure the authentication with the remote repository
        Returns:
        the result of the pull
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException - if a Git related error occurs
        URISyntaxException - if the remote URL is invalid
      • push

        public static Iterable<org.eclipse.jgit.transport.PushResult> push​(org.eclipse.jgit.api.Git git,
                                                                           String remote,
                                                                           boolean pushAll,
                                                                           String localBranch,
                                                                           String remoteBranch,
                                                                           org.craftercms.commons.git.auth.GitAuthenticationConfigurator authConfigurator,
                                                                           boolean force)
                                                                    throws org.eclipse.jgit.api.errors.GitAPIException
        Executes a git push.
        Parameters:
        git - the Git instance used to handle the repository
        remote - remote name or URL
        pushAll - if the push should push all local branches
        remoteBranch - the remote remoteBranch being pushed to
        authConfigurator - the GitAuthenticationConfigurator class used to configure the authentication with the remote repository
        force - sets the force preference for the push
        Returns:
        the result of the push
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException - if a Git related error occurs
      • cleanup

        public static void cleanup​(String repoPath)
                            throws org.eclipse.jgit.api.errors.GitAPIException,
                                   IOException
        Executes a git gc.
        Parameters:
        repoPath - full path of the repository
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException - if there is an error running the command
        IOException - if there is an error opening the repository
      • discardAllChanges

        public static void discardAllChanges​(org.eclipse.jgit.api.Git git)
                                      throws org.eclipse.jgit.api.errors.GitAPIException
        Executes a git reset to discard all uncommitted changes
        Parameters:
        git - the git repository
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException - if there is an error performing the reset