Class BaseRepositoryBuilder<B extends BaseRepositoryBuilder,​R extends Repository>

    • Constructor Detail

      • BaseRepositoryBuilder

        public BaseRepositoryBuilder()
    • Method Detail

      • setFS

        public B setFS​(FS fs)
        Set the file system abstraction needed by this repository.
        Parameters:
        fs - the abstraction.
        Returns:
        this (for chaining calls).
      • getFS

        public FS getFS()
        Get the file system abstraction, or null if not set.
        Returns:
        the file system abstraction, or null if not set.
      • setGitDir

        public B setGitDir​(File gitDir)
        Set the Git directory storing the repository metadata.

        The meta directory stores the objects, references, and meta files like MERGE_HEAD, or the index file. If null the path is assumed to be workTree/.git.

        Parameters:
        gitDir - GIT_DIR, the repository meta directory.
        Returns:
        this (for chaining calls).
      • getGitDir

        public File getGitDir()
        Get the meta data directory; null if not set.
        Returns:
        the meta data directory; null if not set.
      • setObjectDirectory

        public B setObjectDirectory​(File objectDirectory)
        Set the directory storing the repository's objects.
        Parameters:
        objectDirectory - GIT_OBJECT_DIRECTORY, the directory where the repository's object files are stored.
        Returns:
        this (for chaining calls).
      • getObjectDirectory

        public File getObjectDirectory()
        Get the object directory; null if not set.
        Returns:
        the object directory; null if not set.
      • addAlternateObjectDirectory

        public B addAlternateObjectDirectory​(File other)
        Add an alternate object directory to the search list.

        This setting handles one alternate directory at a time, and is provided to support GIT_ALTERNATE_OBJECT_DIRECTORIES.

        Parameters:
        other - another objects directory to search after the standard one.
        Returns:
        this (for chaining calls).
      • addAlternateObjectDirectories

        public B addAlternateObjectDirectories​(Collection<File> inList)
        Add alternate object directories to the search list.

        This setting handles several alternate directories at once, and is provided to support GIT_ALTERNATE_OBJECT_DIRECTORIES.

        Parameters:
        inList - other object directories to search after the standard one. The collection's contents is copied to an internal list.
        Returns:
        this (for chaining calls).
      • addAlternateObjectDirectories

        public B addAlternateObjectDirectories​(File[] inList)
        Add alternate object directories to the search list.

        This setting handles several alternate directories at once, and is provided to support GIT_ALTERNATE_OBJECT_DIRECTORIES.

        Parameters:
        inList - other object directories to search after the standard one. The array's contents is copied to an internal list.
        Returns:
        this (for chaining calls).
      • getAlternateObjectDirectories

        public File[] getAlternateObjectDirectories()
        Get ordered array of alternate directories; null if non were set.
        Returns:
        ordered array of alternate directories; null if non were set.
      • setBare

        public B setBare()
        Force the repository to be treated as bare (have no working directory).

        If bare the working directory aspects of the repository won't be configured, and will not be accessible.

        Returns:
        this (for chaining calls).
      • isBare

        public boolean isBare()
        Whether this repository was forced bare by setBare().
        Returns:
        true if this repository was forced bare by setBare().
      • setMustExist

        public B setMustExist​(boolean mustExist)
        Require the repository to exist before it can be opened.
        Parameters:
        mustExist - true if it must exist; false if it can be missing and created after being built.
        Returns:
        this (for chaining calls).
      • isMustExist

        public boolean isMustExist()
        Whether the repository must exist before being opened.
        Returns:
        true if the repository must exist before being opened.
      • setWorkTree

        public B setWorkTree​(File workTree)
        Set the top level directory of the working files.
        Parameters:
        workTree - GIT_WORK_TREE, the working directory of the checkout.
        Returns:
        this (for chaining calls).
      • getWorkTree

        public File getWorkTree()
        Get the work tree directory, or null if not set.
        Returns:
        the work tree directory, or null if not set.
      • setIndexFile

        public B setIndexFile​(File indexFile)
        Set the local index file that is caching checked out file status.

        The location of the index file tracking the status information for each checked out file in workTree. This may be null to assume the default gitDiir/index.

        Parameters:
        indexFile - GIT_INDEX_FILE, the index file location.
        Returns:
        this (for chaining calls).
      • getIndexFile

        public File getIndexFile()
        Get the index file location, or null if not set.
        Returns:
        the index file location, or null if not set.
      • setInitialBranch

        public B setInitialBranch​(String branch)
                           throws InvalidRefNameException
        Set the initial branch of the new repository. If not specified (null or empty), fall back to the default name (currently master).
        Parameters:
        branch - initial branch name of the new repository. If null or empty the configured default branch will be used.
        Returns:
        this
        Throws:
        InvalidRefNameException - if the branch name is not valid
        Since:
        5.11
      • getInitialBranch

        @NonNull
        public String getInitialBranch()
        Get the initial branch of the new repository.
        Returns:
        the initial branch of the new repository.
        Since:
        5.11
      • readEnvironment

        public B readEnvironment()
        Read standard Git environment variables and configure from those.

        This method tries to read the standard Git environment variables, such as GIT_DIR and GIT_WORK_TREE to configure this builder instance. If an environment variable is set, it overrides the value already set in this builder.

        Returns:
        this (for chaining calls).
      • readEnvironment

        public B readEnvironment​(SystemReader sr)
        Read standard Git environment variables and configure from those.

        This method tries to read the standard Git environment variables, such as GIT_DIR and GIT_WORK_TREE to configure this builder instance. If a property is already set in the builder, the environment variable is not used.

        Parameters:
        sr - the SystemReader abstraction to access the environment.
        Returns:
        this (for chaining calls).
      • addCeilingDirectory

        public B addCeilingDirectory​(File root)
        Add a ceiling directory to the search limit list.

        This setting handles one ceiling directory at a time, and is provided to support GIT_CEILING_DIRECTORIES.

        Parameters:
        root - a path to stop searching at; its parent will not be searched.
        Returns:
        this (for chaining calls).
      • addCeilingDirectories

        public B addCeilingDirectories​(Collection<File> inList)
        Add ceiling directories to the search list.

        This setting handles several ceiling directories at once, and is provided to support GIT_CEILING_DIRECTORIES.

        Parameters:
        inList - directory paths to stop searching at. The collection's contents is copied to an internal list.
        Returns:
        this (for chaining calls).
      • addCeilingDirectories

        public B addCeilingDirectories​(File[] inList)
        Add ceiling directories to the search list.

        This setting handles several ceiling directories at once, and is provided to support GIT_CEILING_DIRECTORIES.

        Parameters:
        inList - directory paths to stop searching at. The array's contents is copied to an internal list.
        Returns:
        this (for chaining calls).
      • findGitDir

        public B findGitDir()
        Configure GIT_DIR by searching up the file system.

        Starts from the current working directory of the JVM and scans up through the directory tree until a Git repository is found. Success can be determined by checking for getGitDir() != null.

        The search can be limited to specific spaces of the local filesystem by addCeilingDirectory(File), or inheriting the list through a prior call to readEnvironment().

        Returns:
        this (for chaining calls).
      • findGitDir

        public B findGitDir​(File current)
        Configure GIT_DIR by searching up the file system.

        Starts from the supplied directory path and scans up through the parent directory tree until a Git repository is found. Success can be determined by checking for getGitDir() != null.

        The search can be limited to specific spaces of the local filesystem by addCeilingDirectory(File), or inheriting the list through a prior call to readEnvironment().

        Parameters:
        current - directory to begin searching in.
        Returns:
        this (for chaining calls).
      • setup

        public B setup()
                throws IllegalArgumentException,
                       IOException
        Guess and populate all parameters not already defined.

        If an option was not set, the setup method will try to default the option based on other options. If insufficient information is available, an exception is thrown to the caller.

        Returns:
        this
        Throws:
        IllegalArgumentException - insufficient parameters were set, or some parameters are incompatible with one another.
        IOException - the repository could not be accessed to configure the rest of the builder's parameters.
      • build

        public R build()
                throws IOException
        Create a repository matching the configuration in this builder.

        If an option was not set, the build method will try to default the option based on other options. If insufficient information is available, an exception is thrown to the caller.

        Returns:
        a repository matching this configuration. The caller is responsible to close the repository instance when it is no longer needed.
        Throws:
        IllegalArgumentException - insufficient parameters were set.
        IOException - the repository could not be accessed to configure the rest of the builder's parameters.
      • requireGitDirOrWorkTree

        protected void requireGitDirOrWorkTree()
        Require either gitDir or workTree to be set.
      • setupGitDir

        protected void setupGitDir()
                            throws IOException
        Perform standard gitDir initialization.
        Throws:
        IOException - the repository could not be accessed
      • setupWorkTree

        protected void setupWorkTree()
                              throws IOException
        Perform standard work-tree initialization.

        This is a method typically invoked inside of setup(), near the end after the repository has been identified and its configuration is available for inspection.

        Throws:
        IOException - the repository configuration could not be read.
      • setupInternals

        protected void setupInternals()
                               throws IOException
        Configure the internal implementation details of the repository.
        Throws:
        IOException - the repository could not be accessed
      • getConfig

        protected Config getConfig()
                            throws IOException
        Get the cached repository configuration, loading if not yet available.
        Returns:
        the configuration of the repository.
        Throws:
        IOException - the configuration is not available, or is badly formed.
      • loadConfig

        protected Config loadConfig()
                             throws IOException
        Parse and load the repository specific configuration.

        The default implementation reads gitDir/config, or returns an empty configuration if gitDir was not set.

        Returns:
        the repository's configuration.
        Throws:
        IOException - the configuration is not available.
      • self

        protected final B self()
        Get this object
        Returns:
        this