Interface GitRepository
-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
AbstractGitRepository,JGitRepository
public interface GitRepository extends AutoCloseable
This interface specifies the basic properties needed for the mojos to access the information about a Git repository- Author:
- Sebastian Staudt
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcheck()Checks whether the Git repository is accessible.voidclose()Closes any resources that are needed to access this repositoryGitTagDescriptiondescribe()Describes the current Git commit likegit describedoesStringgetAbbreviatedCommitId()Returns the abbreviated commit SHA ID of the current Git commitStringgetAbbreviatedCommitId(GitCommit commit)Returns the abbreviated commit SHA ID of the given Git commitStringgetBranch()Returns the currently checked out branch of the Git repositoryGitCommitgetHeadCommit()Returns the currentHEADcommit of the Git repositoryStringgetHeadRef()Returns the Git ref used as theHEADcommit of the repositoryMailMapgetMailMap()Returns aMailMapobject that holds information from Git's.mailmapfileMap<String,GitTag>getTags()Returns a map of tags available in this repositoryFilegetWorkTree()Returns the worktree of the repositorybooleanisChecked()Returns whether this repository instance has been checkedbooleanisDirty(boolean ignoreUntracked)Returns whether the worktree of the repository is in a clean statebooleanisOnUnbornBranch()Returns whether this repository is currently on an “unborn” branch An “unborn” branch is a branch without any actual commits.voidloadTag(GitTag tag)Load tag meta datavoidsetHeadRef(String headRef)Sets the Git ref to use as theHEADcommit of the repository<T extends CommitWalkAction>
TwalkCommits(T action)Runs the given action for all commits reachable from the currentHEADcommit
-
-
-
Method Detail
-
check
void check() throws GitRepositoryExceptionChecks 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:
closein interfaceAutoCloseable
-
describe
GitTagDescription describe() throws GitRepositoryException
Describes the current Git commit likegit describedoes- Returns:
- The description of the current
HEADcommit - Throws:
GitRepositoryException- if the description cannot be created
-
getAbbreviatedCommitId
String getAbbreviatedCommitId() throws GitRepositoryException
Returns the abbreviated commit SHA ID of the current Git commit- Returns:
- The abbreviated commit ID of the current
HEADcommit - Throws:
GitRepositoryException- if the abbreviated commit ID cannot be determined
-
getAbbreviatedCommitId
String getAbbreviatedCommitId(GitCommit commit) throws GitRepositoryException
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
String getBranch() throws GitRepositoryException
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
GitCommit getHeadCommit() throws GitRepositoryException
Returns the currentHEADcommit 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 theHEADcommit of the repository- Returns:
- The ref used as
HEAD
-
getMailMap
MailMap getMailMap() throws GitRepositoryException
Returns aMailMapobject that holds information from Git's.mailmapfile- Returns:
- A
.mailmaprepresentation ornullif none exits - Throws:
GitRepositoryException- if the.mailmapfile cannot be read or parsed
-
getTags
Map<String,GitTag> getTags() throws GitRepositoryException
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:
trueif this repository has already been checked- See Also:
check()
-
isDirty
boolean isDirty(boolean ignoreUntracked) throws GitRepositoryExceptionReturns whether the worktree of the repository is in a clean state- Parameters:
ignoreUntracked- Iftrue, untracked files in the repository will be ignored- Returns:
trueif there are modified files in the repository's worktree- Throws:
GitRepositoryException- if an error occurs while checking the worktree state
-
isOnUnbornBranch
boolean isOnUnbornBranch() throws GitRepositoryExceptionReturns whether this repository is currently on an “unborn” branch An “unborn” branch is a branch without any actual commits. This only applies when the configured head ref is actuallyHEAD. Otherwise a configuration error is assumed.- Returns:
trueif the current branch is- Throws:
GitRepositoryException- if an error occurs while retrieving the current HEAD commit
-
setHeadRef
void setHeadRef(String headRef)
Sets the Git ref to use as theHEADcommit of the repository- Parameters:
headRef- The ref to use asHEAD
-
loadTag
void loadTag(GitTag tag) throws GitRepositoryException
Load tag meta data- Parameters:
tag- The tag to load information for- Throws:
GitRepositoryException- if tag metadata cannot be loaded
-
walkCommits
<T extends CommitWalkAction> T walkCommits(T action) throws GitRepositoryException
Runs the given action for all commits reachable from the currentHEADcommit- Type Parameters:
T- The action’s type- Parameters:
action- The action to execute for each commit found- Returns:
- The action itself
- Throws:
GitRepositoryException- if an error occurs during walking through the commits
-
-