Top Description Fields Constructors Methods
org.eclipse.jgit.lib

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

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.lib.RepositoryBuilder, org.eclipse.jgit.storage.file.FileRepositoryBuilder, org.eclipse.jgit.internal.storage.dfs.DfsRepositoryBuilder
Type Parameters
<B>
type of the repository builder.
<R>
type of the repository that is constructed.
Static Imports
org.eclipse.jgit.lib.ConfigConstants.CONFIG_CORE_SECTION, .ConfigConstants.CONFIG_KEY_BARE, .ConfigConstants.CONFIG_KEY_WORKTREE, .Constants.CONFIG, .Constants.DOT_GIT, .Constants.GITDIR_FILE, .Constants.GIT_ALTERNATE_OBJECT_DIRECTORIES_KEY, .Constants.GIT_CEILING_DIRECTORIES_KEY, .Constants.GIT_COMMON_DIR_KEY, .Constants.GIT_DIR_KEY, .Constants.GIT_INDEX_FILE_KEY, .Constants.GIT_OBJECT_DIRECTORY_KEY, .Constants.GIT_WORK_TREE_KEY, .Constants.OBJECTS

Base builder to customize repository construction.

Repository implementations may subclass this builder in order to add custom repository detection methods.

See Also
RepositoryBuilder, FileRepositoryBuilder

Field Summary

Modifier and TypeField and Description
private List<File>
private boolean
bare

True only if the caller wants to force bare behavior.

private List<File>
ceilingDirectories

Directories limiting the search for a Git repository.

private Config
config

Configuration file of target repository, lazily loaded if required.

private FS
private File
private File
private File
private String
private boolean
mustExist

True if the caller requires the repository to exist.

private File
private File

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public B

Returns:

this (for chaining calls).
addAlternateObjectDirectories
(Collection<File>
other object directories to search after the standard one. The collection's contents is copied to an internal list.
inList
)

Add alternate object directories to the search list.

public B

Returns:

this (for chaining calls).
addAlternateObjectDirectories
(File[]
other object directories to search after the standard one. The array's contents is copied to an internal list.
inList
)

Add alternate object directories to the search list.

public B

Returns:

this (for chaining calls).
addAlternateObjectDirectory
(File
another objects directory to search after the standard one.
other
)

Add an alternate object directory to the search list.

public B

Returns:

this (for chaining calls).
addCeilingDirectories
(Collection<File>
directory paths to stop searching at. The collection's contents is copied to an internal list.
inList
)

Add ceiling directories to the search list.

public B

Returns:

this (for chaining calls).
addCeilingDirectories
(File[]
directory paths to stop searching at. The array's contents is copied to an internal list.
inList
)

Add ceiling directories to the search list.

public B

Returns:

this (for chaining calls).
addCeilingDirectory
(File
a path to stop searching at; its parent will not be searched.
root
)

Add a ceiling directory to the search limit list.

public R

Returns:

a repository matching this configuration. The caller is responsible to close the repository instance when it is no longer needed.
build
()

Create a repository matching the configuration in this builder.

public B

Returns:

this (for chaining calls).
findGitDir
()

Configure GIT_DIR by searching up the file system.

public B

Returns:

this (for chaining calls).
findGitDir
(File
directory to begin searching in.
current
)

Configure GIT_DIR by searching up the file system.

public File[]

Returns:

ordered array of alternate directories; null if non were set.
getAlternateObjectDirectories
()

Get ordered array of alternate directories; null if non were set.

protected Config

Returns:

the configuration of the repository.
getConfig
()

Get the cached repository configuration, loading if not yet available.

public FS

Returns:

the file system abstraction, or null if not set.
getFS
()

Get the file system abstraction, or null if not set.

public File

Returns:

common dir; null if not set.
getGitCommonDir
()

Get common dir.

public File

Returns:

the meta data directory; null if not set.
getGitDir
()

Get the meta data directory; null if not set.

public File

Returns:

the index file location, or null if not set.
getIndexFile
()

Get the index file location, or null if not set.

public String

Returns:

the initial branch of the new repository.
getInitialBranch
()

Get the initial branch of the new repository.

public File

Returns:

the object directory; null if not set.
getObjectDirectory
()

Get the object directory; null if not set.

pack-priv static File

Returns:

the file read from symbolic reference file
getSymRef
(File
the work tree path
workTree
,
File
the .git file
dotGit
,
FS
th FS util
fs
)

Read symbolic reference file

public File

Returns:

the work tree directory, or null if not set.
getWorkTree
()

Get the work tree directory, or null if not set.

private File
public boolean

Returns:

true if this repository was forced bare by setBare().
isBare
()

Whether this repository was forced bare by setBare().

public boolean

Returns:

true if the repository must exist before being opened.
isMustExist
()

Whether the repository must exist before being opened.

private static boolean
isSymRef(byte[] ref)

protected Config

Returns:

the repository's configuration.
loadConfig
()

Parse and load the repository specific configuration.

public B

Returns:

this (for chaining calls).
readEnvironment
()

