Class JGitRepository
java.lang.Object
com.github.koraktor.mavanagaiata.git.AbstractGitRepository
com.github.koraktor.mavanagaiata.git.jgit.JGitRepository
- All Implemented Interfaces:
GitRepository
,AutoCloseable
Wrapper around JGit's
Repository
object to represent a Git
repository- Author:
- Sebastian Staudt
-
Field Summary
Fields inherited from class com.github.koraktor.mavanagaiata.git.AbstractGitRepository
headRef
-
Constructor Summary
ConstructorsConstructorDescriptionJGitRepository
(File workTree, File gitDir, String headRef) Creates a new instance for the given worktree and or Git directory -
Method Summary
Modifier and TypeMethodDescriptionvoid
check()
Checks whether the Git repository is accessible.void
close()
Closes any resources that are needed to access this repositorydescribe()
Describes the current Git commit likegit describe
doesgetAbbreviatedCommitId
(GitCommit commit) Returns the abbreviated commit SHA ID of the given Git commitReturns the currently checked out branch of the Git repositoryReturns the currentHEAD
commit of the Git repositoryReturns the Git ref used as theHEAD
commit of the repositorygetTags()
Returns a map of tags available in this repositoryReturns the worktree of the repositoryboolean
Returns whether this repository instance has been checkedboolean
isDirty
(boolean ignoreUntracked) Returns whether the worktree of the repository is in a clean stateboolean
Returns whether this repository is currently on an “unborn” branchvoid
Load tag meta datavoid
walkCommits
(AbstractCommitWalkAction action) Runs the given action for all commits reachable from the currentHEAD
commitMethods inherited from class com.github.koraktor.mavanagaiata.git.AbstractGitRepository
getAbbreviatedCommitId, getMailMap, setHeadRef
-
Constructor Details
-
JGitRepository
Creates a new instance for the given worktree and or Git directory- Parameters:
workTree
- The worktree of the repository ornull
gitDir
- The GIT_DIR of the repository ornull
headRef
- The ref to use asHEAD
- Throws:
GitRepositoryException
- if the parameters do not match a Git repository
-
-
Method Details
-
check
Description copied from interface:GitRepository
Checks whether the Git repository is accessible.- Throws:
GitRepositoryException
- if the repository is not accessible.
-
close
public void close()Closes any resources that are needed to access this repositoryCloses JGit's repository instance.
- See Also:
-
describe
Description copied from interface:GitRepository
Describes the current Git commit likegit describe
does- Returns:
- The description of the current
HEAD
commit - Throws:
GitRepositoryException
- if the description cannot be created
-
getHeadRef
Description copied from interface:GitRepository
Returns the Git ref used as theHEAD
commit of the repository- Returns:
- The ref used as
HEAD
-
getAbbreviatedCommitId
Description copied from interface:GitRepository
Returns the abbreviated commit SHA ID of the given Git commit- Parameters:
commit
- The Git commit to get the abbreviated ID for- Returns:
- The abbreviated commit ID of the given commit
- Throws:
GitRepositoryException
- if the abbreviated commit ID cannot be determined
-
getBranch
Description copied from interface:GitRepository
Returns the currently checked out branch of the Git repository- Returns:
- The current branch of the Git repository
- Throws:
GitRepositoryException
- if the current branch cannot be determined
-
getHeadCommit
Description copied from interface:GitRepository
Returns the currentHEAD
commit of the Git repository- Returns:
- The current commit of the Git Repository
- Throws:
GitRepositoryException
- if the current commit cannot be determined
-
getTags
Description copied from interface:GitRepository
Returns a map of tags available in this repositoryThe keys of the map are the SHA IDs of the objects referenced by the tags. The map's values are the tags themselves.
Note: Only annotated tags referencing commit objects will be returned.
- Returns:
- A map of tags in this repository
- Throws:
GitRepositoryException
- if an error occurs while determining the tags in this repository
-
getWorkTree
Description copied from interface:GitRepository
Returns the worktree of the repository- Returns:
- The worktree of the repository
-
isChecked
public boolean isChecked()Description copied from interface:GitRepository
Returns whether this repository instance has been checked- Returns:
true
if this repository has already been checked- See Also:
-
isDirty
Description copied from interface:GitRepository
Returns whether the worktree of the repository is in a clean state- Parameters:
ignoreUntracked
- Iftrue
, untracked files in the repository will be ignored- Returns:
true
if there are modified files in the repository's worktree- Throws:
GitRepositoryException
- if an error occurs while checking the worktree state
-
isOnUnbornBranch
Description copied from interface:GitRepository
Returns whether this repository is currently on an “unborn” branchAn “unborn” branch is a branch without any actual commits. This only applies when the configured head ref is actually
HEAD
. Otherwise, a configuration error is assumed.- Returns:
true
if the current branch is- Throws:
GitRepositoryException
- if an error occurs while retrieving the current HEAD commit
-
loadTag
Description copied from interface:GitRepository
Load tag meta data- Parameters:
tag
- The tag to load information for- Throws:
GitRepositoryException
- if tag metadata cannot be loaded
-
walkCommits
Description copied from interface:GitRepository
Runs the given action for all commits reachable from the currentHEAD
commit- Parameters:
action
- The action to execute for each commit found- Throws:
GitRepositoryException
- if an error occurs during walking through the commits
-