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

public Class CommitMsgHook

extends GitHook<String>
Class Inheritance
Imports
java.io.File, .IOException, .PrintStream, org.eclipse.jgit.api.errors.AbortedByHookException, org.eclipse.jgit.lib.Constants, .Repository

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 Summary

Modifier and TypeField and Description
private String
commitMessage

The commit message.

public static final String
NAME

Constant indicating the name of the commit-smg hook.

Constructor Summary

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

Constructor for CommitMsgHook

This constructor will use the default error stream.

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

Constructor for CommitMsgHook

Method Summary

Modifier and TypeMethod and Description
public String
call()

Implements abstract org.eclipse.jgit.hooks.GitHook.call.

Implements java.util.concurrent.Callable.call.

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

private boolean

Returns:

true if and only if the path to the message commit file is not null (which would happen in a bare repository) and the commit message is also not null.
canRun
()

private String

Returns:

The path to the commit edit message file relative to the repository's work tree, or null if the repository is bare.
getCommitEditMessageFilePath
()

public String
getHookName()

Implements abstract org.eclipse.jgit.hooks.GitHook.getHookName.

Get name of the hook

protected String[]
getParameters()

Overrides org.eclipse.jgit.hooks.GitHook.getParameters.

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

public CommitMsgHook

Returns:

this for convenience.
setCommitMessage
(String
The commit message before the hook has run.
commitMessage
)

It is mandatory to call this method with a non-null value before actually calling the hook.

Inherited from org.eclipse.jgit.hooks.GitHook:
doRungetErrorStreamgetOutputStreamgetRepositorygetStdinArgshandleErrorisNativeHookPresent

Field Detail

commitMessageback to summary
private String commitMessage

The commit message.

NAMEback to summary
public static final String NAME

Constant indicating the name of the commit-smg hook.

Constructor Detail

CommitMsgHookback to summary
protected CommitMsgHook(Repository repo, PrintStream outputStream)

Constructor for CommitMsgHook

This constructor will use the default error stream.

Parameters
repo:Repository

The repository

outputStream:PrintStream

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

CommitMsgHookback to summary
protected CommitMsgHook(Repository repo, PrintStream outputStream, PrintStream errorStream)

Constructor for CommitMsgHook

Parameters
repo:Repository

The repository

outputStream:PrintStream

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

errorStream:PrintStream

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

Since
5.6

Method Detail

callback to summary
public String call() throws IOException, AbortedByHookException

Implements abstract org.eclipse.jgit.hooks.GitHook.call.

Implements java.util.concurrent.Callable.call.

Doc from org.eclipse.jgit.hooks.GitHook.call.

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

Run the hook.

Returns:String

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

computed result

Annotations
@Override
canRunback to summary
private boolean canRun()
Returns:boolean

true if and only if the path to the message commit file is not null (which would happen in a bare repository) and the commit message is also not null.

getCommitEditMessageFilePathback to summary
private String getCommitEditMessageFilePath()
Returns:String

The path to the commit edit message file relative to the repository's work tree, or null if the repository is bare.

getHookNameback to summary
public String getHookName()

Implements abstract org.eclipse.jgit.hooks.GitHook.getHookName.

Doc from org.eclipse.jgit.hooks.GitHook.getHookName.

Get name of the hook

Returns:String

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

Annotations
@Override
getParametersback to summary
protected String[] getParameters()

Overrides org.eclipse.jgit.hooks.GitHook.getParameters.

Doc from org.eclipse.jgit.hooks.GitHook.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.

Returns:String[]

The parameters the hook receives.

Annotations
@Override
setCommitMessageback to summary
public CommitMsgHook setCommitMessage(String commitMessage)

It is mandatory to call this method with a non-null value before actually calling the hook.

Parameters
commitMessage:String

The commit message before the hook has run.

Returns:CommitMsgHook

this for convenience.