Package org.eclipse.jgit.hooks
Class GitHook<T>
- java.lang.Object
-
- org.eclipse.jgit.hooks.GitHook<T>
-
- Type Parameters:
T
- the return type which is expected fromcall()
- All Implemented Interfaces:
java.util.concurrent.Callable<T>
- Direct Known Subclasses:
CommitMsgHook
,PostCommitHook
,PreCommitHook
,PrePushHook
abstract class GitHook<T> extends java.lang.Object implements java.util.concurrent.Callable<T>
Git can fire off custom scripts when certain important actions occur. These custom scripts are called "hooks". There are two groups of hooks: client-side (that run on local operations such as committing and merging), and server-side (that run on network operations such as receiving pushed commits). This is the abstract super-class of the different hook implementations in JGit.- Since:
- 4.0
- See Also:
- Git Hooks on the git-scm official site
-
-
Field Summary
Fields Modifier and Type Field Description protected java.io.PrintStream
errorStream
The error stream to be used by the hook.protected java.io.PrintStream
outputStream
The output stream to be used by the hook.private Repository
repo
-
Constructor Summary
Constructors Modifier Constructor Description protected
GitHook(Repository repo, java.io.PrintStream outputStream)
Constructor for GitHook.protected
GitHook(Repository repo, java.io.PrintStream outputStream, java.io.PrintStream errorStream)
Constructor for GitHook
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract T
call()
protected void
doRun()
Runs the hook, without performing any validity checks.protected java.io.PrintStream
getErrorStream()
Get error streamabstract java.lang.String
getHookName()
Get name of the hookprotected java.io.PrintStream
getOutputStream()
Get output streamprotected java.lang.String[]
getParameters()
Override this method when needed to provide relevant parameters to the underlying hook script.protected Repository
getRepository()
Get the repositoryprotected java.lang.String
getStdinArgs()
Override to provide relevant arguments via stdin to the underlying hook script.boolean
isNativeHookPresent()
Check whether a 'native' (i.e.
-
-
-
Field Detail
-
repo
private final Repository repo
-
outputStream
protected final java.io.PrintStream outputStream
The output stream to be used by the hook.
-
errorStream
protected final java.io.PrintStream errorStream
The error stream to be used by the hook.
-
-
Constructor Detail
-
GitHook
protected GitHook(Repository repo, java.io.PrintStream outputStream)
Constructor for GitHook.This constructor will use stderr for the error stream.
- Parameters:
repo
- aRepository
object.outputStream
- The output stream the hook must use.null
is allowed, in which case the hook will useSystem.out
.
-
GitHook
protected GitHook(Repository repo, java.io.PrintStream outputStream, java.io.PrintStream errorStream)
Constructor for GitHook- Parameters:
repo
- aRepository
object.outputStream
- 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
.
-
-
Method Detail
-
call
public abstract T call() throws java.io.IOException, AbortedByHookException
Run the hook.
- Specified by:
call
in interfacejava.util.concurrent.Callable<T>
- Throws:
java.io.IOException
AbortedByHookException
-
getHookName
public abstract java.lang.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 java.lang.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 java.lang.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 java.io.PrintStream getOutputStream()
Get output stream- Returns:
- The output stream the hook must use. Never
null
,System.out
is returned by default.
-
getErrorStream
protected java.io.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
-
-