зеркало из https://github.com/microsoft/git.git
hook: support a --to-stdin=<path> option
Expose the "path_to_stdin" API added in the preceding commit in the "git hook run" command. For now we won't be using this command interface outside of the tests, but exposing this functionality makes it easier to test the hook API. The plan is to use this to extend the "sendemail-validate" hook[1][2]. 1. https://lore.kernel.org/git/ad152e25-4061-9955-d3e6-a2c8b1bd24e7@amd.com 2. https://lore.kernel.org/git/20230120012459.920932-1-michael.strawbridge@amd.com Signed-off-by: Emily Shaffer <emilyshaffer@google.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
96af564d27
Коммит
0414b3891c
|
@ -8,7 +8,7 @@ git-hook - Run git hooks
|
|||
SYNOPSIS
|
||||
--------
|
||||
[verse]
|
||||
'git hook' run [--ignore-missing] <hook-name> [-- <hook-args>]
|
||||
'git hook' run [--ignore-missing] [--to-stdin=<path>] <hook-name> [-- <hook-args>]
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
|
@ -31,6 +31,11 @@ linkgit:githooks[5] for arguments hooks might expect (if any).
|
|||
OPTIONS
|
||||
-------
|
||||
|
||||
--to-stdin::
|
||||
For "run"; Specify a file which will be streamed into the
|
||||
hook's stdin. The hook will receive the entire file from
|
||||
beginning to EOF.
|
||||
|
||||
--ignore-missing::
|
||||
Ignore any missing hook by quietly returning zero. Used for
|
||||
tools that want to do a blind one-shot run of a hook that may
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include "strvec.h"
|
||||
|
||||
#define BUILTIN_HOOK_RUN_USAGE \
|
||||
N_("git hook run [--ignore-missing] <hook-name> [-- <hook-args>]")
|
||||
N_("git hook run [--ignore-missing] [--to-stdin=<path>] <hook-name> [-- <hook-args>]")
|
||||
|
||||
static const char * const builtin_hook_usage[] = {
|
||||
BUILTIN_HOOK_RUN_USAGE,
|
||||
|
@ -28,6 +28,8 @@ static int run(int argc, const char **argv, const char *prefix)
|
|||
struct option run_options[] = {
|
||||
OPT_BOOL(0, "ignore-missing", &ignore_missing,
|
||||
N_("silently ignore missing requested <hook-name>")),
|
||||
OPT_STRING(0, "to-stdin", &opt.path_to_stdin, N_("path"),
|
||||
N_("file to read into hooks' stdin")),
|
||||
OPT_END(),
|
||||
};
|
||||
int ret;
|
||||
|
|
|
@ -177,4 +177,22 @@ test_expect_success 'git hook run a hook with a bad shebang' '
|
|||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'stdin to hooks' '
|
||||
write_script .git/hooks/test-hook <<-\EOF &&
|
||||
echo BEGIN stdin
|
||||
cat
|
||||
echo END stdin
|
||||
EOF
|
||||
|
||||
cat >expect <<-EOF &&
|
||||
BEGIN stdin
|
||||
hello
|
||||
END stdin
|
||||
EOF
|
||||
|
||||
echo hello >input &&
|
||||
git hook run --to-stdin=input test-hook 2>actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_done
|
||||
|
|
Загрузка…
Ссылка в новой задаче