[PATCH 1/2] repo: add the field path.git-dir
From: Pushkar Singh <hidden>
Date: 2026-03-01 14:00:43
Subsystem:
the rest · Maintainer:
Linus Torvalds
The flag --git-dir from git-rev-parse is commonly used by scripts and tooling to retrieve the repository’s Git directory. Since git repo info aims to provide structured repository metadata, expose this information via a new field path.git-dir. The value respects the --path-format flag introduced earlier. Signed-off-by: Pushkar Singh <redacted> --- builtin/repo.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
diff --git a/builtin/repo.c b/builtin/repo.c
index 61cd539e05..8b4c7ae4cb 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c@@ -73,6 +73,21 @@ static int get_path_toplevel(struct repository *repo, struct strbuf *buf, return 0; } +static int get_path_git_dir(struct repository *repo, struct strbuf *buf, + const char *prefix, + enum path_format_type format) +{ + const char *gitdir = repo_get_git_dir(repo); + + if (!gitdir) + return error(_("unable to retrieve git directory")); + + strbuf_add_path(buf, gitdir, prefix, format, + PATH_DEFAULT_UNMODIFIED); + + return 0; +} + static int get_references_format(struct repository *repo, struct strbuf *buf, const char *prefix UNUSED, enum path_format_type format UNUSED)
@@ -87,6 +102,7 @@ static const struct repo_info_field repo_info_field[] = { { "layout.bare", get_layout_bare }, { "layout.shallow", get_layout_shallow }, { "object.format", get_object_format }, + { "path.git-dir", get_path_git_dir }, { "path.toplevel", get_path_toplevel }, { "references.format", get_references_format }, };
--
2.43.0