Class JGitUtils


  • public class JGitUtils
    extends Object
    JGit utility functions.
    Since:
    1.9
    Author:
    Mark Struberg, Dominik Bartholdi (imod)
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static List<ScmFile> addAllFiles​(org.eclipse.jgit.api.Git git, ScmFileSet fileSet)
      Adds all files in the given fileSet to the repository.
      static void closeRepo​(org.eclipse.jgit.api.Git git)
      Closes the repository wrapped by the passed git object
      static org.eclipse.jgit.transport.CredentialsProvider getCredentials​(GitScmProviderRepository repository)
      Creates a credentials provider from the information passed in the repository.
      static List<ScmFile> getFilesInCommit​(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.revwalk.RevCommit commit)
      get a list of all files in the given commit
      static org.eclipse.jgit.lib.ProgressMonitor getMonitor​(ScmLogger logger)
      Construct a logging ProgressMonitor for all JGit operations.
      static List<org.eclipse.jgit.revwalk.RevCommit> getRevCommits​(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.revwalk.RevSort[] sortings, String fromRev, String toRev, Date fromDate, Date toDate, int maxLines)
      Get a list of commits between two revisions.
      static ScmFileStatus getScmFileStatus​(org.eclipse.jgit.diff.DiffEntry.ChangeType changeType)
      Translate a FileStatus in the matching ScmFileStatus.
      static boolean hasCommits​(org.eclipse.jgit.lib.Repository repo)
      Does the Repository have any commits?
      static org.eclipse.jgit.api.Git openRepo​(File basedir)
      Opens a JGit repository in the current directory or a parent directory.
      static org.eclipse.jgit.transport.CredentialsProvider prepareSession​(ScmLogger logger, org.eclipse.jgit.api.Git git, GitScmProviderRepository repository)
      Prepares the in memory configuration of git to connect to the configured repository.
      static Iterable<org.eclipse.jgit.transport.PushResult> push​(ScmLogger logger, org.eclipse.jgit.api.Git git, GitScmProviderRepository repo, org.eclipse.jgit.transport.RefSpec refSpec)  
    • Method Detail

      • openRepo

        public static org.eclipse.jgit.api.Git openRepo​(File basedir)
                                                 throws IOException
        Opens a JGit repository in the current directory or a parent directory.
        Parameters:
        basedir - The directory to start with
        Throws:
        IOException - If the repository cannot be opened
      • closeRepo

        public static void closeRepo​(org.eclipse.jgit.api.Git git)
        Closes the repository wrapped by the passed git object
        Parameters:
        git -
      • getMonitor

        public static org.eclipse.jgit.lib.ProgressMonitor getMonitor​(ScmLogger logger)
        Construct a logging ProgressMonitor for all JGit operations.
        Parameters:
        logger -
        Returns:
        a ProgressMonitor for use
      • prepareSession

        public static org.eclipse.jgit.transport.CredentialsProvider prepareSession​(ScmLogger logger,
                                                                                    org.eclipse.jgit.api.Git git,
                                                                                    GitScmProviderRepository repository)
        Prepares the in memory configuration of git to connect to the configured repository. It configures the following settings in memory:
      • push url
      • fetch url
Parameters:
logger - used to log some details
git - the instance to configure (only in memory, not saved)
repository - the repo config to be used
Returns:
CredentialsProvider in case there are credentials informations configured in the repository.
Parameters:
repository - the config to get the details from
Returns:
null if there is not enough info to create a provider with