Class PrePushHook

java.lang.Object
org.eclipse.jgit.hooks.GitHook<String>
org.eclipse.jgit.hooks.PrePushHook
All Implemented Interfaces:
Callable<String>
Direct Known Subclasses:
LfsPrePushHook

public class PrePushHook extends GitHook<String>
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 Details

    • NAME

      public static final String NAME
      Constant indicating the name of the pre-push hook.
      See Also:
    • remoteName

      private String remoteName
    • remoteLocation

      private String remoteLocation
    • refs

      private String refs
  • Constructor Details

    • PrePushHook

      protected PrePushHook(Repository repo, PrintStream outputStream)
      Constructor for PrePushHook

      This constructor will use the default error stream.

      Parameters:
      repo - The repository
      outputStream - The output stream the hook must use. null is allowed, in which case the hook will use System.out.
    • PrePushHook

      protected PrePushHook(Repository repo, PrintStream outputStream, PrintStream errorStream)
      Constructor for PrePushHook
      Parameters:
      repo - The repository
      outputStream - The output stream the hook must use. null is allowed, in which case the hook will use System.out.
      errorStream - The error stream the hook must use. null is allowed, in which case the hook will use System.err.
      Since:
      5.6
  • Method Details

    • getStdinArgs

      protected String getStdinArgs()
      Override to provide relevant arguments via stdin to the underlying hook script. The default implementation returns null.
      Overrides:
      getStdinArgs in class GitHook<String>
      Returns:
      The parameters the hook receives.
    • call

      public String call() throws IOException, AbortedByHookException

      Run the hook.

      Specified by:
      call in interface Callable<String>
      Specified by:
      call in class GitHook<String>
      Throws:
      IOException
      AbortedByHookException
    • canRun

      private boolean canRun()
      Returns:
      true
    • getHookName

      public String getHookName()
      Get name of the hook
      Specified by:
      getHookName in class GitHook<String>
      Returns:
      The name of the hook, which must not be null.
    • getParameters

      protected 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 class GitHook<String>
      Returns:
      The parameters the hook receives.
    • setRemoteName

      public void setRemoteName(String name)
      Set remote name
      Parameters:
      name - remote name
    • getRemoteName

      protected String getRemoteName()
      Get remote name
      Returns:
      remote name or null
      Since:
      4.11
    • setRemoteLocation

      public void setRemoteLocation(String location)
      Set remote location
      Parameters:
      location - a remote location
    • setRefs

      public void setRefs(Collection<RemoteRefUpdate> toRefs)
      Set Refs
      Parameters:
      toRefs - a collection of RemoteRefUpdates