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 TypeMethodDescriptionvoidcheck()Checks whether the Git repository is accessible.voidclose()Closes any resources that are needed to access this repositorydescribe()Describes the current Git commit likegit describedoesgetAbbreviatedCommitId(GitCommit commit) Returns the abbreviated commit SHA ID of the given Git commitReturns the currently checked out branch of the Git repositoryReturns the currentHEADcommit of the Git repositoryReturns the Git ref used as theHEADcommit of the repositorygetTags()Returns a map of tags available in this repositoryReturns the worktree of the repositorybooleanReturns whether this repository instance has been checkedbooleanisDirty(boolean ignoreUntracked) Returns whether the worktree of the repository is in a clean statebooleanReturns whether this repository is currently on an “unborn” branchvoidLoad tag meta datavoidwalkCommits(AbstractCommitWalkAction action) Runs the given action for all commits reachable from the currentHEADcommitMethods 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 ornullgitDir- The GIT_DIR of the repository ornullheadRef- The ref to use asHEAD- Throws:
GitRepositoryException- if the parameters do not match a Git repository
-
-
Method Details
-
check
Description copied from interface:GitRepositoryChecks 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:GitRepositoryDescribes the current Git commit likegit describedoes- Returns:
- The description of the current
HEADcommit - Throws:
GitRepositoryException- if the description cannot be created
-
getHeadRef
Description copied from interface:GitRepositoryReturns the Git ref used as theHEADcommit of the repository- Returns:
- The ref used as
HEAD
-
getAbbreviatedCommitId
Description copied from interface:GitRepositoryReturns 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:GitRepositoryReturns 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:GitRepositoryReturns the currentHEADcommit 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:GitRepositoryReturns 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:GitRepositoryReturns the worktree of the repository- Returns:
- The worktree of the repository
-
isChecked
public boolean isChecked()Description copied from interface:GitRepositoryReturns whether this repository instance has been checked- Returns:
trueif this repository has already been checked- See Also:
-
isDirty
Description copied from interface:GitRepositoryReturns 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
Description copied from interface:GitRepositoryReturns 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:
trueif the current branch is- Throws:
GitRepositoryException- if an error occurs while retrieving the current HEAD commit
-
loadTag
Description copied from interface:GitRepositoryLoad tag meta data- Parameters:
tag- The tag to load information for- Throws:
GitRepositoryException- if tag metadata cannot be loaded
-
walkCommits
Description copied from interface:GitRepositoryRuns the given action for all commits reachable from the currentHEADcommit- Parameters:
action- The action to execute for each commit found- Throws:
GitRepositoryException- if an error occurs during walking through the commits
-