Installs packaged Git hooks for the consumer repository.
'git:hooks'
'Installs Fast Forward Git hooks.'
['.git/hooks', 'git-hooks']
Properties
Methods
Creates a new GitHooksCommand instance.
Adds the standard JSON output options to the current command.
Configures hook source, target, and initialization options.
Copies packaged Git hooks.
Determines whether JSON output was requested.
Determines whether pretty JSON output was requested.
Compares rendered hook contents with an existing installed hook.
Logs a failed command result and returns the failure exit code.
Installs a single hook and rewrites drifted targets defensively.
Determines whether structured JSON output SHOULD be enabled implicitly.
Determines whether a boolean input option was enabled.
Logs a non-terminal command message unless structured JSON output is active.
Prompts whether a drifted hook should be replaced.
Logs a successful command result and returns the success exit code.
private
FileDiffer
$fileDiffer
private
FileLocatorInterface
$fileLocator
private
FilesystemInterface
$filesystem
private
FinderFactoryInterface
$finderFactory
private
HookContentRenderer
$hookContentRenderer
private
SymfonyStyle
$io
Creates a new GitHooksCommand instance.
public
__construct(FilesystemInterface
$filesystem, FileLocatorInterface
$fileLocator, FinderFactoryInterface
$finderFactory, HookContentRenderer
$hookContentRenderer, FileDiffer
$fileDiffer, SymfonyStyle
$io) : mixed
Parameters
Description
the filesystem used to copy hooks
$fileLocator
:
FileLocatorInterface
Description
the locator used to find packaged hooks
Description
the factory used to create finders for hook files
Description
renders packaged hooks with runtime-specific placeholders
Description
the file differ used to summarize synchronization changes
$io
:
SymfonyStyle
Description
the input/output service used to interact with the user
Adds the standard JSON output options to the current command.
protected
addJsonOption() : static
Return values
Configures hook source, target, and initialization options.
protected
configure() : void
Copies packaged Git hooks.
protected
execute(InputInterface
$input, OutputInterface
$output) : int
Parameters
$input
:
InputInterface
Description
the command input
$output
:
OutputInterface
Description
the command output
Return values
Description
the command status code
Determines whether JSON output was requested.
protected
isJsonOutput(InputInterface
$input) : bool
Description
The pretty-json flag SHALL imply JSON output.
Parameters
$input
:
InputInterface
Return values
Determines whether pretty JSON output was requested.
protected
isPrettyJsonOutput(InputInterface
$input) : bool
Parameters
$input
:
InputInterface
Return values
Compares rendered hook contents with an existing installed hook.
private
compareRenderedHookContents(
string
$sourcePath,
string
$hookPath,
string
$renderedContents) : FileDiff
Parameters
$sourcePath
:
string
Description
the packaged hook source path
$hookPath
:
string
Description
the target installed hook path
$renderedContents
:
string
Description
the rendered hook contents
Return values
Description
the rendered comparison result
Logs a failed command result and returns the failure exit code.
private
failure(
string
$message, InputInterface
$input[,
array<string, mixed>
$context = []][,
string|null
$file = null][,
int|null
$line = null]) : int
Parameters
$message
:
string
Description
the failure message
$input
:
InputInterface
Description
the originating command input
$context
:
array<string, mixed>
=
[]
Description
optional extra log context
$file
:
string|null
=
null
Description
the related file path when known
$line
:
int|null
=
null
Description
the related line when known
Return values
Installs a single hook and rewrites drifted targets defensively.
private
installHook(
string
$sourcePath,
string
$hookPath,
bool
$replaceExisting, InputInterface
$input[,
string|null
$renderedContents = null]) : bool
Parameters
$sourcePath
:
string
Description
the packaged hook path
$hookPath
:
string
Description
the target repository hook path
$replaceExisting
:
bool
Description
whether an existing hook SHOULD be removed first
$input
:
InputInterface
Description
the originating command input
$renderedContents
:
string|null
=
null
Description
optional rendered hook contents that SHOULD be written instead of copied
Return values
Description
true when the hook was installed successfully
Determines whether structured JSON output SHOULD be enabled implicitly.
private
isImplicitJsonOutputEnabled() : bool
Description
Commands MAY opt into runtime-environment-aware behavior by exposing a
$runtimeEnvironment property. Commands that do not expose it SHALL fall
back to the shared runtime-environment service from the DevTools container.
Return values
Determines whether a boolean input option was enabled.
private
isOptionEnabled(InputInterface
$input,
string
$option) : bool
Parameters
$input
:
InputInterface
$option
:
string
Return values
Logs a non-terminal command message unless structured JSON output is active.
private
log(
string
$message, InputInterface
$input[,
array<string, mixed>
$context = []][,
string
$logLevel = LogLevel::INFO]) : void
Parameters
$message
:
string
Description
the progress message
$input
:
InputInterface
Description
the originating command input
$context
:
array<string, mixed>
=
[]
Description
optional extra log context
$logLevel
:
string
=
LogLevel::INFO
Description
the PSR-3 log level used for the message
private
resolveRuntimeEnvironment() : RuntimeEnvironmentInterface|null
Return values
Prompts whether a drifted hook should be replaced.
private
shouldReplaceHook(
string
$hookPath) : bool
Parameters
$hookPath
:
string
Description
the hook path that would be replaced
Return values
Description
true when the replacement SHOULD proceed
Logs a successful command result and returns the success exit code.
private
success(
string
$message, InputInterface
$input[,
array<string, mixed>
$context = []][,
string
$logLevel = LogLevel::INFO]) : int
Parameters
$message
:
string
Description
the success message
$input
:
InputInterface
Description
the originating command input
$context
:
array<string, mixed>
=
[]
Description
optional extra log context
$logLevel
:
string
=
LogLevel::INFO
Description
the PSR-3 log level used for the successful result