Re: [PATCH v4 6/9] hook: add 'run' subcommand
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Sep 11, 2020, 13:30 UTC
- Message-ID
- <45208197-9e2d-6127-026f-b8ee5591677d@gmail.com>
- In-Reply-To
- <20200909004939.1942347-7-emilyshaffer@google.com>
Hi Emily
On 09/09/2020 01:49, Emily Shaffer wrote:
Show 21 quoted lines
> In order to enable hooks to be run as an external process, by a > standalone Git command, or by tools which wrap Git, provide an external > means to run all configured hook commands for a given hook event. > > For now, the hook commands will in config order, in series. As alternate > ordering or parallelism is supported in the future, we should add knobs > to use those to the command line as well. > > As with the legacy hook implementation, all stdout generated by hook > commands is redirected to stderr. Piping from stdin is not yet > supported. > > Legacy hooks (those present in $GITDIR/hooks) are run at the end of the > execution list. For now, there is no way to disable them. > > Users may wish to provide hook commands like 'git config > hook.pre-commit.command "~/linter.sh --pre-commit"'. To enable this, the > contents of the 'hook.*.command' and 'hookcmd.*.command' strings are > first split by space or quotes into an argv_array, then expanded with > 'expand_user_path()'. >
> [...]
Show 22 quoted lines
> diff --git a/t/t1360-config-based-hooks.sh b/t/t1360-config-based-hooks.sh > index ebf8f38d68..ee8114250d 100755 > --- a/t/t1360-config-based-hooks.sh > +++ b/t/t1360-config-based-hooks.sh > @@ -84,4 +84,32 @@ test_expect_success 'git hook list --porcelain prints just the command' ' > test_cmp expected actual > ' > > +test_expect_success 'inline hook definitions execute oneliners' ' > + test_config hook.pre-commit.command "echo \"Hello World\"" && > + > + echo "Hello World" >expected && > + > + # hooks are run with stdout_to_stderr = 1 > + git hook run pre-commit 2>actual && > + test_cmp expected actual > +' > + > +test_expect_success 'inline hook definitions resolve paths' ' > + cat >~/sample-hook.sh <<-EOF && > + echo \"Sample Hook\" > + EOF
I think this could use `write_script`. I'm rather scared of the '~' in the script path, can we write it to the test directory please.
Best Wishes
Phillip
Show 15 quoted lines
> + test_when_finished "rm ~/sample-hook.sh" && > + > + chmod +x ~/sample-hook.sh && > + > + test_config hook.pre-commit.command "~/sample-hook.sh" && > + > + echo \"Sample Hook\" >expected && > + > + # hooks are run with stdout_to_stderr = 1 > + git hook run pre-commit 2>actual && > + test_cmp expected actual > +' > + > test_done >