Class BaseRepositoryBuilder<B extends BaseRepositoryBuilder,R extends Repository>
- Type Parameters:
B
- type of the repository builder.R
- type of the repository that is constructed.
- Direct Known Subclasses:
DfsRepositoryBuilder
,FileRepositoryBuilder
,RepositoryBuilder
Repository implementations may subclass this builder in order to add custom repository detection methods.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
True only if the caller wants to force bare behavior.Directories limiting the search for a Git repository.private Config
Configuration file of target repository, lazily loaded if required.private FS
private File
private File
private String
private boolean
True if the caller requires the repository to exist.private File
private File
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddAlternateObjectDirectories
(File[] inList) Add alternate object directories to the search list.addAlternateObjectDirectories
(Collection<File> inList) Add alternate object directories to the search list.addAlternateObjectDirectory
(File other) Add an alternate object directory to the search list.addCeilingDirectories
(File[] inList) Add ceiling directories to the search list.addCeilingDirectories
(Collection<File> inList) Add ceiling directories to the search list.addCeilingDirectory
(File root) Add a ceiling directory to the search limit list.build()
Create a repository matching the configuration in this builder.ConfigureGIT_DIR
by searching up the file system.findGitDir
(File current) ConfigureGIT_DIR
by searching up the file system.File[]
Get ordered array of alternate directories; null if non were set.protected Config
Get the cached repository configuration, loading if not yet available.getFS()
Get the file system abstraction, or null if not set.Get the meta data directory; null if not set.Get the index file location, or null if not set.Get the initial branch of the new repository.Get the object directory; null if not set.private static File
Get the work tree directory, or null if not set.private File
boolean
isBare()
Whether this repository was forced bare bysetBare()
.boolean
Whether the repository must exist before being opened.private static boolean
isSymRef
(byte[] ref) protected Config
Parse and load the repository specific configuration.Read standard Git environment variables and configure from those.Read standard Git environment variables and configure from those.protected void
Require eithergitDir
orworkTree
to be set.protected FS
safeFS()
Get the configured FS, orFS.DETECTED
.protected final B
self()
Get this objectsetBare()
Force the repository to be treated as bare (have no working directory).Set the file system abstraction needed by this repository.Set the Git directory storing the repository metadata.setIndexFile
(File indexFile) Set the local index file that is caching checked out file status.setInitialBranch
(String branch) Set the initial branch of the new repository.setMustExist
(boolean mustExist) Require the repository to exist before it can be opened.setObjectDirectory
(File objectDirectory) Set the directory storing the repository's objects.setup()
Guess and populate all parameters not already defined.protected void
Perform standard gitDir initialization.protected void
Configure the internal implementation details of the repository.protected void
Perform standard work-tree initialization.setWorkTree
(File workTree) Set the top level directory of the working files.
-
Field Details
-
fs
-
gitDir
-
objectDirectory
-
alternateObjectDirectories
-
indexFile
-
workTree
-
initialBranch
-
ceilingDirectories
Directories limiting the search for a Git repository. -
bare
private boolean bareTrue only if the caller wants to force bare behavior. -
mustExist
private boolean mustExistTrue if the caller requires the repository to exist. -
config
Configuration file of target repository, lazily loaded if required.
-
-
Constructor Details
-
BaseRepositoryBuilder
public BaseRepositoryBuilder()
-
-
Method Details
-
isSymRef
private static boolean isSymRef(byte[] ref) -
getSymRef
- Throws:
IOException
-
setFS
Set the file system abstraction needed by this repository.- Parameters:
fs
- the abstraction.- Returns:
this
(for chaining calls).
-
getFS
Get the file system abstraction, or null if not set.- Returns:
- the file system abstraction, or null if not set.
-
setGitDir
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. Ifnull
the path is assumed to beworkTree/.git
.- Parameters:
gitDir
-GIT_DIR
, the repository meta directory.- Returns:
this
(for chaining calls).
-
getGitDir
Get the meta data directory; null if not set.- Returns:
- the meta data directory; null if not set.
-
setObjectDirectory
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
Get the object directory; null if not set.- Returns:
- the object directory; null if not set.
-
addAlternateObjectDirectory
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
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
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
Get ordered array of alternate directories; null if non were set.- Returns:
- ordered array of alternate directories; null if non were set.
-
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 bysetBare()
.- Returns:
- true if this repository was forced bare by
setBare()
.
-
setMustExist
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
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
Get the work tree directory, or null if not set.- Returns:
- the work tree directory, or null if not set.
-
setIndexFile
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 defaultgitDiir/index
.- Parameters:
indexFile
-GIT_INDEX_FILE
, the index file location.- Returns:
this
(for chaining calls).
-
getIndexFile
Get the index file location, or null if not set.- Returns:
- the index file location, or null if not set.
-
setInitialBranch
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. Ifnull
or empty the configured default branch will be used.- Returns:
this
- Throws:
InvalidRefNameException
- if the branch name is not valid- Since:
- 5.11
-
getInitialBranch
Get the initial branch of the new repository.- Returns:
- the initial branch of the new repository.
- Since:
- 5.11
-
readEnvironment
Read standard Git environment variables and configure from those.This method tries to read the standard Git environment variables, such as
GIT_DIR
andGIT_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
Read standard Git environment variables and configure from those.This method tries to read the standard Git environment variables, such as
GIT_DIR
andGIT_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
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
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
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
ConfigureGIT_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 toreadEnvironment()
.- Returns:
this
(for chaining calls).
-
findGitDir
ConfigureGIT_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 toreadEnvironment()
.- Parameters:
current
- directory to begin searching in.- Returns:
this
(for chaining calls).
-
setup
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
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 eithergitDir
orworkTree
to be set. -
setupGitDir
Perform standard gitDir initialization.- Throws:
IOException
- the repository could not be accessed
-
setupWorkTree
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
Configure the internal implementation details of the repository.- Throws:
IOException
- the repository could not be accessed
-
getConfig
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
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.
-
guessWorkTreeOrFail
- Throws:
IOException
-
safeFS
Get the configured FS, orFS.DETECTED
.- Returns:
- the configured FS, or
FS.DETECTED
.
-
self
Get this object- Returns:
this
-