Read standard Git environment variables and configure from those.

public B

Returns:

this (for chaining calls).
readEnvironment
(SystemReader
the SystemReader abstraction to access the environment.
sr
)

Read standard Git environment variables and configure from those.

protected void
requireGitDirOrWorkTree()

Require either gitDir or workTree to be set.

protected FS

Returns:

the configured FS, or FS#DETECTED.
safeFS
()

Get the configured FS, or FS#DETECTED.

protected final B

Returns:

this
self
()

Get this object

public B

Returns:

this (for chaining calls).
setBare
()

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

public B

Returns:

this (for chaining calls).
setFS
(FS
the abstraction.
fs
)

Set the file system abstraction needed by this repository.

public B

Returns:

this (for chaining calls).
setGitCommonDir
(File
GIT_COMMON_DIR, the common repository meta directory.
gitCommonDir
)

Set common dir.

public B

Returns:

this (for chaining calls).
setGitDir
(File
GIT_DIR, the repository meta directory.
gitDir
)

Set the Git directory storing the repository metadata.

public B

Returns:

this (for chaining calls).
setIndexFile
(File
GIT_INDEX_FILE, the index file location.
indexFile
)

Set the local index file that is caching checked out file status.

public B

Returns:

this
setInitialBranch
(String
initial branch name of the new repository. If null or empty the configured default branch will be used.
branch
)

Set the initial branch of the new repository.

public B

Returns:

this (for chaining calls).
setMustExist
(boolean
true if it must exist; false if it can be missing and created after being built.
mustExist
)

Require the repository to exist before it can be opened.

public B

Returns:

this (for chaining calls).
setObjectDirectory
(File
GIT_OBJECT_DIRECTORY, the directory where the repository's object files are stored.
objectDirectory
)

Set the directory storing the repository's objects.

public B

Returns:

this
setup
()

Guess and populate all parameters not already defined.

protected void
setupCommonDir()

Perform standard common dir initialization.

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.

public B

Returns:

this (for chaining calls).
setWorkTree
(File
GIT_WORK_TREE, the working directory of the checkout.
workTree
)

Set the top level directory of the working files.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

alternateObjectDirectoriesback to summary
private List<File> alternateObjectDirectories
bareback to summary
private boolean bare

True only if the caller wants to force bare behavior.

ceilingDirectoriesback to summary
private List<File> ceilingDirectories

Directories limiting the search for a Git repository.

configback to summary
private Config config

Configuration file of target repository, lazily loaded if required.

fsback to summary
private FS fs
gitCommonDirback to summary
private File gitCommonDir
gitDirback to summary
private File gitDir
indexFileback to summary
private File indexFile
initialBranchback to summary
private String initialBranch
mustExistback to summary
private boolean mustExist

True if the caller requires the repository to exist.

objectDirectoryback to summary
private File objectDirectory
workTreeback to summary
private File workTree

Constructor Detail

BaseRepositoryBuilderback to summary
public BaseRepositoryBuilder()

Method Detail

addAlternateObjectDirectoriesback to summary
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:Collection<File>

other object directories to search after the standard one. The collection's contents is copied to an internal list.

Returns:B

this (for chaining calls).

addAlternateObjectDirectoriesback to summary
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:File[]

other object directories to search after the standard one. The array's contents is copied to an internal list.

Returns:B

this (for chaining calls).

addAlternateObjectDirectoryback to summary
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:File

another objects directory to search after the standard one.

Returns:B

this (for chaining calls).

addCeilingDirectoriesback to summary
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:Collection<File>

directory paths to stop searching at. The collection's contents is copied to an internal list.

Returns:B

this (for chaining calls).

addCeilingDirectoriesback to summary
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:File[]

directory paths to stop searching at. The array's contents is copied to an internal list.

Returns:B

this (for chaining calls).

addCeilingDirectoryback to summary
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:File

a path to stop searching at; its parent will not be searched.

Returns:B

this (for chaining calls).

buildback to summary
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:R

a repository matching this configuration. The caller is responsible to close the repository instance when it is no longer needed.

Annotations
@SuppressWarnings:unchecked, resource
Exceptions
IOException:
the repository could not be accessed to configure the rest of the builder's parameters.
IllegalArgumentException:
insufficient parameters were set.
findGitDirback to summary
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:B

this (for chaining calls).

findGitDirback to summary
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:File

directory to begin searching in.

Returns:B

this (for chaining calls).

getAlternateObjectDirectoriesback to summary
public File[] getAlternateObjectDirectories()

Get ordered array of alternate directories; null if non were set.

Returns:File[]

ordered array of alternate directories; null if non were set.

getConfigback to summary
protected Config getConfig() throws IOException

Get the cached repository configuration, loading if not yet available.

Returns:Config

the configuration of the repository.

Exceptions
IOException:
the configuration is not available, or is badly formed.
getFSback to summary
public FS getFS()

Get the file system abstraction, or null if not set.

Returns:FS

the file system abstraction, or null if not set.

getGitCommonDirback to summary
public File getGitCommonDir()

