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

[PATCH 0/6] configuration-based hook management

From
Emily Shaffer <emilyshaffer@google.com>
Date
Dec 10, 2019, 02:33 UTC
Message-ID
<20191210023335.49987-1-emilyshaffer@google.com>

An implementation of the first piece of the proposal given in lore.kernel.org/git/20191116011125.GG22855@google.com.

Teaches a new command, 'git hook', which will someday include 'git hook --add ...', 'git hook --edit ...', and maybe more. For now, just teach it how to check the config files with 'git hook --list ...'.

The hooks-to-run list is collected in a new library, hook.o, which can someday reimplement find_hook() or otherwise be invoked to run all hooks for a given hookname (e.g. "pre-commit").

The change to config.[ch] allows us to display a similar scope name to the one a user may use to 'git config --add' or later 'git hook --add' a hook at a certain scope, e.g.:

  $ git hook --list pre-commit
  001	global	~/foo.sh
  $ git hook --add --global pre-commit 005 ~/bar.sh
  Added.
  001	global	~/foo.sh
  005	global	~/bar.sh
There are config examples in many of the commit messages in this chain.

Before I consider "--list" to be done, I also want to add support to check "hook.runHookDir" and take .git/hooks/* into account. But I wanted us to spend time chewing on the config format for a while before I got too far.

It's also very possible (likely, even!) to put this feature behind an experimental flag, which gives us more room to change the config format if we want before the feature is "done".

In the discussion thread with brian, I also mentioned a self-paced deprecation of hooks which live in .git/hooks/, which I'm aware some users may not want to follow. However, it occurred to me that we may be able to hide a Git-paced deprecation behind a config macro (since those are new and shiny) which is opt-in, and handles something like:

  hook.runHookDir = true
  hook.warnHookDir = false
  {some months pass, we are sure config-based hooks are working nicely}
  hook.runHookDir = true
  hook.warnHookDir = true
  {so start yelling at users to move away, and wait some more
  months/years}
  hook.runHookDir = false
  {users who have opted into the hookdir phaseout macro are no longer
  using the hookdir}

As it's opt-in (and easily reversible by changing configs) this might be a good middle ground for the "deprecate or not" discussion brian and I had.

Thanks.
 - Emily
Emily Shaffer (6):
  hook: scaffolding for git-hook subcommand
  config: add string mapping for enum config_scope
  hook: add --list mode
  hook: support reordering of hook list
  hook: remove prior hook with '---'
  hook: teach --porcelain mode
 .gitignore                    |  1 +
 Documentation/git-hook.txt    | 53 ++++++++++++++++++++
 Makefile                      |  2 +
 builtin.h                     |  1 +
 builtin/hook.c                | 80 ++++++++++++++++++++++++++++++
 config.c                      | 17 +++++++
 config.h                      |  1 +
 git.c                         |  1 +
 hook.c                        | 93 +++++++++++++++++++++++++++++++++++
 hook.h                        | 14 ++++++
 t/t1360-config-based-hooks.sh | 89 +++++++++++++++++++++++++++++++++
 11 files changed, 352 insertions(+)
 create mode 100644 Documentation/git-hook.txt
 create mode 100644 builtin/hook.c
 create mode 100644 hook.c
 create mode 100644 hook.h
 create mode 100755 t/t1360-config-based-hooks.sh
-- 
2.24.0.393.g34dc348eaf-goog
Next: Emily Shaffer
Message 1 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.