Class JGitRepository

java.lang.Object
com.github.koraktor.mavanagaiata.git.AbstractGitRepository
com.github.koraktor.mavanagaiata.git.jgit.JGitRepository
All Implemented Interfaces:
GitRepository, AutoCloseable

public class JGitRepository extends AbstractGitRepository
Wrapper around JGit's Repository object to represent a Git repository
Author:
Sebastian Staudt
  • Constructor Details

    • JGitRepository

      public JGitRepository(File workTree, File gitDir, String headRef) throws GitRepositoryException
      Creates a new instance for the given worktree and or Git directory
      Parameters:
      workTree - The worktree of the repository or null
      gitDir - The GIT_DIR of the repository or null
      headRef - The ref to use as HEAD
      Throws:
      GitRepositoryException - if the parameters do not match a Git repository
  • Method Details

    • check

      public void check() throws GitRepositoryException
      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 repository

      Closes JGit's repository instance.

      See Also:
      • Repository.close()
    • describe

      public GitTagDescription describe() throws GitRepositoryException
      Description copied from interface: GitRepository
      Describes the current Git commit like git describe does
      Returns:
      The description of the current HEAD commit
      Throws:
      GitRepositoryException - if the description cannot be created
    • getHeadRef

      public String getHeadRef()
      Description copied from interface: GitRepository
      Returns the Git ref used as the HEAD commit of the repository
      Returns:
      The ref used as HEAD
    • getAbbreviatedCommitId

      public String getAbbreviatedCommitId(GitCommit commit) throws GitRepositoryException
      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

      public String getBranch() throws GitRepositoryException
      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

      public GitCommit getHeadCommit() throws GitRepositoryException
      Description copied from interface: GitRepository
      Returns the current HEAD commit of the Git repository
      Returns:
      The current commit of the Git Repository
      Throws:
      GitRepositoryException - if the current commit cannot be determined
    • getTags

      public Map<String,GitTag> getTags() throws GitRepositoryException
      Description copied from interface: GitRepository
      Returns a map of tags available in this repository

      The 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

      public File 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

      public boolean isDirty(boolean ignoreUntracked) throws GitRepositoryException
      Description copied from interface: GitRepository
      Returns whether the worktree of the repository is in a clean state
      Parameters:
      ignoreUntracked - If true, 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

      public boolean isOnUnbornBranch() throws GitRepositoryException
      Description copied from interface: GitRepository
      Returns 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 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

      public void loadTag(GitTag tag) throws GitRepositoryException
      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

      public void walkCommits(AbstractCommitWalkAction action) throws GitRepositoryException
      Description copied from interface: GitRepository
      Runs the given action for all commits reachable from the current HEAD commit
      Parameters:
      action - The action to execute for each commit found
      Throws:
      GitRepositoryException - if an error occurs during walking through the commits