diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-01-29 13:00:07 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-02-03 09:52:57 +0300 |
commit | 6d61ab918b5d1fb9d1725ae3fcdf4dd60dc2dbc9 (patch) | |
tree | c92f93c6f711f01ff56e73768401d152f561b0a2 | |
parent | 65da4cadf6b009f55840297c4d738580595aa0a0 (diff) |
git: Relax hook checks to allow hooks for non-modifying commands
Setup of hooks is currently only allowed for commands which modify any
references. This stems from the fact that all existing hooks were only
ever executed when any refs changed, so this check was added as a safety
measure to not setup hooks if not required.
We've recently grown support for another hook though with the
pack-objects hook. This one is different than the existing hooks, mainly
that it's executed for a read-only command. So in this context, it
doesn't make a lot of sense to keep the restiction.
Let's relax the restriction to allow configuration of hooks for
read-only commands. The requirement to set up hooks for modifying
commands is left as-is.
-rw-r--r-- | internal/git/command.go | 12 | ||||
-rw-r--r-- | internal/git/command_factory.go | 5 |
2 files changed, 4 insertions, 13 deletions
diff --git a/internal/git/command.go b/internal/git/command.go index 1fdc99d47..42d1230ba 100644 --- a/internal/git/command.go +++ b/internal/git/command.go @@ -26,6 +26,9 @@ var ( // ErrInvalidArg represent family of errors to report about bad argument used to make a call. ErrInvalidArg = errors.New("invalid argument") + // ErrHookPayloadRequired indicates a HookPayload is needed but + // absent from the command. + ErrHookPayloadRequired = errors.New("hook payload is required but not configured") ) func init() { @@ -320,15 +323,6 @@ func WithEnv(envs ...string) CmdOpt { } } -var ( - // ErrRefHookRequired indicates a ref hook configuration is needed but - // absent from the command - ErrRefHookRequired = errors.New("ref hook is required but not configured") - // ErrRefHookNotRequired indicates an extraneous ref hook option was - // provided - ErrRefHookNotRequired = errors.New("ref hook is configured but not required") -) - // NewCommand creates a command.Command with the given args and Repository. It // validates the arguments in the command before executing. func NewCommand(ctx context.Context, repo repository.GitRepo, globals []GlobalOption, sc Cmd, opts ...CmdOpt) (*command.Command, error) { diff --git a/internal/git/command_factory.go b/internal/git/command_factory.go index 015d7c7d9..cfc38b1d0 100644 --- a/internal/git/command_factory.go +++ b/internal/git/command_factory.go @@ -144,10 +144,7 @@ func handleOpts(ctx context.Context, sc Cmd, cc *cmdCfg, opts []CmdOpt) error { } if !cc.hooksConfigured && gitCommand.mayUpdateRef() { - return fmt.Errorf("subcommand %q: %w", sc.Subcommand(), ErrRefHookRequired) - } - if cc.hooksConfigured && !gitCommand.mayUpdateRef() { - return fmt.Errorf("subcommand %q: %w", sc.Subcommand(), ErrRefHookNotRequired) + return fmt.Errorf("subcommand %q: %w", sc.Subcommand(), ErrHookPayloadRequired) } if gitCommand.mayGeneratePackfiles() { cc.globals = append(cc.globals, ConfigPair{ |