gitui/git2-hooks
Johannes Agricola 7f75307f6e
Resolve core.hooksPath relative to GIT_WORK_TREE (#2571)
* Resolve core.hooksPath relative to GIT_WORK_TREE

git supports relative values in core.hooksPath.

`man git-config`:

> A relative path is taken as relative to the directory where the hooks are
> run (see the "DESCRIPTION" section of githooks[5]).

`man githooks`:

> Before Git invokes a hook, it changes its working directory to either
> $GIT_DIR in a bare repository or the root of the working tree in a >
> non-bare repository.

I.e. relative paths in core.hooksPath in non-bare repositories are always
relative to GIT_WORK_TREE.

There is a further exception; I believe this is not considered for path
resolution:

> An exception are hooks triggered during a push (pre-receive, update,
> post-receive, post-update, push-to-checkout) which are always executed
> in $GIT_DIR.

* Favor Repository::workdir() over path().parent()

This more clearly errors in case of bare repositories instead of using
the parent directory of the bare repository.

---------

Co-authored-by: Naseschwarz <naseschwarz@0x53a.de>
Co-authored-by: extrawurst <776816+extrawurst@users.noreply.github.com>
2025-04-04 15:28:44 +02:00
..
src Resolve core.hooksPath relative to GIT_WORK_TREE (#2571) 2025-04-04 15:28:44 +02:00
Cargo.toml Change links to point to gitui-org instead of extrawurst (#2538) 2025-03-16 15:33:28 +01:00
LICENSE.md move git hooks support into separate crate (#1971) 2023-12-07 16:28:52 +01:00
README.md git2-hooks: allows customizing what places to look for hooks (#1975) 2023-12-08 14:33:22 +01:00

git2-hooks

adds git hook functionality on top of git2-rs

todo

  • unittest coverage symlinks from .git/hooks/<hook> -> X
  • unittest coverage ~ expansion inside core.hooksPath