Class CommitMsgHook

java.lang.Object
org.eclipse.jgit.hooks.GitHook<String>
org.eclipse.jgit.hooks.CommitMsgHook
All Implemented Interfaces:
Callable<String>

public class CommitMsgHook extends GitHook<String>
The commit-msg hook implementation. This hook is run before the commit and can reject the commit. It passes one argument to the hook script, which is the path to the COMMIT_MSG file, relative to the repository workTree.
Since:
4.0
  • Field Details

  • Constructor Details

    • CommitMsgHook

      protected CommitMsgHook(Repository repo, PrintStream outputStream)
      Constructor for CommitMsgHook

      This constructor will use the default error stream.

      Parameters:
      repo - The repository
      outputStream - The output stream the hook must use. null is allowed, in which case the hook will use System.out.
    • CommitMsgHook

      protected CommitMsgHook(Repository repo, PrintStream outputStream, PrintStream errorStream)
      Constructor for CommitMsgHook
      Parameters:
      repo - The repository
      outputStream - The output stream the hook must use. null is allowed, in which case the hook will use System.out.
      errorStream - The error stream the hook must use. null is allowed, in which case the hook will use System.err.
      Since:
      5.6
  • Method Details

    • call

      public String call() throws IOException, AbortedByHookException
      Description copied from class: GitHook

      Run the hook.

      Specified by:
      call in interface Callable<String>
      Specified by:
      call in class GitHook<String>
      Throws:
      IOException
      AbortedByHookException
    • getHookName

      public String getHookName()
      Description copied from class: GitHook
      Get name of the hook
      Specified by:
      getHookName in class GitHook<String>
      Returns:
      The name of the hook, which must not be null.
    • getParameters

      protected String[] getParameters()
      Override this method when needed to provide relevant parameters to the underlying hook script. The default implementation returns an empty array. This hook receives one parameter, which is the path to the file holding the current commit-msg, relative to the repository's work tree.
      Overrides:
      getParameters in class GitHook<String>
      Returns:
      The parameters the hook receives.
    • setCommitMessage

      public CommitMsgHook setCommitMessage(String commitMessage)
      It is mandatory to call this method with a non-null value before actually calling the hook.
      Parameters:
      commitMessage - The commit message before the hook has run.
      Returns:
      this for convenience.