Interface GitRepository

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void check()
      Checks whether the Git repository is accessible.
      void close()
      Closes any resources that are needed to access this repository
      GitTagDescription describe()
      Describes the current Git commit like git describe does
      String getAbbreviatedCommitId()
      Returns the abbreviated commit SHA ID of the current Git commit
      String getAbbreviatedCommitId​(GitCommit commit)
      Returns the abbreviated commit SHA ID of the given Git commit
      String getBranch()
      Returns the currently checked out branch of the Git repository
      GitCommit getHeadCommit()
      Returns the current HEAD commit of the Git repository
      String getHeadRef()
      Returns the Git ref used as the HEAD commit of the repository
      MailMap getMailMap()
      Returns a MailMap object that holds information from Git's .mailmap file
      Map<String,​GitTag> getTags()
      Returns a map of tags available in this repository
      File getWorkTree()
      Returns the worktree of the repository
      boolean isChecked()
      Returns whether this repository instance has been checked
      boolean isDirty​(boolean ignoreUntracked)
      Returns whether the worktree of the repository is in a clean state
      boolean isOnUnbornBranch()
      Returns whether this repository is currently on an “unborn” branch An “unborn” branch is a branch without any actual commits.
      void loadTag​(GitTag tag)
      Load tag meta data
      void setHeadRef​(String headRef)
      Sets the Git ref to use as the HEAD commit of the repository
      <T extends CommitWalkAction>
      T
      walkCommits​(T action)
      Runs the given action for all commits reachable from the current HEAD commit
    • Method Detail

      • close

        void close()
        Closes any resources that are needed to access this repository
        Specified by:
        close in interface AutoCloseable
      • getAbbreviatedCommitId

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

        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
      • getHeadRef

        String getHeadRef()
        Returns the Git ref used as the HEAD commit of the repository
        Returns:
        The ref used as HEAD
      • getMailMap

        MailMap getMailMap()
                    throws GitRepositoryException
        Returns a MailMap object that holds information from Git's .mailmap file
        Returns:
        A .mailmap representation or null if none exits
        Throws:
        GitRepositoryException - if the .mailmap file cannot be read or parsed
      • getTags

        Map<String,​GitTag> getTags()
                                  throws GitRepositoryException
        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

        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:
        check()
      • isDirty

        boolean isDirty​(boolean ignoreUntracked)
                 throws GitRepositoryException
        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

        boolean isOnUnbornBranch()
                          throws GitRepositoryException
        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
      • setHeadRef

        void setHeadRef​(String headRef)
        Sets the Git ref to use as the HEAD commit of the repository
        Parameters:
        headRef - The ref to use as HEAD
      • walkCommits

        <T extends CommitWalkAction> T walkCommits​(T action)
                                            throws GitRepositoryException
        Runs the given action for all commits reachable from the current HEAD commit
        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