Skip to content

Commit 7cceca5

Browse files
Steven Drakegitster
authored andcommitted
Add 'git rev-parse --show-toplevel' option.
Shows the absolute path of the top-level working directory. Signed-off-by: Steven Drake <sdrake@xnet.co.nz> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 902f235 commit 7cceca5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Documentation/git-rev-parse.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ OPTIONS
112112
--remotes::
113113
Show tag refs found in `$GIT_DIR/refs/remotes`.
114114

115+
--show-toplevel::
116+
Show the absolute path of the top-level directory.
117+
115118
--show-prefix::
116119
When the command is invoked from a subdirectory, show the
117120
path of the current directory relative to the top-level

builtin-rev-parse.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
581581
for_each_remote_ref(show_reference, NULL);
582582
continue;
583583
}
584+
if (!strcmp(arg, "--show-toplevel")) {
585+
const char *work_tree = get_git_work_tree();
586+
if (work_tree)
587+
puts(work_tree);
588+
continue;
589+
}
584590
if (!strcmp(arg, "--show-prefix")) {
585591
if (prefix)
586592
puts(prefix);

0 commit comments

Comments
 (0)