{"thread":{"id":"65278","subject":"[PATCH] repo: add paths.git_dir repo info key","startedAt":"2026-03-17T16:55:22Z","lastAt":"2026-03-22T03:27:37Z","messageCount":3,"participants":["Jayesh Daga via GitGitGadget","Karthik Nayak","Tian Yuchen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"539241","messageId":"pull.2242.git.git.1773766519857.gitgitgadget@gmail.com","threadId":"65278","inReplyTo":null,"subject":"[PATCH] repo: add paths.git_dir repo info key","fromName":"Jayesh Daga via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-03-17T16:55:19Z","receivedAt":"2026-03-17T16:55:22Z","isPatch":true,"sender":{"key":"jayeshdaga99@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86013121?v=4"},"body":"From: jayesh0104 <jayeshdaga99@gmail.com>\n\nIntroduce a new repo info key `paths.git_dir` to expose the\nrepository's gitdir path, equivalent to `git rev-parse --git-dir`.\n\nThis improves consistency and allows tools to retrieve the gitdir\npath without invoking external commands.\n\nThe implementation adds support in repo.c and integrates it into\nthe repo info reporting mechanism. Documentation is updated to\ndescribe the new key, and tests are added to verify that the value\nmatches the output of `git rev-parse --git-dir`.\n\nSigned-off-by: jayesh0104 <jayeshdaga99@gmail.com>\n---\n    repo: add paths.git_dir to 'git repo info'\n    \n    Teach git repo info a new key, paths.git_dir, which reports the\n    repository’s gitdir path (equivalent to git rev-parse --git-dir).\n    \n    Documentation and tests are included.\n    \n    Tests:\n    \n     * make test T=t1900-repo-info.sh\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2242%2Fjayesh0104%2Fmaster-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2242/jayesh0104/master-v1\nPull-Request: https://github.com/git/git/pull/2242\n\n Documentation/git-repo.adoc |  5 +++++\n builtin/repo.c              |  7 +++++++\n t/t1900-repo-info.sh        | 10 ++++++++++\n 3 files changed, 22 insertions(+)\n\ndiff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc\nindex 42262c1983..d17d911ec6 100644\n--- a/Documentation/git-repo.adoc\n+++ b/Documentation/git-repo.adoc\n@@ -95,6 +95,11 @@ In order to obtain a set of values from `git repo info`, you should provide\n the keys that identify them. Here's a list of the available keys and the\n values that they return:\n \n+`paths.git_dir`::\n+\tThe path to the Git directory for the repository (equivalent to\n+\t`git rev-parse --git-dir`).\n+\n+\n `layout.bare`::\n \t`true` if this is a bare repository, otherwise `false`.\n \ndiff --git a/builtin/repo.c b/builtin/repo.c\nindex 55f9b9095c..3067107cad 100644\n--- a/builtin/repo.c\n+++ b/builtin/repo.c\n@@ -66,11 +66,18 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)\n \treturn 0;\n }\n \n+static int get_paths_git_dir(struct repository *repo, struct strbuf *buf)\n+{\n+\tstrbuf_addstr(buf, repo_get_git_dir(repo));\n+\treturn 0;\n+}\n+\n /* repo_info_field keys must be in lexicographical order */\n static const struct repo_info_field repo_info_field[] = {\n \t{ \"layout.bare\", get_layout_bare },\n \t{ \"layout.shallow\", get_layout_shallow },\n \t{ \"object.format\", get_object_format },\n+\t{ \"paths.git_dir\", get_paths_git_dir },\n \t{ \"references.format\", get_references_format },\n };\n \ndiff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh\nindex a9eb07abe8..63be0849c4 100755\n--- a/t/t1900-repo-info.sh\n+++ b/t/t1900-repo-info.sh\n@@ -149,4 +149,14 @@ test_expect_success 'git repo info --keys uses lines as its default output forma\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'paths.git_dir matches rev-parse --git-dir' '\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\tgit repo info paths.git_dir >actual &&\n+\t\techo \"paths.git_dir=$(git rev-parse --git-dir)\" >expect &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n test_done\n\nbase-commit: ca1db8a0f7dc0dbea892e99f5b37c5fe5861be71\n-- \ngitgitgadget\n"},{"id":"539383","messageId":"CAOLa=ZTx1JnxtpPiz-Cegj7eMEGZmGL8s-RJQmTWv7W4H-3UoQ@mail.gmail.com","threadId":"65278","inReplyTo":"pull.2242.git.git.1773766519857.gitgitgadget@gmail.com","subject":"Re: [PATCH] repo: add paths.git_dir repo info key","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2026-03-19T14:00:01Z","receivedAt":"2026-03-19T14:00:04Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"\"Jayesh Daga via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: jayesh0104 <jayeshdaga99@gmail.com>\n>\n> Introduce a new repo info key `paths.git_dir` to expose the\n> repository's gitdir path, equivalent to `git rev-parse --git-dir`.\n>\n> This improves consistency and allows tools to retrieve the gitdir\n> path without invoking external commands.\n>\n> The implementation adds support in repo.c and integrates it into\n> the repo info reporting mechanism. Documentation is updated to\n> describe the new key, and tests are added to verify that the value\n> matches the output of `git rev-parse --git-dir`.\n>\n\nHello Jayesh,\n\nSeeing from the people CC'd I'm assuming that you're interested in\napplying for the GSoC.\n\nAs such, we encourage GSoC contributors to work on micro-projects as\nlisted on our GSoC website and also to read the guidelines we've laid\nout [1] [2].\n\nI would also mention that we do not recommend getting started on a\nproject, unless you're selected.\n\nNow specifically for this project, there is still no decision made about\nusing relative paths vs absolute paths, I've highlighted this in one of\nthe candidates proposals [3]. I would suggest getting involved in that\ndiscussion and coming to a conclusion before starting work on it.\n\n[1]: https://git.github.io/General-Microproject-Information/\n[2]: https://git.github.io/General-Application-Information/\n[3]: https://lore.kernel.org/git/CAOLa=ZTtNSZ904v0-SN16jAis7gK4=MVj1g_5CGdbmaBopeZkg@mail.gmail.com/#t\n\n\nRegards,\nKarthik\n\n[snip]\n"},{"id":"539630","messageId":"90c5b9a9-b77b-43ad-9c04-a0addc058aa8@gmail.com","threadId":"65278","inReplyTo":"pull.2242.git.git.1773766519857.gitgitgadget@gmail.com","subject":"Re: [PATCH] repo: add paths.git_dir repo info key","fromName":"Tian Yuchen","fromEmail":"a3205153416@gmail.com","sentAt":"2026-03-22T03:27:32Z","receivedAt":"2026-03-22T03:27:37Z","isPatch":true,"sender":{"key":"cat@malon.dev","avatar":"https://avatars.githubusercontent.com/u/232002048?v=4"},"body":"Hi Jayesh,\n\nOn 3/18/26 00:55, Jayesh Daga via GitGitGadget wrote:\n> From: jayesh0104 <jayeshdaga99@gmail.com>\n> \n> Introduce a new repo info key `paths.git_dir` to expose the\n> repository's gitdir path, equivalent to `git rev-parse --git-dir`.\n\nHere you promise in the commit message that paths.git_dir and git \nrev-parse --git-dir are equivalent...\n\n> > This improves consistency and allows tools to retrieve the gitdir\n> path without invoking external commands.\n> \n> The implementation adds support in repo.c and integrates it into\n> the repo info reporting mechanism. Documentation is updated to\n> describe the new key, and tests are added to verify that the value\n> matches the output of `git rev-parse --git-dir`.\n> \n> Signed-off-by: jayesh0104 <jayeshdaga99@gmail.com>\n> ---\n>      repo: add paths.git_dir to 'git repo info'\n>      \n>      Teach git repo info a new key, paths.git_dir, which reports the\n>      repository’s gitdir path (equivalent to git rev-parse --git-dir).\n>      \n>      Documentation and tests are included.\n>      \n>      Tests:\n>      \n>       * make test T=t1900-repo-info.sh\n> \n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2242%2Fjayesh0104%2Fmaster-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2242/jayesh0104/master-v1\n> Pull-Request: https://github.com/git/git/pull/2242\n> \n>   Documentation/git-repo.adoc |  5 +++++\n>   builtin/repo.c              |  7 +++++++\n>   t/t1900-repo-info.sh        | 10 ++++++++++\n>   3 files changed, 22 insertions(+)\n> \n> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc\n> index 42262c1983..d17d911ec6 100644\n> --- a/Documentation/git-repo.adoc\n> +++ b/Documentation/git-repo.adoc\n> @@ -95,6 +95,11 @@ In order to obtain a set of values from `git repo info`, you should provide\n>   the keys that identify them. Here's a list of the available keys and the\n>   values that they return:\n>   \n> +`paths.git_dir`::\n> +\tThe path to the Git directory for the repository (equivalent to\n> +\t`git rev-parse --git-dir`).\n> +\n> +\n>   `layout.bare`::\n>   \t`true` if this is a bare repository, otherwise `false`.\n>   \n> diff --git a/builtin/repo.c b/builtin/repo.c\n> index 55f9b9095c..3067107cad 100644\n> --- a/builtin/repo.c\n> +++ b/builtin/repo.c\n> @@ -66,11 +66,18 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)\n>   \treturn 0;\n>   }\n>  \n\n...\n\n> +static int get_paths_git_dir(struct repository *repo, struct strbuf *buf)\n> +{\n> +\tstrbuf_addstr(buf, repo_get_git_dir(repo));\n> +\treturn 0;\n> +}\n> +\n\n...But your implementation here doesn't quite feel right. Check the \ngit-rev-parse documentation: the output of the --git-dir argument is \ncontext-aware and depends on your current directory.\n\nIf you are in the root directory of the repository, it gives '.git'; And \nif you are in some subdirectory of the repository , it gives \n'/home/user/.../repo-root/.../.git'. I don't think simply calling \n'repo_get_git_dir(repo)' will achieve this functionality.\n\n>   /* repo_info_field keys must be in lexicographical order */\n>   static const struct repo_info_field repo_info_field[] = {\n>   \t{ \"layout.bare\", get_layout_bare },\n>   \t{ \"layout.shallow\", get_layout_shallow },\n>   \t{ \"object.format\", get_object_format },\n> +\t{ \"paths.git_dir\", get_paths_git_dir },\n>   \t{ \"references.format\", get_references_format },\n>   };\n>   \n> diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh\n> index a9eb07abe8..63be0849c4 100755\n> --- a/t/t1900-repo-info.sh\n> +++ b/t/t1900-repo-info.sh\n> @@ -149,4 +149,14 @@ test_expect_success 'git repo info --keys uses lines as its default output forma\n>   \ttest_cmp expect actual\n>   '\n>   \n\n...\n\n> +test_expect_success 'paths.git_dir matches rev-parse --git-dir' '\n> +\tgit init repo &&\n> +\t(\n> +\t\tcd repo &&\n> +\t\tgit repo info paths.git_dir >actual &&\n> +\t\techo \"paths.git_dir=$(git rev-parse --git-dir)\" >expect &&\n> +\t\ttest_cmp expect actual\n> +\t)\n> +'\n> +\n>   test_done\n\nAnd you’ve only provided tests for the root directory here, which I \ndon’t think is sufficient. That said, considering that you’ve likely \nmisunderstood how to use the --git-dir parameter, this is understandable.\n\nNext time you create a similar patch, I think you should take a close \nlook at the documentation and source code first, and try using the \nexisting commands a few times on your own to understand how they work, \nright? ;)\n\nRegards,\n\nYuchen\n\n"}]}