Thread View: linux.kernel.git
4 messages
4 total messages
Started by Justin Tobler
Mon, 02 Nov 2026 22:32
Re: [GSoC Patch v7 4/8] repo: add path.hooks with absolute and relative suffixes
Author: Justin Tobler
Date: Mon, 02 Nov 2026 22:32
Date: Mon, 02 Nov 2026 22:32
118 lines
15770 bytes
15770 bytes
On 26/09/27 05:14PM, K Jayatheerth wrote:
> Hooks are an integral part of a repository's configuration and are
> commonly used by tooling to automate repository-specific workflows.
> Currently, scripts typically retrieve the hooks directory by invoking
> `git rev-parse --git-path hooks`.
>
> Introduce `path.hooks.absolute` and `path.hooks.relative` keys to
> `git repo info`. This exposes the hooks directory as a scriptable
> config-like key using standard format rules, allowing scripts to
> retrieve it through the same interface as other repository path
> information.
>
> Mentored-by: Justin Tobler <jltobler@gmail.com>
> Mentored-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
> Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
> ---
> Documentation/git-repo.adoc | 9 +++++++++
> builtin/repo.c | 22 ++++++++++++++++++++++
> t/t1900-repo-info.sh | 28 ++++++++++++++++++++++++++--
> 3 files changed, 57 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
> index e524a07f53..20836cf8f6 100644
> --- a/Documentation/git-repo.adoc
> +++ b/Documentation/git-repo.adoc
> @@ -119,6 +119,15 @@ values that they return:
> `path.gitdir.relative`::
> The path to the Git repository directory relative to the current working directory.
>
> +`path.hooks.absolute`::
> + The canonical absolute path to the repository's hooks directory.
> + Respects the `core.hooksPath` configuration. If `core.hooksPath` is
> + set to `/dev/null`, that value is returned unchanged.
> +
> +`path.hooks.relative`::
> + The path to the repository's hooks directory relative to the current
> + working directory. Respects the `core.hooksPath` configuration.
So if a repository has `core.hooksPath` set to "/dev/null", the relative
path output here would be something like "../../../../dev/null". I
recognize that this matches the current behavior:
$ git -c core.hooksPath=/dev/null rev-parse --path-format=relative --git-path hooks
../../../../dev/null
...but I'm still not really convinced that is is a behavior we would
want to carry over as it makes it harder to users to figure out when
hooks are disabled.
I would suggest we print the "/dev/null" here even when the relative
path is requested and document the behavior.
[snip]
> diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh
> index eec576a1d9..1da5db4942 100755
> --- a/t/t1900-repo-info.sh
> +++ b/t/t1900-repo-info.sh
> @@ -174,7 +174,11 @@ test_repo_info_path () {
> cd repo/sub &&
> ROOT="$(test-tool path-utils real_path ..)" && export ROOT &&
> eval "$init_command" &&
> - echo "path.$field_name.absolute=$ROOT/$expected_dir" >expect &&
> + case "$expected_dir" in
> + /*) EXPECT_ABS="$expected_dir" ;;
> + *) EXPECT_ABS="$ROOT/$expected_dir" ;;
> + esac &&
> + echo "path.$field_name.absolute=$EXPECT_ABS" >expect &&
> git repo info "path.$field_name.absolute" >actual &&
> test_cmp expect actual
> )
> @@ -188,7 +192,11 @@ test_repo_info_path () {
> cd repo/sub &&
> ROOT="$(test-tool path-utils real_path ..)" && export ROOT &&
> eval "$init_command" &&
> - echo "path.$field_name.relative=../$expected_dir" >expect &&
> + case "$expected_dir" in
> + /*) EXPECT_REL="$(test-tool path-utils relative_path "$expected_dir" "$PWD")" ;;
> + *) EXPECT_REL="../$expected_dir" ;;
> + esac &&
> + echo "path.$field_name.relative=$EXPECT_REL" >expect &&
> git repo info "path.$field_name.relative" >actual &&
> test_cmp expect actual
> )
From what I can gather, the code changes to this test helper is really
only required for the "/dev/null" test case. IMO, this helper function
has now become quite unwieldy and rather difficult to parse.
I think we would be better off writing the "/dev/null" test case by hand.
> @@ -213,6 +221,22 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
> '.git' \
> 'GIT_DIR="../.git" && export GIT_DIR'
>
> +test_repo_info_path 'hooks standard' 'hooks' '.git/hooks'
> +
> +test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \
> + 'custom-hooks' \
> + 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"'
> +
> +# /dev/null is not a real, canonicalizable filesystem path on Windows,
> +# so path resolution for core.hooksPath=/dev/null cannot be expected to
> +# produce a literal "/dev/null" the way it does on POSIX systems.
> +if ! test_have_prereq MINGW
> +then
> + test_repo_info_path 'hooks with core.hooksPath=/dev/null' 'hooks' \
> + '/dev/null' \
> + 'git config core.hooksPath /dev/null'
> +fi
I'm not quite sure I follow here. Are we saying that the git-repo-info
command won't work on windows if the hooks are set to "/dev/null"? Or is
it just some issue with how the test is written? If its the latter,
maybe this is something we can work around if the test is written
without the use of the `test_repo_info_path` helper?
-Justin
Re: [GSoC Patch v7 4/8] repo: add path.hooks with absolute and relative suffixes
Author: K Jayatheerth
Date: Tue, 03 Nov 2026 02:31
Date: Tue, 03 Nov 2026 02:31
171 lines
19183 bytes
19183 bytes
On Tue, Nov 3, 2026 at 4:02 AM Justin Tobler <jltobler@gmail.com> wrote:
>
> On 26/09/27 05:14PM, K Jayatheerth wrote:
> > Hooks are an integral part of a repository's configuration and are
> > commonly used by tooling to automate repository-specific workflows.
> > Currently, scripts typically retrieve the hooks directory by invoking
> > `git rev-parse --git-path hooks`.
> >
> > Introduce `path.hooks.absolute` and `path.hooks.relative` keys to
> > `git repo info`. This exposes the hooks directory as a scriptable
> > config-like key using standard format rules, allowing scripts to
> > retrieve it through the same interface as other repository path
> > information.
> >
> > Mentored-by: Justin Tobler <jltobler@gmail.com>
> > Mentored-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
> > Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
> > ---
> > Documentation/git-repo.adoc | 9 +++++++++
> > builtin/repo.c | 22 ++++++++++++++++++++++
> > t/t1900-repo-info.sh | 28 ++++++++++++++++++++++++++--
> > 3 files changed, 57 insertions(+), 2 deletions(-)
> >
> > diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
> > index e524a07f53..20836cf8f6 100644
> > --- a/Documentation/git-repo.adoc
> > +++ b/Documentation/git-repo.adoc
> > @@ -119,6 +119,15 @@ values that they return:
> > `path.gitdir.relative`::
> > The path to the Git repository directory relative to the current working directory.
> >
> > +`path.hooks.absolute`::
> > + The canonical absolute path to the repository's hooks directory.
> > + Respects the `core.hooksPath` configuration. If `core.hooksPath` is
> > + set to `/dev/null`, that value is returned unchanged.
> > +
> > +`path.hooks.relative`::
> > + The path to the repository's hooks directory relative to the current
> > + working directory. Respects the `core.hooksPath` configuration.
>
> So if a repository has `core.hooksPath` set to "/dev/null", the relative
> path output here would be something like "../../../../dev/null". I
> recognize that this matches the current behavior:
>
> $ git -c core.hooksPath=/dev/null rev-parse --path-format=relative --git-path hooks
> ../../../../dev/null
>
> ...but I'm still not really convinced that is is a behavior we would
> want to carry over as it makes it harder to users to figure out when
> hooks are disabled.
>
> I would suggest we print the "/dev/null" here even when the relative
> path is requested and document the behavior.
>
I am more inclined with you, and
I see how returning "/dev/null" for the relative key makes it
much easier for scripts to detect when hooks are disabled.
One thing I wanted to check: in a follow-up series, Junio suggested
extracting a common helper library to share implementations between
`git rev-parse` and `git repo info`. If `git repo info` special-cases
"/dev/null" for `path.hooks.relative` while `rev-parse --git-path hooks`
continues to relative-format it, would that divergence be an issue for
sharing the underlying helper, or should we special-case it only in the
`path.hooks` getter?
> [snip]
> > diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh
> > index eec576a1d9..1da5db4942 100755
> > --- a/t/t1900-repo-info.sh
> > +++ b/t/t1900-repo-info.sh
> > @@ -174,7 +174,11 @@ test_repo_info_path () {
> > cd repo/sub &&
> > ROOT="$(test-tool path-utils real_path ..)" && export ROOT &&
> > eval "$init_command" &&
> > - echo "path.$field_name.absolute=$ROOT/$expected_dir" >expect &&
> > + case "$expected_dir" in
> > + /*) EXPECT_ABS="$expected_dir" ;;
> > + *) EXPECT_ABS="$ROOT/$expected_dir" ;;
> > + esac &&
> > + echo "path.$field_name.absolute=$EXPECT_ABS" >expect &&
> > git repo info "path.$field_name.absolute" >actual &&
> > test_cmp expect actual
> > )
> > @@ -188,7 +192,11 @@ test_repo_info_path () {
> > cd repo/sub &&
> > ROOT="$(test-tool path-utils real_path ..)" && export ROOT &&
> > eval "$init_command" &&
> > - echo "path.$field_name.relative=../$expected_dir" >expect &&
> > + case "$expected_dir" in
> > + /*) EXPECT_REL="$(test-tool path-utils relative_path "$expected_dir" "$PWD")" ;;
> > + *) EXPECT_REL="../$expected_dir" ;;
> > + esac &&
> > + echo "path.$field_name.relative=$EXPECT_REL" >expect &&
> > git repo info "path.$field_name.relative" >actual &&
> > test_cmp expect actual
> > )
>
> From what I can gather, the code changes to this test helper is really
> only required for the "/dev/null" test case. IMO, this helper function
> has now become quite unwieldy and rather difficult to parse.
>
> I think we would be better off writing the "/dev/null" test case by hand.
>
Agreed, reverting the changes to `test_repo_info_path` and writing the
`/dev/null` test as a standalone test block will be much cleaner.
> > @@ -213,6 +221,22 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
> > '.git' \
> > 'GIT_DIR="../.git" && export GIT_DIR'
> >
> > +test_repo_info_path 'hooks standard' 'hooks' '.git/hooks'
> > +
> > +test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \
> > + 'custom-hooks' \
> > + 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"'
> > +
> > +# /dev/null is not a real, canonicalizable filesystem path on Windows,
> > +# so path resolution for core.hooksPath=/dev/null cannot be expected to
> > +# produce a literal "/dev/null" the way it does on POSIX systems.
> > +if ! test_have_prereq MINGW
> > +then
> > + test_repo_info_path 'hooks with core.hooksPath=/dev/null' 'hooks' \
> > + '/dev/null' \
> > + 'git config core.hooksPath /dev/null'
> > +fi
>
> I'm not quite sure I follow here. Are we saying that the git-repo-info
> command won't work on windows if the hooks are set to "/dev/null"? Or is
> it just some issue with how the test is written? If its the latter,
> maybe this is something we can work around if the test is written
> without the use of the `test_repo_info_path` helper?
>
It was both the command and the test helper on Windows, `/dev/null` is
not an actual filesystem path, so passing it through `format_path()`
(and `test-tool path-utils relative_path` in the test) does not resolve
the same way as on POSIX systems (where `$PWD` on Windows has a drive
letter like `C:/...`).
However, if we special-case `/dev/null` in the C code so that both
`path.hooks.absolute` and `path.hooks.relative` output `/dev/null`
directly without passing it through `format_path()`, and write the test
by hand, it will work consistently on Windows too and we can drop the
`!MINGW` prerequisite entirely.
> -Justin
Thank you,
- K Jayatheerth
Re: [GSoC Patch v7 4/8] repo: add path.hooks with absolute and relative suffixes
Author: Justin Tobler
Date: Tue, 03 Nov 2026 16:16
Date: Tue, 03 Nov 2026 16:16
36 lines
12484 bytes
12484 bytes
On 26/11/03 08:01AM, K Jayatheerth wrote: > On Tue, Nov 3, 2026 at 4:02 AM Justin Tobler <jltobler@gmail.com> wrote: > > > > So if a repository has `core.hooksPath` set to "/dev/null", the relative > > path output here would be something like "../../../../dev/null". I > > recognize that this matches the current behavior: > > > > $ git -c core.hooksPath=/dev/null rev-parse --path-format=relative --git-path hooks > > ../../../../dev/null > > > > ...but I'm still not really convinced that is is a behavior we would > > want to carry over as it makes it harder to users to figure out when > > hooks are disabled. > > > > I would suggest we print the "/dev/null" here even when the relative > > path is requested and document the behavior. > > > > I am more inclined with you, and > I see how returning "/dev/null" for the relative key makes it > much easier for scripts to detect when hooks are disabled. > > One thing I wanted to check: in a follow-up series, Junio suggested > extracting a common helper library to share implementations between > `git rev-parse` and `git repo info`. If `git repo info` special-cases > "/dev/null" for `path.hooks.relative` while `rev-parse --git-path hooks` > continues to relative-format it, would that divergence be an issue for > sharing the underlying helper, or should we special-case it only in the > `path.hooks` getter? I don't really think that would be an issue. Regarding the follow-up series, I figure you could just not use a shared helper here if the behavior is diverged, or special case it some way. -Justin
Re: [GSoC Patch v7 4/8] repo: add path.hooks with absolute and relative suffixes
Author: K Jayatheerth
Date: Tue, 03 Nov 2026 18:27
Date: Tue, 03 Nov 2026 18:27
50 lines
13874 bytes
13874 bytes
On Tue, Nov 3, 2026 at 9:46 PM Justin Tobler <jltobler@gmail.com> wrote: > > On 26/11/03 08:01AM, K Jayatheerth wrote: > > On Tue, Nov 3, 2026 at 4:02 AM Justin Tobler <jltobler@gmail.com> wrote: > > > > > > So if a repository has `core.hooksPath` set to "/dev/null", the relative > > > path output here would be something like "../../../../dev/null". I > > > recognize that this matches the current behavior: > > > > > > $ git -c core.hooksPath=/dev/null rev-parse --path-format=relative --git-path hooks > > > ../../../../dev/null > > > > > > ...but I'm still not really convinced that is is a behavior we would > > > want to carry over as it makes it harder to users to figure out when > > > hooks are disabled. > > > > > > I would suggest we print the "/dev/null" here even when the relative > > > path is requested and document the behavior. > > > > > > > I am more inclined with you, and > > I see how returning "/dev/null" for the relative key makes it > > much easier for scripts to detect when hooks are disabled. > > > > One thing I wanted to check: in a follow-up series, Junio suggested > > extracting a common helper library to share implementations between > > `git rev-parse` and `git repo info`. If `git repo info` special-cases > > "/dev/null" for `path.hooks.relative` while `rev-parse --git-path hooks` > > continues to relative-format it, would that divergence be an issue for > > sharing the underlying helper, or should we special-case it only in the > > `path.hooks` getter? > > I don't really think that would be an issue. Regarding the follow-up > series, I figure you could just not use a shared helper here if the > behavior is diverged, or special case it some way. > Sure, then setting a case for /dev/null makes sense I suppose. I can always as you mentioned make it a special case. > -Justin Thanks, - K Jayatheerth
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads