git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] repo: add the field path.git-dir

From
Pushkar Singh <pushkarkumarsingh1970@gmail.com>
Date
Mar 1, 2026, 13:59 UTC
Message-ID
<20260301135927.1072684-3-pushkarkumarsingh1970@gmail.com>
In-Reply-To
<20260301134412.1072596-2-pushkarkumarsingh1970@gmail.com>

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 <pushkarkumarsingh1970@gmail.com>
---
 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
Previous: Pushkar SinghNext: Pushkar Singh
Message 5 of 10 in “[RFC] git repo info: exposing repository paths”
  1. Pushkar SinghFeb 10, 2026
  2. Patrick SteinhardtFeb 11, 2026
  3. Pushkar SinghFeb 18, 2026
  4. 0/2 repo info: add path.git-dir and path.common-dirPushkar Singh, Mar 1, 2026
  5. 1/2 repo: add the field path.git-dirPushkar Singh, Mar 1, 2026
  6. 2/2 repo: add the field path.common-dirPushkar Singh, Mar 1, 2026
  7. K JayatheerthMar 1, 2026
  8. Lucas Seiki OshiroMar 1, 2026
  9. Pushkar SinghMar 1, 2026
  10. Junio C HamanoMar 2, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.