Class JGitRepository

    • Constructor Detail

      • JGitRepository

        JGitRepository()
        Creates a new empty instance
      • 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 Detail

      • close

        public void close()
        Closes any resources that are needed to access this repository

        Closes JGit's repository instance.

        See Also:
        Repository.close()
      • 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
      • findTagCandidates

        private Collection<JGitTagCandidate> findTagCandidates​(RevWalk revWalk,
                                                               Map<String,​GitTag> tagCommits,
                                                               RevFlagSet allFlags)
                                                        throws RevWalkException
        Find up to 10 tag candidates in the current branch. One of these should be the latest tag.
        Parameters:
        revWalk - Repository information
        tagCommits - Map of commits that are associated with a tag
        allFlags - All flags that have been set so far
        Returns:
        A collection of tag candidates
        Throws:
        RevWalkException - if there’s an error during the rev walk
      • correctDistance

        private void correctDistance​(RevWalk revWalk,
                                     JGitTagCandidate candidate,
                                     RevFlagSet allFlags)
                              throws RevWalkException
        Correct the distance for all tag candidates. We have to check all branches to get the correct distance at the end.
        Parameters:
        revWalk - Repository information
        candidate - Collection of tag candidates
        allFlags - All flags that have been set so far
        Throws:
        RevWalkException - if there’s an error during the rev walk
      • 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
      • getRepositoryBuilder

        FileRepositoryBuilder getRepositoryBuilder()
        Creates a new JGit FileRepositoryBuilder instance
        Returns:
        A new repository builder
      • 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:
        GitRepository.check()
      • 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
      • walkCommits

        public <T extends CommitWalkAction> T walkCommits​(T action)
                                                   throws GitRepositoryException
        Description copied from interface: GitRepository
        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
      • getRevWalk

        RevWalk getRevWalk()
        Returns:
        A new JGit RevWalk instance for this repository