Class BaseRepositoryBuilder<B extends BaseRepositoryBuilder,R extends Repository>
- java.lang.Object
-
- org.eclipse.jgit.lib.BaseRepositoryBuilder<B,R>
-
- Type Parameters:
B
- type of the repository builder.R
- type of the repository that is constructed.
- Direct Known Subclasses:
DfsRepositoryBuilder
,FileRepositoryBuilder
,RepositoryBuilder
public class BaseRepositoryBuilder<B extends BaseRepositoryBuilder,R extends Repository> extends Object
Base builder to customize repository construction.Repository implementations may subclass this builder in order to add custom repository detection methods.
- See Also:
RepositoryBuilder
,FileRepositoryBuilder
-
-
Constructor Summary
Constructors Constructor Description BaseRepositoryBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description B
addAlternateObjectDirectories(File[] inList)
Add alternate object directories to the search list.B
addAlternateObjectDirectories(Collection<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(File[] inList)
Add ceiling directories to the search list.B
addCeilingDirectories(Collection<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()
ConfigureGIT_DIR
by searching up the file system.B
findGitDir(File current)
ConfigureGIT_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.String
getInitialBranch()
Get the initial branch of the new repository.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 bysetBare()
.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 eithergitDir
orworkTree
to be set.protected FS
safeFS()
Get the configured FS, orFS.DETECTED
.protected B
self()
Get this objectB
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
setInitialBranch(String branch)
Set the initial branch of the new repository.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.
-
-
-
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. Ifnull
the path is assumed to beworkTree/.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 bysetBare()
.- 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 defaultgitDiir/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. 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
@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
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
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
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
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()
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
public B findGitDir(File current)
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
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 eithergitDir
orworkTree
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.
-
safeFS
protected FS safeFS()
Get the configured FS, orFS.DETECTED
.- Returns:
- the configured FS, or
FS.DETECTED
.
-
self
protected final B self()
Get this object- Returns:
this
-
-