Package org.eclipse.jgit.hooks
Class PreCommitHook
- java.lang.Object
-
- org.eclipse.jgit.hooks.PreCommitHook
-
-
Field Summary
Fields Modifier and Type Field Description protected PrintStream
errorStream
The error stream to be used by the hook.static String
NAME
The pre-commit hook name.protected PrintStream
outputStream
The output stream to be used by the hook.
-
Constructor Summary
Constructors Modifier Constructor Description protected
PreCommitHook(Repository repo, PrintStream outputStream)
Constructor for PreCommitHookprotected
PreCommitHook(Repository repo, PrintStream outputStream, PrintStream errorStream)
Constructor for PreCommitHook
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Void
call()
protected void
doRun()
Runs the hook, without performing any validity checks.protected PrintStream
getErrorStream()
Get error streamString
getHookName()
Get name of the hookprotected PrintStream
getOutputStream()
Get output streamprotected String[]
getParameters()
Override this method when needed to provide relevant parameters to the underlying hook script.protected Repository
getRepository()
Get the repositoryprotected String
getStdinArgs()
Override to provide relevant arguments via stdin to the underlying hook script.boolean
isNativeHookPresent()
Check whether a 'native' (i.e.
-
-
-
Field Detail
-
NAME
public static final String NAME
The pre-commit hook name.- See Also:
- Constant Field Values
-
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 PreCommitHookThis constructor will use the default error stream.
- Parameters:
repo
- The repositoryoutputStream
- The output stream the hook must use.null
is allowed, in which case the hook will useSystem.out
.
-
PreCommitHook
protected PreCommitHook(Repository repo, PrintStream outputStream, PrintStream errorStream)
Constructor for PreCommitHook- Parameters:
repo
- The repositoryoutputStream
- The output stream the hook must use.null
is allowed, in which case the hook will useSystem.out
.errorStream
- The error stream the hook must use.null
is allowed, in which case the hook will useSystem.err
.- Since:
- 5.6
-
-
Method Detail
-
call
public Void call() throws IOException, AbortedByHookException
Run the hook.
- Specified by:
call
in interfaceCallable<Void>
- Throws:
IOException
AbortedByHookException
-
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 returnsnull
.- 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.
-
doRun
protected void doRun() throws AbortedByHookException
Runs the hook, without performing any validity checks.- Throws:
AbortedByHookException
- If the underlying hook script exited with non-zero.
-
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
-
-