Class GitUtils


  • public class GitUtils
    extends java.lang.Object
    The Class GitUtils.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEFAULT_RELEASE_BRANCH
      The Constant DEVELOP_BRANCH.
      static java.lang.String MASTER_BRANCH
      The Constant MASTER_BRANCH.
    • Constructor Summary

      Constructors 
      Constructor Description
      GitUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void checkoutRepoBranch​(org.eclipse.jgit.api.Git git, java.lang.String sBranchName, CommandResult commandResult)
      Checkout repo branch.
      static org.eclipse.jgit.api.Git cloneRepo​(java.lang.String sClonePath, java.lang.String sRepoURL, CommandResult commandResult, java.lang.String strGitHubUserLogin, java.lang.String strUserName, java.lang.String strPassword)
      Clone repo.
      static void createLocalBranch​(org.eclipse.jgit.api.Git git, java.lang.String sBranchName, CommandResult commandResult)
      Creates the local branch.
      static java.util.List<java.lang.String> getBranchList​(java.lang.String repoUrl, java.io.File localRepo, CommandResult commandResult, java.lang.String login, java.lang.String pwd)  
      static java.lang.String getFileContent​(java.lang.String strFullName, java.lang.String strPathFile, java.lang.String strBranch, java.lang.String strUserName, java.lang.String strPassword)
      Gets the file content.
      static org.eclipse.jgit.api.Git getGit​(java.lang.String strClonePath)
      Gets the git.
      static java.lang.String getLastCommitId​(org.eclipse.jgit.api.Git git)
      Gets the last commit id.
      static java.lang.String getLastLog​(org.eclipse.jgit.api.Git git, int nMaxCommit)
      Gets the last log.
      static java.lang.String getRefBranch​(org.eclipse.jgit.api.Git git, java.lang.String sBranchName, CommandResult commandResult)
      Gets the ref branch.
      static java.lang.String getRepoUrl​(java.lang.String strRepoUrl)
      Gets the repo url.
      static java.util.List<java.lang.String> getTagNameList​(org.eclipse.jgit.api.Git git)
      Gets the tag name list.
      static org.eclipse.jgit.api.MergeResult mergeBack​(org.eclipse.jgit.api.Git git, java.lang.String strUserName, java.lang.String strPassword, CommandResult commandResult)
      Merge back.
      static org.eclipse.jgit.api.MergeResult mergeRepoBranch​(org.eclipse.jgit.api.Git git, java.lang.String strBranchToMerge)
      Merge repo branch.
      static org.eclipse.jgit.api.PullResult pullRepoBranch​(org.eclipse.jgit.api.Git git, java.lang.String sBranchName, java.lang.String strUserName, java.lang.String strPassword)
      Pull repo branch.
      static void pushForce​(org.eclipse.jgit.api.Git git, java.lang.String strRefSpec, java.lang.String strUserName, java.lang.String strPassword)
      Push force.
      static GithubSearchResult searchRepo​(java.lang.String strSearch, java.lang.String strOrganization, java.lang.String strUserName, java.lang.String strPassword)
      Search repo.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MASTER_BRANCH

        public static final java.lang.String MASTER_BRANCH
        The Constant MASTER_BRANCH.
        See Also:
        Constant Field Values
      • DEFAULT_RELEASE_BRANCH

        public static final java.lang.String DEFAULT_RELEASE_BRANCH
        The Constant DEVELOP_BRANCH.
        See Also:
        Constant Field Values
    • Constructor Detail

      • GitUtils

        public GitUtils()
    • Method Detail

      • cloneRepo

        public static org.eclipse.jgit.api.Git cloneRepo​(java.lang.String sClonePath,
                                                         java.lang.String sRepoURL,
                                                         CommandResult commandResult,
                                                         java.lang.String strGitHubUserLogin,
                                                         java.lang.String strUserName,
                                                         java.lang.String strPassword)
        Clone repo.
        Parameters:
        sClonePath - the s clone path
        sRepoURL - the s repo URL
        commandResult - the command result
        strGitHubUserLogin - the str git hub user login
        strUserName - the str user name
        strPassword - the str password
        Returns:
        the git
      • checkoutRepoBranch

        public static void checkoutRepoBranch​(org.eclipse.jgit.api.Git git,
                                              java.lang.String sBranchName,
                                              CommandResult commandResult)
        Checkout repo branch.
        Parameters:
        git - the git
        sBranchName - the s branch name
        commandResult - the command result
      • createLocalBranch

        public static void createLocalBranch​(org.eclipse.jgit.api.Git git,
                                             java.lang.String sBranchName,
                                             CommandResult commandResult)
        Creates the local branch.
        Parameters:
        git - the git
        sBranchName - the s branch name
        commandResult - the command result
      • getRefBranch

        public static java.lang.String getRefBranch​(org.eclipse.jgit.api.Git git,
                                                    java.lang.String sBranchName,
                                                    CommandResult commandResult)
        Gets the ref branch.
        Parameters:
        git - the git
        sBranchName - the s branch name
        commandResult - the command result
        Returns:
        the ref branch
      • pushForce

        public static void pushForce​(org.eclipse.jgit.api.Git git,
                                     java.lang.String strRefSpec,
                                     java.lang.String strUserName,
                                     java.lang.String strPassword)
                              throws org.eclipse.jgit.api.errors.InvalidRemoteException,
                                     org.eclipse.jgit.api.errors.TransportException,
                                     org.eclipse.jgit.api.errors.GitAPIException
        Push force.
        Parameters:
        git - the git
        strRefSpec - the str ref spec
        strUserName - the str user name
        strPassword - the str password
        Throws:
        org.eclipse.jgit.api.errors.InvalidRemoteException - the invalid remote exception
        org.eclipse.jgit.api.errors.TransportException - the transport exception
        org.eclipse.jgit.api.errors.GitAPIException - the git API exception
      • pullRepoBranch

        public static org.eclipse.jgit.api.PullResult pullRepoBranch​(org.eclipse.jgit.api.Git git,
                                                                     java.lang.String sBranchName,
                                                                     java.lang.String strUserName,
                                                                     java.lang.String strPassword)
                                                              throws java.io.IOException,
                                                                     org.eclipse.jgit.api.errors.WrongRepositoryStateException,
                                                                     org.eclipse.jgit.api.errors.InvalidConfigurationException,
                                                                     org.eclipse.jgit.api.errors.DetachedHeadException,
                                                                     org.eclipse.jgit.api.errors.InvalidRemoteException,
                                                                     org.eclipse.jgit.api.errors.CanceledException,
                                                                     org.eclipse.jgit.api.errors.RefNotFoundException,
                                                                     org.eclipse.jgit.api.errors.NoHeadException,
                                                                     org.eclipse.jgit.api.errors.TransportException,
                                                                     org.eclipse.jgit.api.errors.GitAPIException
        Pull repo branch.
        Parameters:
        git - the git
        sBranchName - the s branch name
        strUserName - the str user name
        strPassword - the str password
        Returns:
        the pull result
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        org.eclipse.jgit.api.errors.WrongRepositoryStateException - the wrong repository state exception
        org.eclipse.jgit.api.errors.InvalidConfigurationException - the invalid configuration exception
        org.eclipse.jgit.api.errors.DetachedHeadException - the detached head exception
        org.eclipse.jgit.api.errors.InvalidRemoteException - the invalid remote exception
        org.eclipse.jgit.api.errors.CanceledException - the canceled exception
        org.eclipse.jgit.api.errors.RefNotFoundException - the ref not found exception
        org.eclipse.jgit.api.errors.NoHeadException - the no head exception
        org.eclipse.jgit.api.errors.TransportException - the transport exception
        org.eclipse.jgit.api.errors.GitAPIException - the git API exception
      • mergeRepoBranch

        public static org.eclipse.jgit.api.MergeResult mergeRepoBranch​(org.eclipse.jgit.api.Git git,
                                                                       java.lang.String strBranchToMerge)
                                                                throws java.io.IOException,
                                                                       org.eclipse.jgit.api.errors.WrongRepositoryStateException,
                                                                       org.eclipse.jgit.api.errors.InvalidConfigurationException,
                                                                       org.eclipse.jgit.api.errors.DetachedHeadException,
                                                                       org.eclipse.jgit.api.errors.InvalidRemoteException,
                                                                       org.eclipse.jgit.api.errors.CanceledException,
                                                                       org.eclipse.jgit.api.errors.RefNotFoundException,
                                                                       org.eclipse.jgit.api.errors.NoHeadException,
                                                                       org.eclipse.jgit.api.errors.TransportException,
                                                                       org.eclipse.jgit.api.errors.GitAPIException
        Merge repo branch.
        Parameters:
        git - the git
        strBranchToMerge - the str branch to merge
        Returns:
        the merge result
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        org.eclipse.jgit.api.errors.WrongRepositoryStateException - the wrong repository state exception
        org.eclipse.jgit.api.errors.InvalidConfigurationException - the invalid configuration exception
        org.eclipse.jgit.api.errors.DetachedHeadException - the detached head exception
        org.eclipse.jgit.api.errors.InvalidRemoteException - the invalid remote exception
        org.eclipse.jgit.api.errors.CanceledException - the canceled exception
        org.eclipse.jgit.api.errors.RefNotFoundException - the ref not found exception
        org.eclipse.jgit.api.errors.NoHeadException - the no head exception
        org.eclipse.jgit.api.errors.TransportException - the transport exception
        org.eclipse.jgit.api.errors.GitAPIException - the git API exception
      • getLastLog

        public static java.lang.String getLastLog​(org.eclipse.jgit.api.Git git,
                                                  int nMaxCommit)
                                           throws org.eclipse.jgit.api.errors.NoHeadException,
                                                  org.eclipse.jgit.api.errors.GitAPIException
        Gets the last log.
        Parameters:
        git - the git
        nMaxCommit - the n max commit
        Returns:
        the last log
        Throws:
        org.eclipse.jgit.api.errors.NoHeadException - the no head exception
        org.eclipse.jgit.api.errors.GitAPIException - the git API exception
      • getLastCommitId

        public static java.lang.String getLastCommitId​(org.eclipse.jgit.api.Git git)
                                                throws org.eclipse.jgit.api.errors.NoHeadException,
                                                       org.eclipse.jgit.api.errors.GitAPIException
        Gets the last commit id.
        Parameters:
        git - the git
        Returns:
        the last commit id
        Throws:
        org.eclipse.jgit.api.errors.NoHeadException - the no head exception
        org.eclipse.jgit.api.errors.GitAPIException - the git API exception
      • mergeBack

        public static org.eclipse.jgit.api.MergeResult mergeBack​(org.eclipse.jgit.api.Git git,
                                                                 java.lang.String strUserName,
                                                                 java.lang.String strPassword,
                                                                 CommandResult commandResult)
                                                          throws java.io.IOException,
                                                                 org.eclipse.jgit.api.errors.GitAPIException
        Merge back.
        Parameters:
        git - the git
        strUserName - the str user name
        strPassword - the str password
        commandResult - the command result
        Returns:
        the merge result
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        org.eclipse.jgit.api.errors.GitAPIException - the git API exception
      • searchRepo

        public static GithubSearchResult searchRepo​(java.lang.String strSearch,
                                                    java.lang.String strOrganization,
                                                    java.lang.String strUserName,
                                                    java.lang.String strPassword)
        Search repo.
        Parameters:
        strSearch - the str search
        strOrganization - the str organization
        strUserName - the str user name
        strPassword - the str password
        Returns:
        the github search result
      • getFileContent

        public static java.lang.String getFileContent​(java.lang.String strFullName,
                                                      java.lang.String strPathFile,
                                                      java.lang.String strBranch,
                                                      java.lang.String strUserName,
                                                      java.lang.String strPassword)
        Gets the file content.
        Parameters:
        strFullName - the str full name
        strPathFile - the str path file
        strBranch - the str branch
        strUserName - the str user name
        strPassword - the str password
        Returns:
        the file content
      • getTagNameList

        public static java.util.List<java.lang.String> getTagNameList​(org.eclipse.jgit.api.Git git)
        Gets the tag name list.
        Parameters:
        git - the git
        Returns:
        the tag name list
      • getRepoUrl

        public static java.lang.String getRepoUrl​(java.lang.String strRepoUrl)
        Gets the repo url.
        Parameters:
        strRepoUrl - the str repo url
        Returns:
        the repo url
      • getGit

        public static org.eclipse.jgit.api.Git getGit​(java.lang.String strClonePath)
        Gets the git.
        Parameters:
        strClonePath - the str clone path
        Returns:
        the git
      • getBranchList

        public static java.util.List<java.lang.String> getBranchList​(java.lang.String repoUrl,
                                                                     java.io.File localRepo,
                                                                     CommandResult commandResult,
                                                                     java.lang.String login,
                                                                     java.lang.String pwd)