All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] repo: add paths.toplevel to repo info
@ 2026-04-02 17:14 Jayesh Daga via GitGitGadget
  2026-04-02 17:38 ` Junio C Hamano
  2026-04-08 17:08 ` [PATCH v2] " Jayesh Daga via GitGitGadget
  0 siblings, 2 replies; 8+ messages in thread
From: Jayesh Daga via GitGitGadget @ 2026-04-02 17:14 UTC (permalink / raw)
  To: git; +Cc: Derrick Stolee, Jayesh Daga, Jayesh Daga

From: Jayesh Daga <jayeshdaga99@gmail.com>

Expose the working tree root via `git repo info` as
paths.toplevel, matching the semantics of
`git rev-parse --show-toplevel`.

For bare repositories, this value is empty, consistent
with other non-applicable fields.

This allows scripts to retrieve the repository root
through a structured interface without invoking
rev-parse.

Signed-off-by: Jayesh Daga <jayeshdaga99@gmail.com>
---
    repo: add paths.toplevel to repo info
    
    repo info currently does not expose the repository's working tree root,
    even though this information is available via repo_get_work_tree().
    
    This makes it harder for scripts to retrieve the repository root through
    a structured interface, often requiring the use of git rev-parse
    --show-toplevel.
    
    Add a new field paths.toplevel to git repo info that returns the working
    tree root. For bare repositories, this value is empty, consistent with
    other non-applicable fields.
    
    This provides a consistent and script-friendly way to query repository
    paths without invoking additional commands.
    
    Signed-off-by: Jayesh Daga jayeshdaga99@gmail.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2264%2Fjayesh0104%2Frepo-toplevel-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2264/jayesh0104/repo-toplevel-v1
Pull-Request: https://github.com/git/git/pull/2264

 builtin/repo.c       | 12 ++++++++++++
 t/t1900-repo-info.sh | 16 ++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/builtin/repo.c b/builtin/repo.c
index 71a5c1c29c..d0491f6c66 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -62,6 +62,17 @@ static int get_layout_bare(struct repository *repo UNUSED, struct strbuf *buf)
 	return 0;
 }
 
+static int get_paths_toplevel(struct repository *repo, struct strbuf *buf)
+{
+    const char *wt = repo_get_work_tree(repo);
+
+    if (!wt)
+	return -1; /* match existing error style */
+
+    strbuf_addstr(buf, wt);
+    return 0;
+}
+
 static int get_layout_shallow(struct repository *repo, struct strbuf *buf)
 {
 	strbuf_addstr(buf,
@@ -87,6 +98,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 },
+	{ "paths.toplevel", get_paths_toplevel },
 	{ "references.format", get_references_format },
 };
 
diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh
index 39bb77dda0..470e06e8c2 100755
--- a/t/t1900-repo-info.sh
+++ b/t/t1900-repo-info.sh
@@ -155,4 +155,20 @@ test_expect_success 'git repo info -h shows only repo info usage' '
 	test_grep ! "git repo structure" actual
 '
 
+test_expect_success 'repo info paths.toplevel' '
+    git repo info paths.toplevel >actual &&
+    echo "paths.toplevel=$(git rev-parse --show-toplevel)" >expected &&
+    test_cmp expected actual
+'
+
+test_expect_success 'repo info paths.toplevel (bare repo)' '
+    git init --bare bare.git &&
+    (
+	cd bare.git &&
+	git repo info paths.toplevel >actual &&
+	echo "paths.toplevel=" >expected &&
+	test_cmp expected actual
+    )
+'
+
 test_done

base-commit: 256554692df0685b45e60778b08802b720880c50
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-04-09 16:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-02 17:14 [PATCH] repo: add paths.toplevel to repo info Jayesh Daga via GitGitGadget
2026-04-02 17:38 ` Junio C Hamano
2026-04-08 17:08 ` [PATCH v2] " Jayesh Daga via GitGitGadget
2026-04-09  6:01   ` [PATCH v3] " Jayesh Daga via GitGitGadget
2026-04-09 13:13     ` Karthik Nayak
2026-04-09 14:48       ` Junio C Hamano
2026-04-09 16:01         ` Karthik Nayak
2026-04-09 14:42     ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.