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

[PATCH 1/2] Add 'git rev-parse --show-toplevel' option.

From
SDSteven Drake <sdrake@xnet.co.nz>
Date
Jan 11, 2010, 22:33 UTC
Message-ID
<alpine.LNX.2.00.1001121133080.10158@vqena.qenxr.bet.am>
In-Reply-To
<alpine.LNX.2.00.1001102011420.2560@vqena.qenxr.bet.am>
Shows the absolute path of the top-level working directory.
Signed-off-by: Steven Drake <sdrake@xnet.co.nz>
---
 Documentation/git-rev-parse.txt |    3 +++
 builtin-rev-parse.c             |    6 ++++++
 2 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index 82045a2..dc829b3 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -112,6 +112,9 @@ OPTIONS
 --remotes::
 	Show tag refs found in `$GIT_DIR/refs/remotes`.
 
+--show-toplevel::
+	Show the absolute path of the top-level directory.
+
 --show-prefix::
 	When the command is invoked from a subdirectory, show the
 	path of the current directory relative to the top-level
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 37d0233..96ab8bb 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -581,6 +581,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 				for_each_remote_ref(show_reference, NULL);
 				continue;
 			}
+			if (!strcmp(arg, "--show-toplevel")) {
+				const char *work_tree = get_git_work_tree();
+				if (work_tree)
+					printf("%s\n", work_tree);
+				continue;
+			}
 			if (!strcmp(arg, "--show-prefix")) {
 				if (prefix)
 					puts(prefix);
-- 
1.6.4
Previous: Steven DrakeNext: Steven Drake
Message 2 of 3 in “Add 'git rev-parse --show-toplevel' option.”
  1. 1/2 Add 'git rev-parse --show-toplevel' option.Steven Drake, Jan 10, 2010
  2. 1/2 Add 'git rev-parse --show-toplevel' option.Steven Drake, Jan 11, 2010
  3. 2/2 Use $(git rev-parse --show-toplevel) in cd_to_toplevel().Steven Drake, Jan 11, 2010

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.