- All Implemented Interfaces:
AutoCloseable
- GIT_DIR
- objects/ - objects
- refs/ - tags and heads
- config - configuration
- info/ - more configurations
This class is thread-safe.
This implementation only handles a subtly undocumented subset of git features.
-
Constructor Summary
ConstructorsConstructorDescriptionFileRepository(File gitDir) Construct a representation of a Git repository.FileRepository(String gitDir) A convenience API forFileRepository(File).FileRepository(BaseRepositoryBuilder options) Create a repository using the local file system. -
Method Summary
Modifier and TypeMethodDescriptionvoidautoGC(ProgressMonitor monitor) Check whether any housekeeping is required; if yes, run garbage collection; if not, exit without performing any work.voidconvertRefStorage(String format, boolean writeLogs, boolean backup) Converts between ref storage formats.voidcreate(boolean bare) Create a new Git repository initializing the necessary files and directories.voidcreate(boolean bare, boolean relativePaths) Create a new Git repository initializing the necessary files and directories.Create a newAttributesNodeProvider.Objects known to exist but not expressed byRepository.getAllRefs().Get the configuration of this repository.Read theGIT_DIR/descriptionfile for gitweb.Get repository identifier.Get the object database which stores this repository's data.Get the directory containing the objects owned by this repositoryGet the reference database which stores the reference namespace.voidnotifyIndexChanged(boolean internal) Notify that the index changed by firing an IndexChangedEvent.voidAdd a single existing pack to the list of available pack files.voidForce a scan for changed refs.voidsetGitwebDescription(String description) Set theGIT_DIR/descriptionfile for gitweb.Methods inherited from class org.eclipse.jgit.lib.Repository
close, create, doClose, exactRef, findRef, fireEvent, getAllRefs, getAllRefsByPeeledObjectId, getBranch, getCommonDirectory, getDirectory, getFS, getFullBranch, getGlobalListenerList, getIndexFile, getInitialBranch, getListenerList, getReflogReader, getReflogReader, getRemoteName, getRemoteNames, getRepositoryState, getTags, getWorkTree, incrementOpen, isBare, isValidRefName, isWorkTreeCaseInsensitive, lockDirCache, newObjectInserter, newObjectReader, normalizeBranchName, open, open, parseCommit, readCherryPickHead, readCommitEditMsg, readDirCache, readMergeCommitMsg, readMergeHeads, readOrigHead, readRebaseTodo, readRevertHead, readSquashCommitMsg, renameRef, resolve, shortenRefName, shortenRemoteBranchName, simplify, stripWorkDir, toString, updateRef, updateRef, writeCherryPickHead, writeCommitEditMsg, writeMergeCommitMsg, writeMergeHeads, writeOrigHead, writeRebaseTodoFile, writeRevertHead, writeSquashCommitMsg
-
Constructor Details
-
FileRepository
Construct a representation of a Git repository.The work tree, object directory, alternate object directories and index file locations are deduced from the given git directory and the default rules by running
FileRepositoryBuilder. This constructor is the same as saying:new FileRepositoryBuilder().setGitDir(gitDir).build()
- Parameters:
gitDir- GIT_DIR (the location of the repository metadata).- Throws:
IOException- the repository appears to already exist but cannot be accessed.- See Also:
-
FileRepository
A convenience API forFileRepository(File).- Parameters:
gitDir- GIT_DIR (the location of the repository metadata).- Throws:
IOException- the repository appears to already exist but cannot be accessed.- See Also:
-
FileRepository
Create a repository using the local file system.- Parameters:
options- description of the repository's important paths.- Throws:
IOException- the user configuration file or repository configuration file cannot be accessed.
-
-
Method Details
-
create
Create a new Git repository initializing the necessary files and directories.Create a new Git repository initializing the necessary files and directories.
- Specified by:
createin classRepository- Parameters:
bare- if true, a bare repository (a repository without a working directory) is created.- Throws:
IOException- in case of IO problem
-
create
Create a new Git repository initializing the necessary files and directories.- Parameters:
bare- if true, a bare repository (a repository without a working directory) is created.relativePaths- if true, relative paths are used for GIT_DIR and GIT_WORK_TREE- Throws:
IOException- in case of IO problem
-
getObjectsDirectory
Get the directory containing the objects owned by this repository- Returns:
- the directory containing the objects owned by this repository.
-
getObjectDatabase
Description copied from class:RepositoryGet the object database which stores this repository's data.- Specified by:
getObjectDatabasein classRepository- Returns:
- the object database which stores this repository's data.
-
getRefDatabase
Description copied from class:RepositoryGet the reference database which stores the reference namespace.- Specified by:
getRefDatabasein classRepository- Returns:
- the reference database which stores the reference namespace.
-
getIdentifier
Description copied from class:RepositoryGet repository identifier.- Specified by:
getIdentifierin classRepository- Returns:
- repository identifier. The returned identifier has to be unique within a given Git server.
-
getConfig
Description copied from class:RepositoryGet the configuration of this repository.- Specified by:
getConfigin classRepository- Returns:
- the configuration of this repository.
-
getGitwebDescription
Description copied from class:RepositoryRead theGIT_DIR/descriptionfile for gitweb.- Overrides:
getGitwebDescriptionin classRepository- Returns:
- description text; null if no description has been configured.
- Throws:
IOException- description cannot be accessed.
-
setGitwebDescription
Description copied from class:RepositorySet theGIT_DIR/descriptionfile for gitweb.- Overrides:
setGitwebDescriptionin classRepository- Parameters:
description- new description; null to clear the description.- Throws:
IOException- description cannot be persisted.
-
getAdditionalHaves
Objects known to exist but not expressed byRepository.getAllRefs().When a repository borrows objects from another repository, it can advertise that it safely has that other repository's references, without exposing any other details about the other repository. This may help a client trying to push changes avoid pushing more than it needs to.
Objects known to exist but not expressed by
#getAllRefs().When a repository borrows objects from another repository, it can advertise that it safely has that other repository's references, without exposing any other details about the other repository. This may help a client trying to push changes avoid pushing more than it needs to.
- Overrides:
getAdditionalHavesin classRepository- Returns:
- unmodifiable collection of other known objects.
- Throws:
IOException- if an IO error occurred
-
openPack
Add a single existing pack to the list of available pack files.- Parameters:
pack- path of the pack file to open.- Throws:
IOException- index file could not be opened, read, or is not recognized as a Git pack file index.
-
scanForRepoChanges
Description copied from class:RepositoryForce a scan for changed refs. Fires an IndexChangedEvent(false) if changes are detected.- Specified by:
scanForRepoChangesin classRepository- Throws:
IOException- if an IO error occurred
-
notifyIndexChanged
public void notifyIndexChanged(boolean internal) Description copied from class:RepositoryNotify that the index changed by firing an IndexChangedEvent.- Specified by:
notifyIndexChangedin classRepository- Parameters:
internal-trueif the index was changed by the same JGit process
-
createAttributesNodeProvider
Description copied from class:RepositoryCreate a newAttributesNodeProvider.- Specified by:
createAttributesNodeProviderin classRepository- Returns:
- a new
AttributesNodeProvider. ThisAttributesNodeProvideris lazy loaded only once. It means that it will not be updated after loading. Prefer creating new instance for each use.
-
autoGC
Description copied from class:RepositoryCheck whether any housekeeping is required; if yes, run garbage collection; if not, exit without performing any work. Some JGit commands run autoGC after performing operations that could create many loose objects.Currently this option is supported for repositories of type
FileRepositoryonly. SeeGC.setAuto(boolean)for configuration details.- Overrides:
autoGCin classRepository- Parameters:
monitor- to report progress
-
convertRefStorage
Converts between ref storage formats.- Parameters:
format- the format to convert to, either "reftable" or "refdir"writeLogs- whether to write reflogsbackup- whether to make a backup of the old data- Throws:
IOException- on I/O problems.
-