Package org.eclipse.jgit.hooks
Class PrePushHook
- java.lang.Object
-
- org.eclipse.jgit.hooks.GitHook<java.lang.String>
-
- org.eclipse.jgit.hooks.PrePushHook
-
- All Implemented Interfaces:
java.util.concurrent.Callable<java.lang.String>
- Direct Known Subclasses:
LfsPrePushHook
public class PrePushHook extends GitHook<java.lang.String>
Thepre-push
hook implementation. The pre-push hook runs during git push, after the remote refs have been updated but before any objects have been transferred.- Since:
- 4.2
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
NAME
Constant indicating the name of the pre-push hook.private java.lang.String
refs
private java.lang.String
remoteLocation
private java.lang.String
remoteName
-
Fields inherited from class org.eclipse.jgit.hooks.GitHook
errorStream, outputStream
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
PrePushHook(Repository repo, java.io.PrintStream outputStream)
Constructor for PrePushHookprotected
PrePushHook(Repository repo, java.io.PrintStream outputStream, java.io.PrintStream errorStream)
Constructor for PrePushHook
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
call()
private boolean
canRun()
java.lang.String
getHookName()
Get name of the hookprotected java.lang.String[]
getParameters()
Override this method when needed to provide relevant parameters to the underlying hook script.protected java.lang.String
getRemoteName()
Get remote nameprotected java.lang.String
getStdinArgs()
Override to provide relevant arguments via stdin to the underlying hook script.void
setRefs(java.util.Collection<RemoteRefUpdate> toRefs)
Set Refsvoid
setRemoteLocation(java.lang.String location)
Set remote locationvoid
setRemoteName(java.lang.String name)
Set remote name-
Methods inherited from class org.eclipse.jgit.hooks.GitHook
doRun, getErrorStream, getOutputStream, getRepository, isNativeHookPresent
-
-
-
-
Field Detail
-
NAME
public static final java.lang.String NAME
Constant indicating the name of the pre-push hook.- See Also:
- Constant Field Values
-
remoteName
private java.lang.String remoteName
-
remoteLocation
private java.lang.String remoteLocation
-
refs
private java.lang.String refs
-
-
Constructor Detail
-
PrePushHook
protected PrePushHook(Repository repo, java.io.PrintStream outputStream)
Constructor for PrePushHookThis 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
.
-
PrePushHook
protected PrePushHook(Repository repo, java.io.PrintStream outputStream, java.io.PrintStream errorStream)
Constructor for PrePushHook- 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
-
getStdinArgs
protected java.lang.String getStdinArgs()
Override to provide relevant arguments via stdin to the underlying hook script. The default implementation returnsnull
.- Overrides:
getStdinArgs
in classGitHook<java.lang.String>
- Returns:
- The parameters the hook receives.
-
call
public java.lang.String call() throws java.io.IOException, AbortedByHookException
Run the hook.
- Specified by:
call
in interfacejava.util.concurrent.Callable<java.lang.String>
- Specified by:
call
in classGitHook<java.lang.String>
- Throws:
java.io.IOException
AbortedByHookException
-
canRun
private boolean canRun()
- Returns:
true
-
getHookName
public java.lang.String getHookName()
Get name of the hook- Specified by:
getHookName
in 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 two parameters, which is the name and the location of the remote repository.
- Overrides:
getParameters
in classGitHook<java.lang.String>
- Returns:
- The parameters the hook receives.
-
setRemoteName
public void setRemoteName(java.lang.String name)
Set remote name- Parameters:
name
- remote name
-
getRemoteName
protected java.lang.String getRemoteName()
Get remote name- Returns:
- remote name or null
- Since:
- 4.11
-
setRemoteLocation
public void setRemoteLocation(java.lang.String location)
Set remote location- Parameters:
location
- a remote location
-
setRefs
public void setRefs(java.util.Collection<RemoteRefUpdate> toRefs)
Set Refs- Parameters:
toRefs
- a collection ofRemoteRefUpdate
s
-
-