Re: [PATCH 6/6] hook: teach --porcelain mode
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 11, 2019, 19:33 UTC
- Message-ID
- <xmqqimmmodwt.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <20191210023335.49987-7-emilyshaffer@google.com>
Emily Shaffer <emilyshaffer@google.com> writes:
Show 8 quoted lines
> It might be desirable - for a user script, or a scripted Git command - > to run the appropriate set of hooks from outside of the compiled Git > binary. So, teach --porcelain in a way that enables the following: > > git hook --list --porcelain pre-commit | xargs -I% sh "%" > > Signed-off-by: Emily Shaffer <emilyshaffer@google.com> > ---
Show 20 quoted lines
> +--porcelain::
> + Print in a machine-readable format suitable for scripting.
> +
> ...
> +static int print_hook_list(const struct strbuf *hookname, int porcelain)
> {
> struct list_head *head, *pos;
> struct hook *item;
> @@ -25,10 +25,14 @@ static int print_hook_list(const struct strbuf *hookname)
>
> list_for_each(pos, head) {
> item = list_entry(pos, struct hook, list);
> + if (item) {
> + if (porcelain)
> + printf("%s\n", item->command.buf);
> + else
> + printf("%.3d\t%s\t%s\n", item->order,
> + config_scope_to_string(item->origin),
> + item->command.buf);
> + }So, a Porcelain script cannot learn where the hook command comes from, or what the precedence order of each line of the output is?