Class GitTool


  • public class GitTool
    extends java.lang.Object
    Git toolbox
    This class only provides static variables and methods
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String HEAD
      Head revision
      static java.lang.String MASTER
      Master branch name
      static java.lang.String ORIGIN
      Origin
      static java.lang.String POM_FOOTER
      POM file footer
      static java.lang.String POM_HEADER
      POM file header
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void addRemote​(java.io.File dir, java.lang.String name, java.lang.String uri)
      Add remote
      static void checkout​(ObjectDB mdl, java.lang.String commitId)
      Checkout commit ID in module's repository worktree
      static void checkout​(ObjectDB mdl, java.lang.String branch, boolean create, java.lang.String remoteBranch)
      Checkout a branch in module's repository worktree
      static void checkout​(java.io.File dir, java.lang.String commitId)
      Checkout a commit ID in the repository worktree.
      static void checkout​(java.io.File dir, java.lang.String branch, boolean create, java.lang.String remoteBranch)
      Checkout a branch in the repository worktree.
      static void clone​(java.io.File dir, java.lang.String uri, java.lang.String username, java.lang.String password, java.lang.String remote, java.lang.String branch)
      Clone an existing repository
      static java.lang.String commitModule​(ObjectDB mdl, java.lang.String msg)
      Deprecated.
      Use commitModule with addtional format parameter
      static java.lang.String commitModule​(ObjectDB mdl, java.lang.String format, java.lang.String msg)
      Commit selected module
      static org.eclipse.jgit.api.Git create​(java.io.File dir)
      Create a new repository
      static java.lang.String dumpCommit​(org.eclipse.jgit.lib.Repository rep, org.eclipse.jgit.lib.ObjectId commitId)
      Dump commit information
      static java.lang.String dumpModuleCommit​(ObjectDB mdl, org.eclipse.jgit.lib.ObjectId commitId)
      Dump module's commit for specified row ID
      static void fetch​(java.io.File dir, java.lang.String username, java.lang.String password, java.lang.String remote)
      Fetch from remote
      static org.json.JSONArray getAllCommits​(org.eclipse.jgit.lib.Repository rep, int n)
      Get last commits information
      static org.json.JSONArray getAllModuleCommits​(ObjectDB mdl, int n)
      Get modules's last commits information for module
      static java.util.List<java.lang.String> getBranchNames​(ObjectDB mdl, boolean local, boolean remote)
      Get branch names from an existing repository
      static java.util.List<java.lang.String> getBranchNames​(java.io.File dir, boolean local, boolean remote)
      Get branch names from an existing repository
      static java.util.List<java.lang.String> getBranchNames​(org.eclipse.jgit.api.Git git, boolean local, boolean remote)
      Get branch names from an existing repository
      static java.lang.String getCurrentBranchName​(ObjectDB mdl)
      Get current branch name from an existing repository
      static java.lang.String getCurrentBranchName​(java.io.File dir)
      Get current branch name from an existing repository
      static org.json.JSONArray getDiff​(org.eclipse.jgit.lib.Repository rep, org.eclipse.jgit.revwalk.RevCommit oldCommit, org.eclipse.jgit.revwalk.RevCommit newCommit)
      Get diff entries of 2 revisions
      static org.json.JSONArray getLastCommitDiff​(org.eclipse.jgit.lib.Repository rep)
      Get last commit's diff entries
      static java.util.List<java.lang.String> getLocalBranchNames​(ObjectDB mdl)
      Get local branch names from an existing repository
      static java.util.List<java.lang.String> getLocalBranchNames​(java.io.File dir)
      Get local branch names from an existing repository
      static java.util.List<java.lang.String> getLocalBranchNames​(org.eclipse.jgit.api.Git git)
      Get local branch names from an existing repository
      static java.io.InputStream getModuleZIP​(ObjectDB mdl)
      Get clean ZIP stream from a module
      static java.io.InputStream getModuleZIP​(java.io.File dir)
      Get clean ZIP stream from a checkout directory
      static java.io.InputStream getModuleZIP​(java.lang.String name)
      Get clean ZIP stream from a module name
      static java.lang.String getPrevCommitId​(ObjectDB mdl, java.lang.String commitId)
      Get previous module's commit ID for specified commit ID
      static java.lang.String getPrevCommitId​(org.eclipse.jgit.lib.Repository rep, java.lang.String commitId)
      Get previous commit ID for specified commit ID
      static java.lang.String getRawDiff​(ObjectDB mdl, java.lang.String commitId)
      Get raw diff for specified commit ID
      static java.lang.String getRawDiff​(org.eclipse.jgit.lib.Repository rep, java.lang.String commitId)
      Get raw diff for specified commit ID
      static java.lang.String getRawDiff​(org.eclipse.jgit.lib.Repository rep, org.eclipse.jgit.revwalk.RevCommit oldCommit, org.eclipse.jgit.revwalk.RevCommit newCommit)
      Get raw diff of 2 revisions
      static java.util.List<java.lang.String> getRemoteBranchNames​(ObjectDB mdl)
      Get remote branch names from an existing repository
      static java.util.List<java.lang.String> getRemoteBranchNames​(java.io.File dir)
      Get remote branch names from an existing repository
      static java.util.List<java.lang.String> getRemoteBranchNames​(org.eclipse.jgit.api.Git git)
      Get remote branch names from an existing repository
      static java.util.List<java.lang.String> getRemoteNames​(ObjectDB mdl)
      Get remote names from an existing repository
      static java.util.List<java.lang.String> getRemoteNames​(java.io.File dir)
      Get remote names from an existing repository
      static java.util.List<java.lang.String> getRemoteNames​(org.eclipse.jgit.api.Git git)
      Get remote names from an existing repository
      static java.io.File getRepositoryDir​(ObjectDB mdl)
      Get repository directory file for specified name
      static java.io.File getRepositoryDir​(java.lang.String name)
      Get repository directory file for specified name
      static java.util.List<java.lang.String> getTags​(ObjectDB mdl, java.lang.String commitId)
      Get all tags for a commit ID
      static java.util.List<java.lang.String> getTags​(java.io.File dir, java.lang.String commitId)
      Get all tags for a commit ID
      static Message importModule​(Grant g, java.io.File dir, org.json.JSONArray diffs)
      Import module from repository checkout
      static Message importModule​(ObjectDB mdl)
      Import module from repository checkout
      static java.lang.String lsremote​(java.lang.String uri, java.lang.String username, java.lang.String password)
      Get list of remote repository refs
      static boolean merge​(java.io.File dir, java.lang.String remote)
      Merge
      static java.lang.String projectPOM​(ObjectDB mdl)
      Generate a project-level POM file content for specified module and its child modules
      static boolean pull​(java.io.File dir, java.lang.String username, java.lang.String password, java.lang.String remote)
      Pull from remote
      static void push​(java.io.File dir, java.lang.String username, java.lang.String password, java.lang.String remote)
      Push to remote
      static void removeRemote​(java.io.File dir, java.lang.String name)
      Remove remote
      static boolean repositoryExists​(ObjectDB mdl)
      Check whether a repository exists for specified name
      static boolean repositoryExists​(java.lang.String name)
      Check whether a repository exists for specified name
      static void tag​(ObjectDB mdl, java.lang.String tag, java.lang.String commitId)
      Tag module's commit
      static void tag​(java.io.File dir, java.lang.String tag, java.lang.String commitId)
      Tag commit
      • Methods inherited from class java.lang.Object

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

      • getRepositoryDir

        public static java.io.File getRepositoryDir​(java.lang.String name)
        Get repository directory file for specified name
        Parameters:
        name - Repository name
        Returns:
        Repository directory file
      • getRepositoryDir

        public static java.io.File getRepositoryDir​(ObjectDB mdl)
        Get repository directory file for specified name
        Parameters:
        mdl - Module
        Returns:
        Repository directory file
      • repositoryExists

        public static boolean repositoryExists​(java.lang.String name)
        Check whether a repository exists for specified name
        Parameters:
        name - Repository name
        Returns:
        True if repository exists
      • repositoryExists

        public static boolean repositoryExists​(ObjectDB mdl)
        Check whether a repository exists for specified name
        Parameters:
        mdl - Module
        Returns:
        True if repository exists
      • lsremote

        public static java.lang.String lsremote​(java.lang.String uri,
                                                java.lang.String username,
                                                java.lang.String password)
                                         throws GitException
        Get list of remote repository refs
        Parameters:
        uri - Repository URI
        username - Optional username
        password - Optional password
        Returns:
        List of remote repository refs
        Throws:
        GitException
      • create

        public static org.eclipse.jgit.api.Git create​(java.io.File dir)
                                               throws GitException
        Create a new repository
        Parameters:
        dir - Directory
        Returns:
        Git
        Throws:
        GitException
      • clone

        public static void clone​(java.io.File dir,
                                 java.lang.String uri,
                                 java.lang.String username,
                                 java.lang.String password,
                                 java.lang.String remote,
                                 java.lang.String branch)
                          throws GitException
        Clone an existing repository
        Parameters:
        dir - Directory to clone to
        uri - Repository URI
        username - Optional username
        password - Optional password
        remote - Optional remote (defaults to "origin")
        branch - Optional branch (defaults to "master")
        Throws:
        GitException
      • getCurrentBranchName

        public static java.lang.String getCurrentBranchName​(java.io.File dir)
                                                     throws GitException
        Get current branch name from an existing repository
        Parameters:
        dir - Directory
        Returns:
        Current branch name
        Throws:
        GitException
      • getCurrentBranchName

        public static java.lang.String getCurrentBranchName​(ObjectDB mdl)
                                                     throws GitException
        Get current branch name from an existing repository
        Parameters:
        mdl - Module
        Returns:
        Current branch name
        Throws:
        GitException
      • getLocalBranchNames

        public static java.util.List<java.lang.String> getLocalBranchNames​(java.io.File dir)
                                                                    throws GitException
        Get local branch names from an existing repository
        Parameters:
        dir - Directory
        Returns:
        List of branch names ([branch name]])
        Throws:
        GitException
      • getRemoteBranchNames

        public static java.util.List<java.lang.String> getRemoteBranchNames​(java.io.File dir)
                                                                     throws GitException
        Get remote branch names from an existing repository
        Parameters:
        dir - Directory
        Returns:
        List of remote branch names ([remote name]/[branch name]])
        Throws:
        GitException
      • getBranchNames

        public static java.util.List<java.lang.String> getBranchNames​(java.io.File dir,
                                                                      boolean local,
                                                                      boolean remote)
                                                               throws GitException
        Get branch names from an existing repository
        Parameters:
        dir - Directory
        local - Local branches?
        remote - Remote branches?
        Returns:
        List of branch names ([branch name] for local branches, [remote name]/[branch name]] for remote branches names)
        Throws:
        GitException
      • getLocalBranchNames

        public static java.util.List<java.lang.String> getLocalBranchNames​(org.eclipse.jgit.api.Git git)
                                                                    throws GitException
        Get local branch names from an existing repository
        Parameters:
        git - Git
        Returns:
        List of branch names ([branch name]])
        Throws:
        GitException
      • getRemoteBranchNames

        public static java.util.List<java.lang.String> getRemoteBranchNames​(org.eclipse.jgit.api.Git git)
                                                                     throws GitException
        Get remote branch names from an existing repository
        Parameters:
        git - Git
        Returns:
        List of remote branch names ([remote name]/[branch name]])
        Throws:
        GitException
      • getBranchNames

        public static java.util.List<java.lang.String> getBranchNames​(org.eclipse.jgit.api.Git git,
                                                                      boolean local,
                                                                      boolean remote)
                                                               throws GitException
        Get branch names from an existing repository
        Parameters:
        git - Git
        local - Local branches?
        remote - Remote branches?
        Returns:
        List of branch names ([branch name] for local branches, [remote name]/[branch name]] for remote branches names)
        Throws:
        GitException
      • getLocalBranchNames

        public static java.util.List<java.lang.String> getLocalBranchNames​(ObjectDB mdl)
                                                                    throws GitException
        Get local branch names from an existing repository
        Parameters:
        mdl - Module
        Returns:
        List of branch names ([branch name]])
        Throws:
        GitException
      • getRemoteBranchNames

        public static java.util.List<java.lang.String> getRemoteBranchNames​(ObjectDB mdl)
                                                                     throws GitException
        Get remote branch names from an existing repository
        Parameters:
        mdl - Module
        Returns:
        List of remote branch names ([remote name]/[branch name]])
        Throws:
        GitException
      • getBranchNames

        public static java.util.List<java.lang.String> getBranchNames​(ObjectDB mdl,
                                                                      boolean local,
                                                                      boolean remote)
                                                               throws GitException
        Get branch names from an existing repository
        Parameters:
        mdl - Module
        local - Local branches?
        remote - Remote branches?
        Returns:
        List of branch names ([branch name] for local branches, [remote name]/[branch name]] for remote branches names)
        Throws:
        GitException
      • getRemoteNames

        public static java.util.List<java.lang.String> getRemoteNames​(java.io.File dir)
                                                               throws GitException
        Get remote names from an existing repository
        Parameters:
        dir - Directory
        Returns:
        List of remote names
        Throws:
        GitException
      • getRemoteNames

        public static java.util.List<java.lang.String> getRemoteNames​(ObjectDB mdl)
                                                               throws GitException
        Get remote names from an existing repository
        Parameters:
        mdl - Module
        Returns:
        List of remote names
        Throws:
        GitException
      • getRemoteNames

        public static java.util.List<java.lang.String> getRemoteNames​(org.eclipse.jgit.api.Git git)
                                                               throws GitException
        Get remote names from an existing repository
        Parameters:
        git - Git
        Returns:
        RLis of remote names
        Throws:
        GitException
      • addRemote

        public static void addRemote​(java.io.File dir,
                                     java.lang.String name,
                                     java.lang.String uri)
                              throws GitException
        Add remote
        Parameters:
        dir - Directory
        name - Remote name
        uri - URI
        Throws:
        GitException
      • removeRemote

        public static void removeRemote​(java.io.File dir,
                                        java.lang.String name)
                                 throws GitException
        Remove remote
        Parameters:
        dir - Directory
        name - Remote name
        Throws:
        GitException
      • pull

        public static boolean pull​(java.io.File dir,
                                   java.lang.String username,
                                   java.lang.String password,
                                   java.lang.String remote)
                            throws GitException
        Pull from remote
        Parameters:
        dir - Directory
        username - Optional username
        password - Optional password
        remote - Remote name (defaults to "origin")
        Returns:
        True if pull is successful
        Throws:
        GitException
      • fetch

        public static void fetch​(java.io.File dir,
                                 java.lang.String username,
                                 java.lang.String password,
                                 java.lang.String remote)
                          throws GitException
        Fetch from remote
        Parameters:
        dir - Directory
        username - Optional username
        password - Optional password
        remote - Remote name (defaults to "origin")
        Throws:
        GitException
      • merge

        public static boolean merge​(java.io.File dir,
                                    java.lang.String remote)
                             throws GitException
        Merge
        Parameters:
        dir - Directory
        Returns:
        True if merge is sucessful
        Throws:
        GitException
      • push

        public static void push​(java.io.File dir,
                                java.lang.String username,
                                java.lang.String password,
                                java.lang.String remote)
                         throws GitException
        Push to remote
        Parameters:
        dir - Directory
        username - Optional username
        password - Optional password
        remote - Remote name (defaults to "origin")
        Throws:
        GitException
      • checkout

        public static void checkout​(ObjectDB mdl,
                                    java.lang.String commitId)
                             throws GitException
        Checkout commit ID in module's repository worktree
        Parameters:
        mdl - Module
        commitId - Commit ID (defaults to "HEAD")
        Throws:
        GitException
      • checkout

        public static void checkout​(java.io.File dir,
                                    java.lang.String commitId)
                             throws GitException
        Checkout a commit ID in the repository worktree.
        Parameters:
        dir - Directory
        commitId - Commit ID (defaults to "HEAD")
        Throws:
        GitException
      • checkout

        public static void checkout​(ObjectDB mdl,
                                    java.lang.String branch,
                                    boolean create,
                                    java.lang.String remoteBranch)
                             throws GitException
        Checkout a branch in module's repository worktree
        Parameters:
        mdl - Module
        branch - Local branch name (defaults to "master")
        create - Create branch?
        remoteBranch - Name of a remote branch <remote name, e.g. origin>/<remote branch name> to track
        Throws:
        GitException
      • checkout

        public static void checkout​(java.io.File dir,
                                    java.lang.String branch,
                                    boolean create,
                                    java.lang.String remoteBranch)
                             throws GitException
        Checkout a branch in the repository worktree.
        Parameters:
        dir - Directory
        branch - Local branch name (defaults to "master")
        create - Create branch?
        remoteBranch - Name of a remote branch <remote name, e.g. origin>/<remote branch name> to track
        Throws:
        GitException
      • tag

        public static void tag​(ObjectDB mdl,
                               java.lang.String tag,
                               java.lang.String commitId)
                        throws GitException
        Tag module's commit
        Parameters:
        mdl - Module
        tag - Tag
        commitId - Commit ID (null means last commit)
        Throws:
        GitException
      • tag

        public static void tag​(java.io.File dir,
                               java.lang.String tag,
                               java.lang.String commitId)
                        throws GitException
        Tag commit
        Parameters:
        dir - Directory
        tag - Tag
        commitId - Commit ID (null means last commit)
        Throws:
        GitException
      • getTags

        public static java.util.List<java.lang.String> getTags​(ObjectDB mdl,
                                                               java.lang.String commitId)
                                                        throws GitException
        Get all tags for a commit ID
        Parameters:
        mdl - Module
        commitId - Commit ID (null means last commit)
        Returns:
        List of tags
        Throws:
        GitException
      • getTags

        public static java.util.List<java.lang.String> getTags​(java.io.File dir,
                                                               java.lang.String commitId)
                                                        throws GitException
        Get all tags for a commit ID
        Parameters:
        dir - Directory
        commitId - Commit ID (null means last commit)
        Returns:
        List of tags
        Throws:
        GitException
      • getPrevCommitId

        public static java.lang.String getPrevCommitId​(org.eclipse.jgit.lib.Repository rep,
                                                       java.lang.String commitId)
                                                throws GitException
        Get previous commit ID for specified commit ID
        Parameters:
        rep - Repository
        commitId - Commit ID
        Returns:
        Previous commit ID
        Throws:
        GitException
      • getPrevCommitId

        public static java.lang.String getPrevCommitId​(ObjectDB mdl,
                                                       java.lang.String commitId)
                                                throws GitException
        Get previous module's commit ID for specified commit ID
        Parameters:
        mdl - Module
        commitId - Commit ID
        Returns:
        Previous module's commit ID
        Throws:
        GitException
      • getDiff

        public static org.json.JSONArray getDiff​(org.eclipse.jgit.lib.Repository rep,
                                                 org.eclipse.jgit.revwalk.RevCommit oldCommit,
                                                 org.eclipse.jgit.revwalk.RevCommit newCommit)
                                          throws GitException
        Get diff entries of 2 revisions
        Parameters:
        rep - Repository
        oldCommit - Old commit
        newCommit - New commit
        Returns:
        Diff entries as JSON array
        Throws:
        GitException
      • getRawDiff

        public static java.lang.String getRawDiff​(org.eclipse.jgit.lib.Repository rep,
                                                  org.eclipse.jgit.revwalk.RevCommit oldCommit,
                                                  org.eclipse.jgit.revwalk.RevCommit newCommit)
                                           throws GitException
        Get raw diff of 2 revisions
        Parameters:
        rep - Repository
        oldCommit - Old commit
        newCommit - New commit
        Returns:
        Raw diff
        Throws:
        GitException
      • getRawDiff

        public static java.lang.String getRawDiff​(org.eclipse.jgit.lib.Repository rep,
                                                  java.lang.String commitId)
                                           throws GitException
        Get raw diff for specified commit ID
        Parameters:
        rep - Repository
        commitId - Commit ID
        Returns:
        Raw diff
        Throws:
        GitException
      • getRawDiff

        public static java.lang.String getRawDiff​(ObjectDB mdl,
                                                  java.lang.String commitId)
                                           throws GitException
        Get raw diff for specified commit ID
        Parameters:
        mdl - Module
        commitId - Commit ID
        Returns:
        Raw diff
        Throws:
        GitException
      • getLastCommitDiff

        public static org.json.JSONArray getLastCommitDiff​(org.eclipse.jgit.lib.Repository rep)
                                                    throws GitException
        Get last commit's diff entries
        Parameters:
        rep - Repository
        Returns:
        Last commit's diff entries as JSON array
        Throws:
        GitException
      • getAllCommits

        public static org.json.JSONArray getAllCommits​(org.eclipse.jgit.lib.Repository rep,
                                                       int n)
                                                throws GitException
        Get last commits information
        Parameters:
        rep - Repository
        n - Depth
        Returns:
        Last commits information as JSON array
        Throws:
        GitException
      • getAllModuleCommits

        public static org.json.JSONArray getAllModuleCommits​(ObjectDB mdl,
                                                             int n)
                                                      throws GitException
        Get modules's last commits information for module
        Parameters:
        mdl - Module
        n - Depth
        Returns:
        Modules's last commits information as JSON array
        Throws:
        GitException
      • dumpCommit

        public static java.lang.String dumpCommit​(org.eclipse.jgit.lib.Repository rep,
                                                  org.eclipse.jgit.lib.ObjectId commitId)
                                           throws GitException
        Dump commit information
        Parameters:
        rep - Repository
        commitId - Commit ID (null means last commit)
        Returns:
        Commit information as string
        Throws:
        GitException
      • dumpModuleCommit

        public static java.lang.String dumpModuleCommit​(ObjectDB mdl,
                                                        org.eclipse.jgit.lib.ObjectId commitId)
                                                 throws GitException
        Dump module's commit for specified row ID
        Parameters:
        mdl - Module
        commitId - Commit ID (null means last commit)
        Returns:
        Commit dump
        Throws:
        GitException
      • projectPOM

        public static java.lang.String projectPOM​(ObjectDB mdl)
                                           throws PlatformException
        Generate a project-level POM file content for specified module and its child modules
        Parameters:
        mdl - Module object
        Returns:
        POM file content
        Throws:
        PlatformException
      • commitModule

        @Deprecated
        public static java.lang.String commitModule​(ObjectDB mdl,
                                                    java.lang.String msg)
                                             throws PlatformException
        Deprecated.
        Use commitModule with addtional format parameter
        Throws:
        PlatformException
      • commitModule

        public static java.lang.String commitModule​(ObjectDB mdl,
                                                    java.lang.String format,
                                                    java.lang.String msg)
                                             throws PlatformException
        Commit selected module
        Parameters:
        mdl - Module object
        format - Format (one of Integration_FORMAT_*)
        msg - Message
        Returns:
        Commit ID
        Throws:
        PlatformException
      • getModuleZIP

        public static java.io.InputStream getModuleZIP​(ObjectDB mdl)
                                                throws GitException
        Get clean ZIP stream from a module
        Parameters:
        mdl - Module
        Returns:
        ZIP stream
        Throws:
        GitException
      • getModuleZIP

        public static java.io.InputStream getModuleZIP​(java.lang.String name)
                                                throws GitException
        Get clean ZIP stream from a module name
        Parameters:
        name - Module name
        Returns:
        ZIP stream
        Throws:
        GitException
      • getModuleZIP

        public static java.io.InputStream getModuleZIP​(java.io.File dir)
                                                throws GitException
        Get clean ZIP stream from a checkout directory
        Parameters:
        dir - Checkout directory
        Returns:
        ZIP stream
        Throws:
        GitException
      • importModule

        public static Message importModule​(Grant g,
                                           java.io.File dir,
                                           org.json.JSONArray diffs)
                                    throws PlatformException
        Import module from repository checkout
        Parameters:
        g - Grant
        dir - Repository directory
        Returns:
        Message
        Throws:
        PlatformException