Skip to content

Latest commit

 

History

History
81 lines (61 loc) · 2.01 KB

File metadata and controls

81 lines (61 loc) · 2.01 KB

Lefthook integration

lefthook is a popular git hook manager. When lefthook takes over a repository's hooks it replaces the hook scripts in .git/hooks with its own runner. Lefthook then invokes the configured commands but, unlike git, does not forward the positional arguments (such as the commit-message file path) to those commands.

This means that when lefthook runs mit-commit-msg and mit-prepare-commit-msg the commit-message path argument is missing. The hooks fall back to <gitdir>/COMMIT_EDITMSG so co-author trailers and lints continue to work.

Setup

We need a git repository with the hooks installed.

git init .
git mit-install
git mit bt se

Configuring lefthook

We tell lefthook to run all three git-mit hooks. No {1} argument forwarding is needed.

---
pre-commit:
  commands:
    git-mit:
      run: mit-pre-commit

prepare-commit-msg:
  commands:
    git-mit:
      run: mit-prepare-commit-msg

commit-msg:
  commands:
    git-mit:
      run: mit-commit-msg

Installing lefthook takes over the hooks.

lefthook install

Committing through lefthook

When we commit, lefthook intercepts each hook and runs the git-mit binaries without forwarding the commit-message path. The co-author trailers still appear because the hooks fall back to COMMIT_EDITMSG.

echo "# Hello, world!" > README.md

git add .
git commit --message="Add a feature" --quiet
git show --pretty='format:author: [%an %ae] signed-by: [%GS]
---
%B' -q
author: [Billie Thompson billie@example.com] signed-by: []
---
Add a feature

Co-authored-by: Someone Else <someone@example.com>