--------
[verse]
'git hook' run [--ignore-missing] [--to-stdin=<path>] <hook-name> [-- <hook-args>]
-'git hook' list <hook-name>
+'git hook' list [-z] <hook-name>
DESCRIPTION
-----------
mandatory `--` (or `--end-of-options`, see linkgit:gitcli[7]). See
linkgit:githooks[5] for arguments hooks might expect (if any).
-list::
+list [-z]::
Print a list of hooks which will be run on `<hook-name>` event. If no
hooks are configured for that event, print a warning and return 1.
+ Use `-z` to terminate output lines with NUL instead of newlines.
OPTIONS
-------
tools that want to do a blind one-shot run of a hook that may
or may not be present.
+-z::
+ Terminate "list" output lines with NUL instead of newlines.
+
WRAPPERS
--------
#define BUILTIN_HOOK_RUN_USAGE \
N_("git hook run [--ignore-missing] [--to-stdin=<path>] <hook-name> [-- <hook-args>]")
#define BUILTIN_HOOK_LIST_USAGE \
- N_("git hook list <hook-name>")
+ N_("git hook list [-z] <hook-name>")
static const char * const builtin_hook_usage[] = {
BUILTIN_HOOK_RUN_USAGE,
struct string_list *head;
struct string_list_item *item;
const char *hookname = NULL;
+ int line_terminator = '\n';
int ret = 0;
struct option list_options[] = {
+ OPT_SET_INT('z', NULL, &line_terminator,
+ N_("use NUL as line terminator"), '\0'),
OPT_END(),
};
switch (h->kind) {
case HOOK_TRADITIONAL:
- printf("%s\n", _("hook from hookdir"));
+ printf("%s%c", _("hook from hookdir"), line_terminator);
break;
case HOOK_CONFIGURED:
- printf("%s\n", h->u.configured.friendly_name);
+ printf("%s%c", h->u.configured.friendly_name, line_terminator);
break;
default:
BUG("unknown hook kind");
test_cmp expect actual
'
+test_expect_success 'git hook list: -z shows NUL-terminated output' '
+ test_hook test-hook <<-EOF &&
+ echo Test hook
+ EOF
+ test_config hook.myhook.command "echo Hello" &&
+ test_config hook.myhook.event test-hook --add &&
+
+ printf "myhookQhook from hookdirQ" >expect &&
+ git hook list -z test-hook >actual.raw &&
+ nul_to_q <actual.raw >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'git hook run: nonexistent hook' '
cat >stderr.expect <<-\EOF &&
error: cannot find a hook named test-hook