Package com.diffplug.spotless
Class GitPrePushHookInstaller
java.lang.Object
com.diffplug.spotless.GitPrePushHookInstaller
- Direct Known Subclasses:
GitPrePushHookInstallerGradle,GitPrePushHookInstallerMaven
Abstract class responsible for installing a Git pre-push hook in a repository.
This class ensures that specific checks and logic are run before a push operation in Git.
Subclasses should define specific behavior for hook installation by implementing the required abstract methods.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final GitPrePushHookInstaller.GitPreHookLoggerLogger for recording informational and error messages during the installation process.protected final FileThe root directory of the Git repository where the hook will be installed. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor to initialize the GitPrePushHookInstaller with a logger and repository root path. -
Method Summary
Modifier and TypeMethodDescriptionvoidinstall()Installs the Git pre-push hook into the repository.protected abstract StringProvides the content of the hook that should be inserted into the pre-push script.protected StringpreHookTemplate(GitPrePushHookInstaller.Executor executor, String commandCheck, String commandApply) Generates a pre-push template script that defines the commands to check and apply changes using an executor and Spotless.
-
Field Details
-
logger
Logger for recording informational and error messages during the installation process. -
root
The root directory of the Git repository where the hook will be installed.
-
-
Constructor Details
-
GitPrePushHookInstaller
Constructor to initialize the GitPrePushHookInstaller with a logger and repository root path.- Parameters:
logger- The logger for recording messages.root- The root directory of the Git repository.
-
-
Method Details
-
install
Installs the Git pre-push hook into the repository.This method checks for the following:
- Ensures Git is installed and the `.git/config` file exists.
- Checks if an executor required by the hook is available.
- Creates and writes the pre-push hook file if it does not exist.
- Skips installation if the hook is already installed.
- Throws:
Exception- if any error occurs during installation.
-
preHookContent
Provides the content of the hook that should be inserted into the pre-push script.- Returns:
- A string representing the content to include in the pre-push script.
-
preHookTemplate
protected String preHookTemplate(GitPrePushHookInstaller.Executor executor, String commandCheck, String commandApply) Generates a pre-push template script that defines the commands to check and apply changes using an executor and Spotless.- Parameters:
executor- The tool to execute the check and apply commands.commandCheck- The command to check for issues.commandApply- The command to apply corrections.- Returns:
- A string template representing the Spotless Git pre-push hook content.
-