git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 6/6] hook: teach --porcelain mode

From
Emily Shaffer <emilyshaffer@google.com>
Date
Dec 11, 2019, 22:00 UTC
Message-ID
<20191211220039.GB8464@google.com>
In-Reply-To
<xmqqimmmodwt.fsf@gitster-ct.c.googlers.com>
On Wed, Dec 11, 2019 at 11:33:38AM -0800, Junio C Hamano wrote:
Show 34 quoted lines
> Emily Shaffer <emilyshaffer@google.com> writes:
> 
> > 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>
> > ---
> 
> > +--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,
Not as I had envisioned.
> or what the precedence order of each line of the output is?
> 

They're printed in the order they should be executed; the explicit order isn't provided.

I suppose I had considered really just the one use case listed in the commit message, especially since other inquiry into the hooks to be run can be done against the config files themselves. But - I'm of course open to use cases. What did you have in mind?

Maybe this can be solved better with a --pretty=format type of argument.
Previous: Junio C HamanoNext: Junio C Hamano
Message 16 of 19 in “configuration-based hook management”
  1. 0/6 configuration-based hook managementEmily Shaffer, Dec 10, 2019
  2. 1/6 hook: scaffolding for git-hook subcommandEmily Shaffer, Dec 10, 2019
  3. Bert WesargDec 12, 2019
  4. SZEDER GáborDec 12, 2019
  5. 2/6 config: add string mapping for enum config_scopeEmily Shaffer, Dec 10, 2019
  6. Philip OakleyDec 10, 2019
  7. Philip OakleyDec 10, 2019
  8. 3/6 hook: add --list modeEmily Shaffer, Dec 10, 2019
  9. Bert WesargDec 12, 2019
  10. SZEDER GáborDec 12, 2019
  11. 4/6 hook: support reordering of hook listEmily Shaffer, Dec 10, 2019
  12. Junio C HamanoDec 11, 2019
  13. 5/6 hook: remove prior hook with '---'Emily Shaffer, Dec 10, 2019
  14. 6/6 hook: teach --porcelain modeEmily Shaffer, Dec 10, 2019
  15. Junio C HamanoDec 11, 2019
  16. Emily ShafferDec 11, 2019
  17. Junio C HamanoDec 11, 2019
  18. Emily ShafferDec 11, 2019
  19. Junio C HamanoDec 11, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.