Interface Repository


  • public interface Repository
    This interface models coarse grained, implementation independent methods used by Nyx to access a Git repository.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void add​(Collection<String> paths)
      Adds the given paths to the staging area.
      Commit commit​(String message)
      Commits changes to the repository.
      Commit commit​(String message, Identity author, Identity committer)
      Commits changes to the repository.
      Commit commit​(Collection<String> paths, String message)
      Adds the given files to the staging area and commits changes to the repository.
      Commit commit​(Collection<String> paths, String message, Identity author, Identity committer)
      Adds the given files to the staging area and commits changes to the repository.
      Set<Tag> getCommitTags​(String commit)
      Returns a set of abjects representing all the tags for the given commit.
      String getLatestCommit()
      Returns the SHA-1 identifier of the last commit in the current branch.
      String getRootCommit()
      Returns the SHA-1 identifier of the first commit in the repository (the only commit with no parents).
      boolean isClean()
      Returns true if the repository is clean, which is when no differences exist between the working tree, the index, and the current HEAD.
      String push()
      Pushes local changes in the current branch to the default remote origin.
      String push​(String remote)
      Pushes local changes in the current branch to the given remote.
      Set<String> push​(Collection<String> remotes)
      Pushes local changes in the current branch to the given remotes.
      Tag tag​(String name)
      Tags the latest commit in the current branch with a tag with the given name.
      Tag tag​(String name, String message)
      Tags the latest commit in the current branch with a tag with the given name and optional message.
      Tag tag​(String name, String message, Identity tagger)
      Tags the latest commit in the current branch with a tag with the given name and optional message using the optional tagger identity.
      Tag tag​(String target, String name, String message, Identity tagger)
      Tags the object represented by the given SHA-1 with a tag with the given name and optional message using the optional tagger identity.
      void walkHistory​(String start, String end, CommitVisitor visitor)
      Browse the repository commit history using the given visitor to inspect each commit.
    • Method Detail

      • commit

        Commit commit​(String message)
               throws GitException
        Commits changes to the repository. Files to commit must be staged separately using add(Collection).
        Parameters:
        message - the commit message. Cannot be null.
        Returns:
        the object modelling the new commit that was created. Never null.
        Throws:
        GitException - in case some problem is encountered with the underlying Git repository, preventing to commit.
        See Also:
        add(Collection)
      • commit

        Commit commit​(String message,
                      Identity author,
                      Identity committer)
               throws GitException
        Commits changes to the repository. Files to commit must be staged separately using add(Collection).
        Parameters:
        message - the commit message. Cannot be null.
        author - the object modelling the commit author informations. It may be null, in which case the default for the repository will be used
        committer - the object modelling the committer informations. It may be null, in which case the default for the repository will be used
        Returns:
        the object modelling the new commit that was created. Never null.
        Throws:
        GitException - in case some problem is encountered with the underlying Git repository, preventing to commit.
        See Also:
        add(Collection)
      • commit

        Commit commit​(Collection<String> paths,
                      String message)
               throws GitException
        Adds the given files to the staging area and commits changes to the repository. This method is a shorthand for add(Collection) and commit(String).
        Parameters:
        paths - the file patterns of the contents to add to stage. Cannot be null or empty. The path "." represents all files in the working area so with that you can add all locally changed files.
        message - the commit message. Cannot be null.
        Returns:
        the object modelling the new commit that was created. Never null.
        Throws:
        GitException - in case some problem is encountered with the underlying Git repository, preventing to commit.
      • commit

        Commit commit​(Collection<String> paths,
                      String message,
                      Identity author,
                      Identity committer)
               throws GitException
        Adds the given files to the staging area and commits changes to the repository. This method is a shorthand for add(Collection) and commit(String, Identity, Identity).
        Parameters:
        paths - the file patterns of the contents to add to stage. Cannot be null or empty. The path "." represents all files in the working area so with that you can add all locally changed files.
        message - the commit message. Cannot be null.
        author - the object modelling the commit author informations. It may be null, in which case the default for the repository will be used
        committer - the object modelling the committer informations. It may be null, in which case the default for the repository will be used
        Returns:
        the object modelling the new commit that was created. Never null.
        Throws:
        GitException - in case some problem is encountered with the underlying Git repository, preventing to commit.
      • push

        String push()
             throws GitException
        Pushes local changes in the current branch to the default remote origin.
        Returns:
        the local name of the remotes that has been pushed
        Throws:
        GitException - in case some problem is encountered with the underlying Git repository, preventing to push.
      • push

        String push​(String remote)
             throws GitException
        Pushes local changes in the current branch to the given remote.
        Parameters:
        remote - the name of the remote to push to. If null or empty the default remote name (origin) is used.
        Returns:
        the local name of the remotes that has been pushed
        Throws:
        GitException - in case some problem is encountered with the underlying Git repository, preventing to push.
      • push

        Set<String> push​(Collection<String> remotes)
                  throws GitException
        Pushes local changes in the current branch to the given remotes.
        Parameters:
        remotes - the names of remotes to push to. If null or empty the default remote name (origin) is used.
        Returns:
        a collection with the local names of remotes that have been pushed
        Throws:
        GitException - in case some problem is encountered with the underlying Git repository, preventing to push.
      • tag

        Tag tag​(String name)
         throws GitException
        Tags the latest commit in the current branch with a tag with the given name. The resulting tag is lightweight.
        Parameters:
        name - the name of the tag. Cannot be null
        Returns:
        the object modelling the new tag that was created. Never null.
        Throws:
        GitException - in case some problem is encountered with the underlying Git repository, preventing to tag (i.e. when the tag name is null or there is already a tag with the given name in the repository).
      • tag

        Tag tag​(String name,
                String message)
         throws GitException
        Tags the latest commit in the current branch with a tag with the given name and optional message.
        Parameters:
        name - the name of the tag. Cannot be null
        message - the optional tag message. If null the new tag will be lightweight, otherwise it will be an annotated tag
        Returns:
        the object modelling the new tag that was created. Never null.
        Throws:
        GitException - in case some problem is encountered with the underlying Git repository, preventing to tag (i.e. when the tag name is null or there is already a tag with the given name in the repository).
      • tag

        Tag tag​(String name,
                String message,
                Identity tagger)
         throws GitException
        Tags the latest commit in the current branch with a tag with the given name and optional message using the optional tagger identity.
        Parameters:
        name - the name of the tag. Cannot be null
        message - the optional tag message. If null the new tag will be lightweight, otherwise it will be an annotated tag
        tagger - the optional identity of the tagger. If null Git defaults are used. If message is null this is ignored.
        Returns:
        the object modelling the new tag that was created. Never null.
        Throws:
        GitException - in case some problem is encountered with the underlying Git repository, preventing to tag (i.e. when the tag name is null or there is already a tag with the given name in the repository).
      • tag

        Tag tag​(String target,
                String name,
                String message,
                Identity tagger)
         throws GitException
        Tags the object represented by the given SHA-1 with a tag with the given name and optional message using the optional tagger identity.
        Parameters:
        target - the SHA-1 identifier of the object to tag. If null the latest commit in the current branch is tagged.
        name - the name of the tag. Cannot be null
        message - the optional tag message. If null the new tag will be lightweight, otherwise it will be an annotated tag
        tagger - the optional identity of the tagger. If null Git defaults are used. If message is null this is ignored.
        Returns:
        the object modelling the new tag that was created. Never null.
        Throws:
        GitException - in case some problem is encountered with the underlying Git repository, preventing to tag (i.e. when the tag name is null or there is already a tag with the given name in the repository).
      • walkHistory

        void walkHistory​(String start,
                         String end,
                         CommitVisitor visitor)
                  throws GitException
        Browse the repository commit history using the given visitor to inspect each commit. Commits are evaluated in Git's natural order, from the most recent to oldest.
        Parameters:
        start - the optional SHA-1 id of the commit to start from. If null the latest commit in the current branch (HEAD) is used. This can be a long or abbreviated SHA-1. If this commit cannot be resolved within the repository a GitException is thrown.
        end - the optional SHA-1 id of the commit to end with, included. If null the repository root commit is used (until the given visitor returns false). If this commit is not reachable from the start it will be ignored. This can be a long or abbreviated SHA-1. If this commit cannot be resolved within the repository a GitException is thrown.
        visitor - the visitor function that will receive commit data to evaluate. If null this method takes no action.
        Throws:
        GitException - in case some problem is encountered with the underlying Git repository, including when the repository has no commits yet or a given commit identifier cannot be resolved.
      • getLatestCommit

        String getLatestCommit()
                        throws GitException
        Returns the SHA-1 identifier of the last commit in the current branch.
        Returns:
        the SHA-1 identifier of the last commit in the current branch.
        Throws:
        GitException - in case some problem is encountered with the underlying Git repository, including when the repository has no commits yet or is in the 'detached HEAD' state.
      • getRootCommit

        String getRootCommit()
                      throws GitException
        Returns the SHA-1 identifier of the first commit in the repository (the only commit with no parents).
        Returns:
        the SHA-1 identifier of the first commit in the repository.
        Throws:
        GitException - in case some problem is encountered with the underlying Git repository, including when the repository has no commits yet or is in the 'detached HEAD' state.
      • getCommitTags

        Set<Tag> getCommitTags​(String commit)
                        throws GitException
        Returns a set of abjects representing all the tags for the given commit.
        Parameters:
        commit - the SHA-1 identifier of the commit to get the tags for. It can be a full or abbreviated SHA-1.
        Returns:
        the set of abjects representing all the tags for the given commit.
        Throws:
        GitException - in case some problem is encountered with the underlying Git repository.
      • isClean

        boolean isClean()
                 throws GitException
        Returns true if the repository is clean, which is when no differences exist between the working tree, the index, and the current HEAD.
        Returns:
        true if the repository is clean, false otherwise.
        Throws:
        GitException - in case some problem is encountered with the underlying Git repository, including when the repository has no commits yet or is in the 'detached HEAD' state.