B
- type of the repository builder.R
- type of the repository that is constructed.public class BaseRepositoryBuilder<B extends BaseRepositoryBuilder,R extends Repository> extends Object
Repository implementations may subclass this builder in order to add custom repository detection methods.
RepositoryBuilder
,
FileRepositoryBuilder
Constructor and Description |
---|
BaseRepositoryBuilder() |
Modifier and Type | Method and Description |
---|---|
B |
addAlternateObjectDirectories(Collection<File> inList)
Add alternate object directories to the search list.
|
B |
addAlternateObjectDirectories(File[] inList)
Add alternate object directories to the search list.
|
B |
addAlternateObjectDirectory(File other)
Add an alternate object directory to the search list.
|
B |
addCeilingDirectories(Collection<File> inList)
Add ceiling directories to the search list.
|
B |
addCeilingDirectories(File[] inList)
Add ceiling directories to the search list.
|
B |
addCeilingDirectory(File root)
Add a ceiling directory to the search limit list.
|
R |
build()
Create a repository matching the configuration in this builder.
|
B |
findGitDir()
Configure
GIT_DIR by searching up the file system. |
B |
findGitDir(File current)
Configure
GIT_DIR by searching up the file system. |
File[] |
getAlternateObjectDirectories()
Get ordered array of alternate directories; null if non were set.
|
protected Config |
getConfig()
Get the cached repository configuration, loading if not yet available.
|
FS |
getFS()
Get the file system abstraction, or null if not set.
|
File |
getGitDir()
Get the meta data directory; null if not set.
|
File |
getIndexFile()
Get the index file location, or null if not set.
|
File |
getObjectDirectory()
Get the object directory; null if not set.
|
File |
getWorkTree()
Get the work tree directory, or null if not set.
|
boolean |
isBare()
Whether this repository was forced bare by
setBare() . |
boolean |
isMustExist()
Whether the repository must exist before being opened.
|
protected Config |
loadConfig()
Parse and load the repository specific configuration.
|
B |
readEnvironment()
Read standard Git environment variables and configure from those.
|
B |
readEnvironment(SystemReader sr)
Read standard Git environment variables and configure from those.
|
protected void |
requireGitDirOrWorkTree()
Require either
gitDir or workTree to be set. |
protected FS |
safeFS()
Get the configured FS, or
FS.DETECTED . |
protected B |
self()
Get this object
|
B |
setBare()
Force the repository to be treated as bare (have no working directory).
|
B |
setFS(FS fs)
Set the file system abstraction needed by this repository.
|
B |
setGitDir(File gitDir)
Set the Git directory storing the repository metadata.
|
B |
setIndexFile(File indexFile)
Set the local index file that is caching checked out file status.
|
B |
setMustExist(boolean mustExist)
Require the repository to exist before it can be opened.
|
B |
setObjectDirectory(File objectDirectory)
Set the directory storing the repository's objects.
|
B |
setup()
Guess and populate all parameters not already defined.
|
protected void |
setupGitDir()
Perform standard gitDir initialization.
|
protected void |
setupInternals()
Configure the internal implementation details of the repository.
|
protected void |
setupWorkTree()
Perform standard work-tree initialization.
|
B |
setWorkTree(File workTree)
Set the top level directory of the working files.
|
public B setFS(FS fs)
fs
- the abstraction.this
(for chaining calls).public FS getFS()
public B setGitDir(File gitDir)
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
.
gitDir
- GIT_DIR
, the repository meta directory.this
(for chaining calls).public File getGitDir()
public B setObjectDirectory(File objectDirectory)
objectDirectory
- GIT_OBJECT_DIRECTORY
, the directory where the
repository's object files are stored.this
(for chaining calls).public File getObjectDirectory()
public B addAlternateObjectDirectory(File other)
This setting handles one alternate directory at a time, and is provided
to support GIT_ALTERNATE_OBJECT_DIRECTORIES
.
other
- another objects directory to search after the standard one.this
(for chaining calls).public B addAlternateObjectDirectories(Collection<File> inList)
This setting handles several alternate directories at once, and is
provided to support GIT_ALTERNATE_OBJECT_DIRECTORIES
.
inList
- other object directories to search after the standard one. The
collection's contents is copied to an internal list.this
(for chaining calls).public B addAlternateObjectDirectories(File[] inList)
This setting handles several alternate directories at once, and is
provided to support GIT_ALTERNATE_OBJECT_DIRECTORIES
.
inList
- other object directories to search after the standard one. The
array's contents is copied to an internal list.this
(for chaining calls).public File[] getAlternateObjectDirectories()
public B setBare()
If bare the working directory aspects of the repository won't be configured, and will not be accessible.
this
(for chaining calls).public boolean isBare()
setBare()
.setBare()
.public B setMustExist(boolean mustExist)
mustExist
- true if it must exist; false if it can be missing and created
after being built.this
(for chaining calls).public boolean isMustExist()
public B setWorkTree(File workTree)
workTree
- GIT_WORK_TREE
, the working directory of the checkout.this
(for chaining calls).public File getWorkTree()
public B setIndexFile(File indexFile)
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
.
indexFile
- GIT_INDEX_FILE
, the index file location.this
(for chaining calls).public File getIndexFile()
public B readEnvironment()
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.
this
(for chaining calls).public B readEnvironment(SystemReader sr)
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.
sr
- the SystemReader abstraction to access the environment.this
(for chaining calls).public B addCeilingDirectory(File root)
This setting handles one ceiling directory at a time, and is provided to
support GIT_CEILING_DIRECTORIES
.
root
- a path to stop searching at; its parent will not be searched.this
(for chaining calls).public B addCeilingDirectories(Collection<File> inList)
This setting handles several ceiling directories at once, and is provided
to support GIT_CEILING_DIRECTORIES
.
inList
- directory paths to stop searching at. The collection's
contents is copied to an internal list.this
(for chaining calls).public B addCeilingDirectories(File[] inList)
This setting handles several ceiling directories at once, and is provided
to support GIT_CEILING_DIRECTORIES
.
inList
- directory paths to stop searching at. The array's contents is
copied to an internal list.this
(for chaining calls).public B findGitDir()
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()
.
this
(for chaining calls).public B findGitDir(File current)
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()
.
current
- directory to begin searching in.this
(for chaining calls).public B setup() throws IllegalArgumentException, IOException
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.
this
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.public R build() throws IOException
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.
IllegalArgumentException
- insufficient parameters were set.IOException
- the repository could not be accessed to configure the rest of
the builder's parameters.protected void requireGitDirOrWorkTree()
gitDir
or workTree
to be set.protected void setupGitDir() throws IOException
IOException
- the repository could not be accessedprotected void setupWorkTree() throws IOException
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.
IOException
- the repository configuration could not be read.protected void setupInternals() throws IOException
IOException
- the repository could not be accessedprotected Config getConfig() throws IOException
IOException
- the configuration is not available, or is badly formed.protected Config loadConfig() throws IOException
The default implementation reads gitDir/config
, or returns an
empty configuration if gitDir was not set.
IOException
- the configuration is not available.protected FS safeFS()
FS.DETECTED
.FS.DETECTED
.protected final B self()
this
Copyright © 2019 Eclipse JGit Project. All rights reserved.