Package org.eclipse.jgit.hooks
Class CommitMsgHook
- java.lang.Object
-
- org.eclipse.jgit.hooks.GitHook<java.lang.String>
-
- org.eclipse.jgit.hooks.CommitMsgHook
-
- All Implemented Interfaces:
java.util.concurrent.Callable<java.lang.String>
public class CommitMsgHook extends GitHook<java.lang.String>
Thecommit-msghook 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
Fields Modifier and Type Field Description private java.lang.StringcommitMessageThe commit message.static java.lang.StringNAMEConstant indicating the name of the commit-smg hook.
-
Constructor Summary
Constructors Modifier Constructor Description protectedCommitMsgHook(Repository repo, java.io.PrintStream outputStream)Constructor for CommitMsgHookprotectedCommitMsgHook(Repository repo, java.io.PrintStream outputStream, java.io.PrintStream errorStream)Constructor for CommitMsgHook
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringcall()private booleancanRun()private java.lang.StringgetCommitEditMessageFilePath()java.lang.StringgetHookName()Get name of the hookprotected java.lang.String[]getParameters()Override this method when needed to provide relevant parameters to the underlying hook script.CommitMsgHooksetCommitMessage(java.lang.String commitMessage)It is mandatory to call this method with a non-null value before actually calling the hook.-
Methods inherited from class org.eclipse.jgit.hooks.GitHook
doRun, getErrorStream, getOutputStream, getRepository, getStdinArgs, handleError, isNativeHookPresent
-
-
-
-
Field Detail
-
NAME
public static final java.lang.String NAME
Constant indicating the name of the commit-smg hook.- See Also:
- Constant Field Values
-
commitMessage
private java.lang.String commitMessage
The commit message.
-
-
Constructor Detail
-
CommitMsgHook
protected CommitMsgHook(Repository repo, java.io.PrintStream outputStream)
Constructor for CommitMsgHookThis constructor will use the default error stream.
- Parameters:
repo- The repositoryoutputStream- The output stream the hook must use.nullis allowed, in which case the hook will useSystem.out.
-
CommitMsgHook
protected CommitMsgHook(Repository repo, java.io.PrintStream outputStream, java.io.PrintStream errorStream)
Constructor for CommitMsgHook- Parameters:
repo- The repositoryoutputStream- The output stream the hook must use.nullis allowed, in which case the hook will useSystem.out.errorStream- The error stream the hook must use.nullis allowed, in which case the hook will useSystem.err.- Since:
- 5.6
-
-
Method Detail
-
call
public java.lang.String call() throws java.io.IOException, AbortedByHookExceptionRun the hook.
- Specified by:
callin interfacejava.util.concurrent.Callable<java.lang.String>- Specified by:
callin classGitHook<java.lang.String>- Throws:
java.io.IOExceptionAbortedByHookException
-
canRun
private boolean canRun()
- Returns:
trueif 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.
-
getHookName
public java.lang.String getHookName()
Get name of the hook- Specified by:
getHookNamein classGitHook<java.lang.String>- Returns:
- The name of the hook, which must not be
null.
-
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. This hook receives one parameter, which is the path to the file holding the current commit-msg, relative to the repository's work tree.- Overrides:
getParametersin classGitHook<java.lang.String>- Returns:
- The parameters the hook receives.
-
getCommitEditMessageFilePath
private java.lang.String getCommitEditMessageFilePath()
- Returns:
- The path to the commit edit message file relative to the repository's work tree, or null if the repository is bare.
-
setCommitMessage
public CommitMsgHook setCommitMessage(java.lang.String commitMessage)
It is mandatory to call this method with a non-null value before actually calling the hook.- Parameters:
commitMessage- The commit message before the hook has run.- Returns:
thisfor convenience.
-
-