Class PreCommitHook

  • All Implemented Interfaces:
    Callable<Void>

    public class PreCommitHook
    extends Object
    The pre-commit hook implementation. This hook is run before the commit and can reject the commit.
    Since:
    4.0
    • Field Detail

      • outputStream

        protected final PrintStream outputStream
        The output stream to be used by the hook.
      • errorStream

        protected final PrintStream errorStream
        The error stream to be used by the hook.
    • Constructor Detail

      • PreCommitHook

        protected PreCommitHook​(Repository repo,
                                PrintStream outputStream)
        Constructor for PreCommitHook

        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.
      • PreCommitHook

        protected PreCommitHook​(Repository repo,
                                PrintStream outputStream,
                                PrintStream errorStream)
        Constructor for PreCommitHook
        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 Detail

      • getHookName

        public String getHookName()
        Get name of the hook
        Returns:
        The name of the hook, which must not be null.
      • getRepository

        protected Repository getRepository()
        Get the repository
        Returns:
        The repository.
      • 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.
        Returns:
        The parameters the hook receives.
      • getStdinArgs

        protected String getStdinArgs()
        Override to provide relevant arguments via stdin to the underlying hook script. The default implementation returns null.
        Returns:
        The parameters the hook receives.
      • getOutputStream

        protected PrintStream getOutputStream()
        Get output stream
        Returns:
        The output stream the hook must use. Never null, System.out is returned by default.
      • getErrorStream

        protected PrintStream getErrorStream()
        Get error stream
        Returns:
        The error stream the hook must use. Never null, System.err is returned by default.
      • isNativeHookPresent

        public boolean isNativeHookPresent()
        Check whether a 'native' (i.e. script) hook is installed in the repository.
        Returns:
        whether a native hook script is installed in the repository.
        Since:
        4.11