From: Justin Tobler <jltobler@gmail.com>
To: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
Cc: git@vger.kernel.org, a3205153416@gmail.com, gitster@pobox.com,
kumarayushjha123@gmail.com, lucasseikioshiro@gmail.com,
phillip.wood@dunelm.org.uk, sandals@crustytoothpaste.net,
kristofferhaugsbakk@fastmail.com
Subject: Re: [GSoC Patch v4 3/4] repo: add path.commondir with absolute and relative suffix formatting
Date: Mon, 15 Jun 2026 13:17:33 -0500 [thread overview]
Message-ID: <ajAz5izOU1FSVrKW@denethor> (raw)
In-Reply-To: <20260615045112.50686-4-jayatheerthkulkarni2005@gmail.com>
On 26/06/15 10:21AM, K Jayatheerth wrote:
> Scripts working with worktree setups need a reliable way to discover
> the common directory, which diverges from the git directory when
> multiple worktrees are in use. There is no way to retrieve this path
> from git repo info today.
>
> Introduce path.commondir.absolute and path.commondir.relative keys.
> Exposing explicit format variants rather than a single key with a
> default avoids ambiguity for scripts that require predictable output.
>
> Add a test helper test_repo_info_path that creates isolated
> repositories per test case to prevent state leaks, captures the repo
> root before changing directories to avoid eval, and accepts an optional
> init_command to cover environment variable overrides such as
> GIT_COMMON_DIR and GIT_DIR.
I'm not sure this last paragraph in the log message provides much value.
To me it's a bit verbose and focuses mostly on what the test helper is
doing. Maybe we can just omit this section? If we want to have a note
though maybe we could say something like:
Each path key is expected to have an absolute and relative form. To
reduce duplication, a test_repo_info_path helper function is
introduced to configure and exercise both cases.
> Mentored-by: Justin Tobler <jltobler@gmail.com>
> Mentored-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
> Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
> ---
[snip]
> diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh
> index 39bb77dda0..0c0228687f 100755
> --- a/t/t1900-repo-info.sh
> +++ b/t/t1900-repo-info.sh
> @@ -155,4 +155,65 @@ test_expect_success 'git repo info -h shows only repo info usage' '
> test_grep ! "git repo structure" actual
> '
>
> +# Helper function to test path keys in both absolute and relative formats.
> +# $1: label for the test
> +# $2: field_name (e.g., commondir)
> +# $3: unique repo name for isolation
> +# $4: expect_absolute (suffix appended to repo root)
> +# $5: expect_relative (the relative path string expected)
> +# $6: init_command (extra setup like exporting env vars)
> +test_repo_info_path () {
> + label=$1
> + field_name=$2
> + repo_name=$3
> + expect_absolute_suffix=$4
> + expect_relative=$5
> + init_command=$6
I may be overthinking it, but I can't help but feel this test helper is
overly complicated. I wonder if we can simlify and reduce the number of
arguments. For example, could we programatically construct the label
from the field name and init_command instead of explicitly passing it?
> + absolute_root="$repo_name-absolute"
> + relative_root="$repo_name-relative"
> +
> + test_expect_success "setup: $label" '
> + git init "$absolute_root" &&
> + git init "$relative_root" &&
> + mkdir -p "$absolute_root/sub" "$relative_root/sub"
> + '
Do really need this setup test case? Could we instead embed the setup in
both test cases below? Something like:
test_when_finished rm -rf repo &&
git init repo &&
(
mkdir repo/sub &&
cd repo/sub &&
...
)
With something like this, each test case is responsible to creating its
own repo and cleaning it up when finished. Then we could avoid have to
provide a separate repo name for each set of test cases and remove the
repo_name argument.
> + test_expect_success "absolute: $label" '
> + (
> + cd "$absolute_root/sub" &&
> + ROOT="$(test-tool path-utils real_path ..)" && export ROOT &&
> + eval "$init_command" &&
> + expect_path="$ROOT${expect_absolute_suffix:+/$expect_absolute_suffix}" &&
> + echo "path.$field_name.absolute=$expect_path" >expect &&
> + git repo info "path.$field_name.absolute" >actual &&
> + test_cmp expect actual
> + )
> + '
> +
> + test_expect_success "relative: $label" '
> + (
> + cd "$relative_root/sub" &&
> + ROOT="$(test-tool path-utils real_path ..)" && export ROOT &&
> + eval "$init_command" &&
> + echo "path.$field_name.relative=$expect_relative" >expect &&
> + git repo info "path.$field_name.relative" >actual &&
> + test_cmp expect actual
> + )
> + '
> +}
> +
> +test_repo_info_path 'commondir standard' 'commondir' 'commondir-std' \
> + '.git' '../.git'
> +
> +test_repo_info_path 'commondir with GIT_COMMON_DIR and GIT_DIR' 'commondir' \
> + 'commondir-envs' 'custom-common' '../custom-common' \
> + 'GIT_COMMON_DIR="$ROOT/custom-common" && export GIT_COMMON_DIR &&
> + GIT_DIR="../.git" && export GIT_DIR &&
> + git init --bare "$ROOT/custom-common"'
> +
> +test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \
> + 'commondir-only-gitdir' '.git' '../.git' \
For each of these test cases, the `expect_absolute_suffix` and
`expect_relative` and exactly the same. This also appears to be the case
for the test cases in the next patch. Do these really need to be
configurable at all? Can we just embed them directly in each test case
assertion? Or maybe future keys will need this to be configurable?
> + 'GIT_DIR="../.git" && export GIT_DIR'
> +
> test_done
Overall the rest of the patch looks good to me.
-Justin
next prev parent reply other threads:[~2026-06-15 18:17 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-01 15:19 [GSoC][PATCH 0/4] teach git repo info to handle path keys K Jayatheerth
2026-06-01 15:19 ` [GSoC][PATCH 1/4] path: add strbuf_add_path for formatting paths K Jayatheerth
2026-06-02 13:00 ` Phillip Wood
2026-06-01 15:19 ` [GSoC][PATCH 2/4] rev-parse: use strbuf_add_path for path formatting K Jayatheerth
2026-06-01 15:19 ` [GSoC][PATCH 3/4] repo: add path.gitdir with absolute and relative suffix formatting K Jayatheerth
2026-06-01 16:28 ` Lucas Seiki Oshiro
2026-06-01 23:09 ` Junio C Hamano
2026-06-01 15:19 ` [GSoC][PATCH 4/4] repo: add path.commondir " K Jayatheerth
2026-06-01 16:34 ` Lucas Seiki Oshiro
2026-06-01 21:58 ` Lucas Seiki Oshiro
2026-06-01 16:25 ` [GSoC][PATCH 0/4] teach git repo info to handle path keys Lucas Seiki Oshiro
2026-06-01 22:04 ` Lucas Seiki Oshiro
2026-06-01 23:05 ` Junio C Hamano
2026-06-02 13:03 ` Phillip Wood
2026-06-05 16:30 ` [GSoC PATCH v2 " K Jayatheerth
2026-06-05 16:30 ` [GSoC PATCH v2 1/4] path: introduce format_path() for centralized path formatting K Jayatheerth
2026-06-05 16:55 ` Kristoffer Haugsbakk
2026-06-09 2:27 ` K Jayatheerth
2026-06-08 15:05 ` Lucas Seiki Oshiro
2026-06-09 2:47 ` K Jayatheerth
2026-06-08 17:28 ` Justin Tobler
2026-06-05 16:30 ` [GSoC PATCH v2 2/4] rev-parse: use format_path for " K Jayatheerth
2026-06-08 17:54 ` Justin Tobler
2026-06-05 16:30 ` [GSoC PATCH v2 3/4] repo: add path.gitdir with absolute and relative suffix formatting K Jayatheerth
2026-06-08 18:50 ` Justin Tobler
2026-06-09 4:41 ` K Jayatheerth
2026-06-09 14:31 ` Justin Tobler
2026-06-10 12:11 ` K Jayatheerth
2026-06-08 22:17 ` Lucas Seiki Oshiro
2026-06-05 16:30 ` [GSoC PATCH v2 4/4] repo: add path.commondir " K Jayatheerth
2026-06-08 22:40 ` Lucas Seiki Oshiro
2026-06-05 17:35 ` [GSoC PATCH v2 0/4] teach git repo info to handle path keys Lucas Seiki Oshiro
2026-06-09 2:30 ` K Jayatheerth
2026-06-08 22:36 ` Junio C Hamano
2026-06-09 5:00 ` K Jayatheerth
2026-06-10 12:42 ` Lucas Seiki Oshiro
2026-06-12 18:28 ` [GSoC Patch v3 " K Jayatheerth
2026-06-12 18:28 ` [GSoC Patch v3 1/4] path: introduce append_formatted_path() for shared path formatting K Jayatheerth
2026-06-12 18:28 ` [GSoC Patch v3 2/4] rev-parse: use append_formatted_path() for " K Jayatheerth
2026-06-12 18:28 ` [GSoC Patch v3 3/4] repo: add path.commondir with absolute and relative suffix formatting K Jayatheerth
2026-06-15 1:54 ` Lucas Seiki Oshiro
2026-06-12 18:28 ` [GSoC Patch v3 4/4] repo: add path.gitdir " K Jayatheerth
2026-06-15 1:55 ` Lucas Seiki Oshiro
2026-06-15 1:59 ` [GSoC Patch v3 0/4] teach git repo info to handle path keys Lucas Seiki Oshiro
2026-06-15 4:51 ` [GSoC Patch v4 " K Jayatheerth
2026-06-15 4:51 ` [GSoC Patch v4 1/4] path: introduce append_formatted_path() for shared path formatting K Jayatheerth
2026-06-15 4:51 ` [GSoC Patch v4 2/4] rev-parse: use append_formatted_path() for " K Jayatheerth
2026-06-15 17:18 ` Justin Tobler
2026-06-15 4:51 ` [GSoC Patch v4 3/4] repo: add path.commondir with absolute and relative suffix formatting K Jayatheerth
2026-06-15 18:17 ` Justin Tobler [this message]
2026-06-15 4:51 ` [GSoC Patch v4 4/4] repo: add path.gitdir " K Jayatheerth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ajAz5izOU1FSVrKW@denethor \
--to=jltobler@gmail.com \
--cc=a3205153416@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jayatheerthkulkarni2005@gmail.com \
--cc=kristofferhaugsbakk@fastmail.com \
--cc=kumarayushjha123@gmail.com \
--cc=lucasseikioshiro@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
--cc=sandals@crustytoothpaste.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox