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

public Class PrePushHook

extends GitHook<String>
Class Inheritance
Imports
java.io.IOException, .PrintStream, java.util.Collection, org.eclipse.jgit.api.errors.AbortedByHookException, org.eclipse.jgit.lib.ObjectId, .Repository, org.eclipse.jgit.transport.RemoteRefUpdate

The pre-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

Modifier and TypeField and Description
private boolean
public static final String
NAME

Constant indicating the name of the pre-push hook.

private String
private String
private String

Constructor Summary

AccessConstructor and Description
protected
PrePushHook(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 PrePushHook

This constructor will use the default error stream.

protected
PrePushHook(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 PrePushHook

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
canRun
()

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.

protected String

Returns:

remote name or null
getRemoteName
()

Get remote name

protected String
getStdinArgs()

Overrides org.eclipse.jgit.hooks.GitHook.getStdinArgs.

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

protected boolean

Returns:

true if the push is a dry run, false otherwise
isDryRun
()

Tells whether the push is a dry run.

public void
setDryRun(boolean
true if the push is a dry run, false otherwise
dryRun
)

Sets whether the push is a dry run.

public void
setRefs(Collection<RemoteRefUpdate>
a collection of RemoteRefUpdates
toRefs
)

Set Refs

public void
setRemoteLocation(String
a remote location
location
)

Set remote location

public void
setRemoteName(String
remote name
name
)

Set remote name

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

Field Detail

dryRunback to summary
private boolean dryRun
NAMEback to summary
public static final String NAME

Constant indicating the name of the pre-push hook.

refsback to summary
private String refs
remoteLocationback to summary
private String remoteLocation
remoteNameback to summary
private String remoteName

Constructor Detail

PrePushHookback to summary
protected PrePushHook(Repository repo, PrintStream outputStream)

Constructor for PrePushHook

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.

PrePushHookback to summary
protected PrePushHook(Repository repo, PrintStream outputStream, PrintStream errorStream)

Constructor for PrePushHook

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

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 two parameters, which is the name and the location of the remote repository.

Returns:String[]

The parameters the hook receives.

Annotations
@Override
getRemoteNameback to summary
protected String getRemoteName()

Get remote name

Returns:String

remote name or null

Since
4.11
getStdinArgsback to summary
protected String getStdinArgs()

Overrides org.eclipse.jgit.hooks.GitHook.getStdinArgs.

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

Annotations
@Override
isDryRunback to summary
protected boolean isDryRun()

Tells whether the push is a dry run.

Returns:boolean

true if the push is a dry run, false otherwise

Since
6.2
setDryRunback to summary
public void setDryRun(boolean dryRun)

Sets whether the push is a dry run.

Parameters
dryRun:boolean

true if the push is a dry run, false otherwise

Since
6.2
setRefsback to summary
public void setRefs(Collection<RemoteRefUpdate> toRefs)

Set Refs

Parameters
toRefs:Collection<RemoteRefUpdate>

a collection of RemoteRefUpdates

setRemoteLocationback to summary
public void setRemoteLocation(String location)

Set remote location

Parameters
location:String

a remote location

setRemoteNameback to summary
public void setRemoteName(String name)

Set remote name

Parameters
name:String

remote name