Class CommitCommand

    • Constructor Detail

      • CommitCommand

        protected CommitCommand​(Repository repo)
        Constructor for CommitCommand
        Parameters:
        repo - the Repository
    • Method Detail

      • setMessage

        public CommitCommand setMessage​(String message)
        Set the commit message
        Parameters:
        message - the commit message used for the commit
        Returns:
        this
      • setAllowEmpty

        public CommitCommand setAllowEmpty​(boolean allowEmpty)
        Set whether to allow to create an empty commit
        Parameters:
        allowEmpty - whether it should be allowed to create a commit which has the same tree as it's sole predecessor (a commit which doesn't change anything). By default when creating standard commits (without specifying paths) JGit allows to create such commits. When this flag is set to false an attempt to create an "empty" standard commit will lead to an EmptyCommitException.

        By default when creating a commit containing only specified paths an attempt to create an empty commit leads to a JGitInternalException. By setting this flag to true this exception will not be thrown.

        Returns:
        this
        Since:
        4.2
      • getMessage

        public String getMessage()
        Get the commit message
        Returns:
        the commit message used for the commit
      • setCommitter

        public CommitCommand setCommitter​(PersonIdent committer)
        Sets the committer for this commit. If no committer is explicitly specified because this method is never called or called with null value then the committer will be deduced from config info in repository, with current time.
        Parameters:
        committer - the committer used for the commit
        Returns:
        this
      • setCommitter

        public CommitCommand setCommitter​(String name,
                                          String email)
        Sets the committer for this commit. If no committer is explicitly specified because this method is never called then the committer will be deduced from config info in repository, with current time.
        Parameters:
        name - the name of the committer used for the commit
        email - the email of the committer used for the commit
        Returns:
        this
      • getCommitter

        public PersonIdent getCommitter()
        Get the committer
        Returns:
        the committer used for the commit. If no committer was specified null is returned and the default PersonIdent of this repo is used during execution of the command
      • setAuthor

        public CommitCommand setAuthor​(PersonIdent author)
        Sets the author for this commit. If no author is explicitly specified because this method is never called or called with null value then the author will be set to the committer or to the original author when amending.
        Parameters:
        author - the author used for the commit
        Returns:
        this
      • setAuthor

        public CommitCommand setAuthor​(String name,
                                       String email)
        Sets the author for this commit. If no author is explicitly specified because this method is never called then the author will be set to the committer or to the original author when amending.
        Parameters:
        name - the name of the author used for the commit
        email - the email of the author used for the commit
        Returns:
        this
      • getAuthor

        public PersonIdent getAuthor()
        Get the author
        Returns:
        the author used for the commit. If no author was specified null is returned and the default PersonIdent of this repo is used during execution of the command
      • setAll

        public CommitCommand setAll​(boolean all)
        If set to true the Commit command automatically stages files that have been modified and deleted, but new files not known by the repository are not affected. This corresponds to the parameter -a on the command line.
        Parameters:
        all - whether to auto-stage all files that have been modified and deleted
        Returns:
        this
        Throws:
        JGitInternalException - in case of an illegal combination of arguments/ options
      • setAmend

        public CommitCommand setAmend​(boolean amend)
        Used to amend the tip of the current branch. If set to true, the previous commit will be amended. This is equivalent to --amend on the command line.
        Parameters:
        amend - whether to amend the tip of the current branch
        Returns:
        this
      • setOnly

        public CommitCommand setOnly​(String only)
        Commit dedicated path only.

        This method can be called several times to add multiple paths. Full file paths are supported as well as directory paths; in the latter case this commits all files/directories below the specified path.

        Parameters:
        only - path to commit (with / as separator)
        Returns:
        this
      • setInsertChangeId

        public CommitCommand setInsertChangeId​(boolean insertChangeId)
        If set to true a change id will be inserted into the commit message An existing change id is not replaced. An initial change id (I000...) will be replaced by the change id.
        Parameters:
        insertChangeId - whether to insert a change id
        Returns:
        this
      • setReflogComment

        public CommitCommand setReflogComment​(String reflogComment)
        Override the message written to the reflog
        Parameters:
        reflogComment - the comment to be written into the reflog or null to specify that no reflog should be written
        Returns:
        this
      • setNoVerify

        public CommitCommand setNoVerify​(boolean noVerify)
        Sets the noVerify option on this commit command.

        Both the pre-commit and commit-msg hooks can block a commit by their return value; setting this option to true will bypass these two hooks.

        Parameters:
        noVerify - Whether this commit should be verified by the pre-commit and commit-msg hooks.
        Returns:
        this
        Since:
        3.7
      • setHookOutputStream

        public CommitCommand setHookOutputStream​(PrintStream hookStdOut)
        Set the output stream for all hook scripts executed by this command (pre-commit, commit-msg, post-commit). If not set it defaults to System.out.
        Parameters:
        hookStdOut - the output stream for hook scripts executed by this command
        Returns:
        this
        Since:
        3.7
      • setHookErrorStream

        public CommitCommand setHookErrorStream​(PrintStream hookStdErr)
        Set the error stream for all hook scripts executed by this command (pre-commit, commit-msg, post-commit). If not set it defaults to System.err.
        Parameters:
        hookStdErr - the error stream for hook scripts executed by this command
        Returns:
        this
        Since:
        5.6
      • setHookOutputStream

        public CommitCommand setHookOutputStream​(String hookName,
                                                 PrintStream hookStdOut)
        Set the output stream for a selected hook script executed by this command (pre-commit, commit-msg, post-commit). If not set it defaults to System.out.
        Parameters:
        hookName - name of the hook to set the output stream for
        hookStdOut - the output stream to use for the selected hook
        Returns:
        this
        Since:
        4.5
      • setHookErrorStream

        public CommitCommand setHookErrorStream​(String hookName,
                                                PrintStream hookStdErr)
        Set the error stream for a selected hook script executed by this command (pre-commit, commit-msg, post-commit). If not set it defaults to System.err.
        Parameters:
        hookName - name of the hook to set the output stream for
        hookStdErr - the output stream to use for the selected hook
        Returns:
        this
        Since:
        5.6
      • setSigningKey

        public CommitCommand setSigningKey​(String signingKey)
        Sets the signing key

        Per spec of user.signingKey: this will be sent to the GPG program as is, i.e. can be anything supported by the GPG program.

        Note, if none was set or null is specified a default will be obtained from the configuration.

        Parameters:
        signingKey - signing key (maybe null)
        Returns:
        this
        Since:
        5.3
      • setSign

        public CommitCommand setSign​(Boolean sign)
        Sets whether the commit should be signed.
        Parameters:
        sign - true to sign, false to not sign and null for default behavior (read from configuration)
        Returns:
        this
        Since:
        5.3
      • setGpgSigner

        public CommitCommand setGpgSigner​(GpgSigner signer)
        Sets the GpgSigner to use if the commit is to be signed.
        Parameters:
        signer - to use; if null, the default signer will be used
        Returns:
        this
        Since:
        5.11
      • setGpgConfig

        public CommitCommand setGpgConfig​(GpgConfig config)
        Sets an external GpgConfig to use. Whether it will be used is at the discretion of the setGpgSigner(GpgSigner).
        Parameters:
        config - to set; if null, the config will be loaded from the git config of the repository
        Returns:
        this
        Since:
        5.11
      • setCredentialsProvider

        public CommitCommand setCredentialsProvider​(CredentialsProvider credentialsProvider)
        Parameters:
        credentialsProvider - the provider to use when querying for credentials (eg., during signing)
        Returns:
        this
        Since:
        6.0