Get common dir.

Returns:File

common dir; null if not set.

Since
7.0
getGitDirback to summary
public File getGitDir()

Get the meta data directory; null if not set.

Returns:File

the meta data directory; null if not set.

getIndexFileback to summary
public File getIndexFile()

Get the index file location, or null if not set.

Returns:File

the index file location, or null if not set.

getInitialBranchback to summary
public String getInitialBranch()

Get the initial branch of the new repository.

Returns:String

the initial branch of the new repository.

Annotations
@NonNull
Since
5.11
getObjectDirectoryback to summary
public File getObjectDirectory()

Get the object directory; null if not set.

Returns:File

the object directory; null if not set.

getSymRefback to summary
pack-priv static File getSymRef(File workTree, File dotGit, FS fs) throws IOException

Read symbolic reference file

Parameters
workTree:File

the work tree path

dotGit:File

the .git file

fs:FS

th FS util

Returns:File

the file read from symbolic reference file

Exceptions
IOException:
the dotGit file is invalid reference
Since
7.0
getWorkTreeback to summary
public File getWorkTree()

Get the work tree directory, or null if not set.

Returns:File

the work tree directory, or null if not set.

guessWorkTreeOrFailback to summary
private File guessWorkTreeOrFail() throws IOException
isBareback to summary
public boolean isBare()

Whether this repository was forced bare by setBare().

Returns:boolean

true if this repository was forced bare by setBare().

isMustExistback to summary
public boolean isMustExist()

Whether the repository must exist before being opened.

Returns:boolean

true if the repository must exist before being opened.

isSymRefback to summary
private static boolean isSymRef(byte[] ref)
loadConfigback to summary
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:Config

the repository's configuration.

Exceptions
IOException:
the configuration is not available.
readEnvironmentback to summary
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, GIT_COMMON_DIR, GIT_WORK_TREE etc. to configure this builder instance. If an environment variable is set, it overrides the value already set in this builder.

Returns:B

this (for chaining calls).

readEnvironmentback to summary
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, GIT_COMMON_DIR, GIT_WORK_TREE etc. to configure this builder instance. If a property is already set in the builder, the environment variable is not used.

Parameters
sr:SystemReader

the SystemReader abstraction to access the environment.

Returns:B

this (for chaining calls).

requireGitDirOrWorkTreeback to summary
protected void requireGitDirOrWorkTree()

Require either gitDir or workTree to be set.

safeFSback to summary
protected FS safeFS()

Get the configured FS, or FS#DETECTED.

Returns:FS

the configured FS, or FS#DETECTED.

selfback to summary
protected final B self()

Get this object

Returns:B

this

Annotations
@SuppressWarnings:unchecked
setBareback to summary
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:B

this (for chaining calls).

setFSback to summary
public B setFS(FS fs)

Set the file system abstraction needed by this repository.

Parameters
fs:FS

the abstraction.

Returns:B

this (for chaining calls).

setGitCommonDirback to summary
public B setGitCommonDir(File gitCommonDir)

Set common dir.

Parameters
gitCommonDir:File

GIT_COMMON_DIR, the common repository meta directory.

Returns:B

this (for chaining calls).

Since
7.0
setGitDirback to summary
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:File

GIT_DIR, the repository meta directory.

Returns:B

this (for chaining calls).

setIndexFileback to summary
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:File

GIT_INDEX_FILE, the index file location.

Returns:B

this (for chaining calls).

setInitialBranchback to summary
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:String

initial branch name of the new repository. If null or empty the configured default branch will be used.

Returns:B

this

Exceptions
InvalidRefNameException:
if the branch name is not valid
Since
5.11
setMustExistback to summary
public B setMustExist(boolean mustExist)

Require the repository to exist before it can be opened.

Parameters
mustExist:boolean

true if it must exist; false if it can be missing and created after being built.

Returns:B

this (for chaining calls).

setObjectDirectoryback to summary
public B setObjectDirectory(File objectDirectory)

Set the directory storing the repository's objects.

Parameters
objectDirectory:File

GIT_OBJECT_DIRECTORY, the directory where the repository's object files are stored.

Returns:B

this (for chaining calls).

setupback to summary
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:B

this

Exceptions
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.
setupCommonDirback to summary
protected void setupCommonDir() throws IOException

Perform standard common dir initialization.

Exceptions
IOException:
the repository could not be accessed
Since
7.0
setupGitDirback to summary
protected void setupGitDir() throws IOException

Perform standard gitDir initialization.

Exceptions
IOException:
the repository could not be accessed
setupInternalsback to summary
protected void setupInternals() throws IOException

Configure the internal implementation details of the repository.

Exceptions
IOException:
the repository could not be accessed
setupWorkTreeback to summary
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.

Exceptions
IOException:
the repository configuration could not be read.
setWorkTreeback to summary
public B setWorkTree(File workTree)

Set the top level directory of the working files.

Parameters
workTree:File

GIT_WORK_TREE, the working directory of the checkout.

Returns:B

this (for chaining calls).