Class GitFileRepository

  • All Implemented Interfaces:
    GitRepository, java.lang.AutoCloseable

    public class GitFileRepository
    extends java.lang.Object
    implements GitRepository, java.lang.AutoCloseable
    • Constructor Summary

      Constructors 
      Constructor Description
      GitFileRepository​(java.io.File parentDirectory)  
      GitFileRepository​(java.lang.String repositoryName, java.io.File parentDirectory)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.eclipse.jgit.revwalk.RevCommit addSubmodule​(GitFileRepository submoduleRepo)  
      org.eclipse.jgit.lib.Ref checkout​(java.lang.String branchName)  
      void close()
      Clean up any held resources (called automatically when used as a @Rule)
      org.eclipse.jgit.revwalk.RevCommit commit​(java.lang.String message)
      Commits all changes in the working tree.
      org.eclipse.jgit.revwalk.RevCommit commit​(java.lang.String message, java.lang.String... paths)
      Commits changes to the given paths.
      org.eclipse.jgit.lib.Ref createAnnotatedTag​(java.lang.String tagName, java.lang.String message)  
      org.eclipse.jgit.lib.Ref createBranch​(java.lang.String branchName)  
      org.eclipse.jgit.lib.Ref createLightWeightTag​(java.lang.String tagName)  
      java.io.File file​(java.lang.Object... path)  
      org.eclipse.jgit.api.Git getGit()
      Returns the underlying Git object from JGit.
      org.eclipse.jgit.lib.Ref getHead()  
      java.lang.String getId()  
      java.lang.String getName()  
      java.util.List<java.net.URI> getRemotes()  
      java.net.URI getUrl()  
      java.io.File getWorkTree()  
      static GitFileRepository init​(java.io.File repositoryDirectory)
      Factory method for creating a GitRepository without using a JUnit @Rule.
      static GitFileRepository open​(java.io.File repositoryDirectory)
      Factory method for opening a GitRepository without using a JUnit @Rule.
      org.eclipse.jgit.revwalk.RevCommit updateSubmodulesToLatest()
      Updates any submodules in this repository to the latest in the submodule origin repository
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GitFileRepository

        public GitFileRepository​(java.lang.String repositoryName,
                                 java.io.File parentDirectory)
      • GitFileRepository

        public GitFileRepository​(java.io.File parentDirectory)
    • Method Detail

      • getGit

        public org.eclipse.jgit.api.Git getGit()
        Returns the underlying Git object from JGit. Please consider adding more convenience methods to this fixture over using "raw" Git APIs.
      • getName

        public java.lang.String getName()
      • init

        public static GitFileRepository init​(java.io.File repositoryDirectory)
                                      throws org.eclipse.jgit.api.errors.GitAPIException
        Factory method for creating a GitRepository without using a JUnit @Rule. Creates a repository in the given repositoryDirectory.
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException
      • open

        public static GitFileRepository open​(java.io.File repositoryDirectory)
                                      throws java.io.IOException
        Factory method for opening a GitRepository without using a JUnit @Rule. Open an existing repository in the given repositoryDirectory.
        Throws:
        java.io.IOException
      • close

        public void close()
        Clean up any held resources (called automatically when used as a @Rule)
        Specified by:
        close in interface java.lang.AutoCloseable
      • addSubmodule

        public org.eclipse.jgit.revwalk.RevCommit addSubmodule​(GitFileRepository submoduleRepo)
                                                        throws org.eclipse.jgit.api.errors.GitAPIException
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException
      • getRemotes

        public java.util.List<java.net.URI> getRemotes()
                                                throws org.eclipse.jgit.api.errors.GitAPIException,
                                                       java.net.URISyntaxException
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException
        java.net.URISyntaxException
      • updateSubmodulesToLatest

        public org.eclipse.jgit.revwalk.RevCommit updateSubmodulesToLatest()
                                                                    throws org.eclipse.jgit.api.errors.GitAPIException
        Updates any submodules in this repository to the latest in the submodule origin repository
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException
      • commit

        public org.eclipse.jgit.revwalk.RevCommit commit​(java.lang.String message,
                                                         java.lang.String... paths)
                                                  throws org.eclipse.jgit.api.errors.GitAPIException
        Commits changes to the given paths. The paths are passed as-is to the underlying JGit library.
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException
      • commit

        public org.eclipse.jgit.revwalk.RevCommit commit​(java.lang.String message)
                                                  throws org.eclipse.jgit.api.errors.GitAPIException
        Commits all changes in the working tree. This is approximately git commit -am "message"
        Specified by:
        commit in interface GitRepository
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException
      • createBranch

        public org.eclipse.jgit.lib.Ref createBranch​(java.lang.String branchName)
                                              throws org.eclipse.jgit.api.errors.GitAPIException
        Specified by:
        createBranch in interface GitRepository
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException
      • checkout

        public org.eclipse.jgit.lib.Ref checkout​(java.lang.String branchName)
                                          throws org.eclipse.jgit.api.errors.GitAPIException
        Specified by:
        checkout in interface GitRepository
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException
      • createLightWeightTag

        public org.eclipse.jgit.lib.Ref createLightWeightTag​(java.lang.String tagName)
                                                      throws org.eclipse.jgit.api.errors.GitAPIException
        Specified by:
        createLightWeightTag in interface GitRepository
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException
      • createAnnotatedTag

        public org.eclipse.jgit.lib.Ref createAnnotatedTag​(java.lang.String tagName,
                                                           java.lang.String message)
                                                    throws org.eclipse.jgit.api.errors.GitAPIException
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException
      • getHead

        public org.eclipse.jgit.lib.Ref getHead()
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • file

        public java.io.File file​(java.lang.Object... path)
        Specified by:
        file in interface GitRepository
      • getId

        public java.lang.String getId()