Top Description Fields Constructors Methods
org.eclipse.jgit.hooks

public abstract Class GitHook<T>

extends Object
implements Callable<T>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Callable
Known Direct Subclasses
org.eclipse.jgit.hooks.PostCommitHook, org.eclipse.jgit.hooks.PreCommitHook, org.eclipse.jgit.hooks.PrePushHook, org.eclipse.jgit.hooks.CommitMsgHook
Type Parameters
<T>
the return type which is expected from call()
Imports
java.io.ByteArrayOutputStream, .IOException, .OutputStream, java.util.concurrent.Callable, org.eclipse.jgit.api.errors.AbortedByHookException, org.eclipse.jgit.lib.Repository, org.eclipse.jgit.util.FS, .ProcessResult, .SystemReader, org.eclipse.jgit.util.io.TeeOutputStream

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
5.11
See Also
Git Hooks on the git-scm official site

Field Summary

Modifier and TypeField and Description
private final OutputStream
errorStream

The error stream to be used by the hook.

private final OutputStream
outputStream

The output stream to be used by the hook.

private final Repository

Constructor Summary

AccessConstructor and Description
protected
GitHook(Repository repo, OutputStream
The output stream the hook must use. null is allowed, in which case the hook will use System.out.
outputStream
)

Constructor for GitHook.

protected
GitHook(Repository repo, OutputStream
The output stream the hook must use. null is allowed, in which case the hook will use System.out.
outputStream
,
OutputStream
The error stream the hook must use. null is allowed, in which case the hook will use System.err.
errorStream
)

Constructor for GitHook

Method Summary

Modifier and TypeMethod and Description
public abstract T
call()

Redeclares java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

protected void
doRun()

Runs the hook, without performing any validity checks.

protected OutputStream

Returns:

The error stream the hook must use. Never null, System.err is returned by default.
getErrorStream
()

Get error stream

public abstract String

Returns:

The name of the hook, which must not be null.
getHookName
()

Get name of the hook

protected OutputStream

Returns:

The output stream the hook must use. Never null, System.out is returned by default.
getOutputStream
()

Get output stream

protected String[]

Returns:

The parameters the hook receives.
getParameters
()

Override this method when needed to provide relevant parameters to the underlying hook script.

protected Repository

Returns:

The repository.
getRepository
()

Get the repository

protected String

Returns:

The parameters the hook receives.
getStdinArgs
()

Override to provide relevant arguments via stdin to the underlying hook script.

protected void
handleError(String
error message
message
,
final ProcessResult
The process result of the hook
result
)

Process that the hook exited with an error.

public boolean

Returns:

whether a native hook script is installed in the repository.
isNativeHookPresent
()

Check whether a 'native' (i.e. script) hook is installed in the repository.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

errorStreamback to summary
private final OutputStream errorStream

The error stream to be used by the hook.

outputStreamback to summary
private final OutputStream outputStream

The output stream to be used by the hook.

repoback to summary
private final Repository repo

Constructor Detail

GitHookback to summary
protected GitHook(Repository repo, OutputStream outputStream)

Constructor for GitHook.

This constructor will use stderr for the error stream.

Parameters
repo:Repository

a org.eclipse.jgit.lib.Repository object.

outputStream:OutputStream

The output stream the hook must use. null is allowed, in which case the hook will use System.out.

GitHookback to summary
protected GitHook(Repository repo, OutputStream outputStream, OutputStream errorStream)

Constructor for GitHook

Parameters
repo:Repository

a org.eclipse.jgit.lib.Repository object.

outputStream:OutputStream

The output stream the hook must use. null is allowed, in which case the hook will use System.out.

errorStream:OutputStream

The error stream the hook must use. null is allowed, in which case the hook will use System.err.

Method Detail

callback to summary
public abstract T call() throws IOException, AbortedByHookException

Redeclares java.util.concurrent.Callable.call.

Doc from java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

Run the hook.

Returns:T

computed result

Annotations
@Override
doRunback to summary
protected void doRun() throws AbortedByHookException, IOException

Runs the hook, without performing any validity checks.

Exceptions
AbortedByHookException:
If the underlying hook script exited with non-zero.
IOException:
if an IO error occurred
getErrorStreamback to summary
protected OutputStream getErrorStream()

Get error stream

Returns:OutputStream

The error stream the hook must use. Never null, System.err is returned by default.

getHookNameback to summary
public abstract String getHookName()

Get name of the hook

Returns:String

The name of the hook, which must not be null.

getOutputStreamback to summary
protected OutputStream getOutputStream()

Get output stream

Returns:OutputStream

The output stream the hook must use. Never null, System.out is returned by default.

getParametersback to summary
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:String[]

The parameters the hook receives.

getRepositoryback to summary
protected Repository getRepository()

Get the repository

Returns:Repository

The repository.

getStdinArgsback to summary
protected String getStdinArgs()

Override to provide relevant arguments via stdin to the underlying hook script. The default implementation returns null.

Returns:String

The parameters the hook receives.

handleErrorback to summary
protected void handleError(String message, final ProcessResult result) throws AbortedByHookException

Process that the hook exited with an error. This default implementation throws an AbortedByHookException. Hooks which need a different behavior can overwrite this method.

Parameters
message:String

error message

result:ProcessResult

The process result of the hook

Exceptions
AbortedByHookException:
When the hook should be aborted
Since
5.11
isNativeHookPresentback to summary
public boolean isNativeHookPresent()

Check whether a 'native' (i.e. script) hook is installed in the repository.

Returns:boolean

whether a native hook script is installed in the repository.

Since
4.11