Interface GitRepository
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
AbstractGitRepository
,JGitRepository
This interface specifies the basic properties needed for the mojos to access
the information about a Git repository
- Author:
- Sebastian Staudt
-
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
doesReturns the abbreviated commit SHA ID of the current Git commitgetAbbreviatedCommitId
(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 repositoryReturns aMailMap
object that holds information from Git's.mailmap
filegetTags()
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
setHeadRef
(String headRef) Sets the Git ref to use as theHEAD
commit of the repositoryvoid
walkCommits
(AbstractCommitWalkAction action) Runs the given action for all commits reachable from the currentHEAD
commit
-
Method Details
-
check
Checks whether the Git repository is accessible.- Throws:
GitRepositoryException
- if the repository is not accessible.
-
close
void close()Closes any resources that are needed to access this repository- Specified by:
close
in interfaceAutoCloseable
-
describe
Describes the current Git commit likegit describe
does- Returns:
- The description of the current
HEAD
commit - Throws:
GitRepositoryException
- if the description cannot be created
-
getAbbreviatedCommitId
Returns the abbreviated commit SHA ID of the current Git commit- Returns:
- The abbreviated commit ID of the current
HEAD
commit - Throws:
GitRepositoryException
- if the abbreviated commit ID cannot be determined
-
getAbbreviatedCommitId
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
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
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
-
getHeadRef
String getHeadRef()Returns the Git ref used as theHEAD
commit of the repository- Returns:
- The ref used as
HEAD
-
getMailMap
Returns aMailMap
object that holds information from Git's.mailmap
file- Returns:
- A
.mailmap
representation ornull
if none exits - Throws:
GitRepositoryException
- if the.mailmap
file cannot be read or parsed
-
getTags
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
File getWorkTree()Returns the worktree of the repository- Returns:
- The worktree of the repository
-
isChecked
boolean isChecked()Returns whether this repository instance has been checked- Returns:
true
if this repository has already been checked- See Also:
-
isDirty
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
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
-
setHeadRef
Sets the Git ref to use as theHEAD
commit of the repository- Parameters:
headRef
- The ref to use asHEAD
-
loadTag
Load tag meta data- Parameters:
tag
- The tag to load information for- Throws:
GitRepositoryException
- if tag metadata cannot be loaded
-
walkCommits
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
-