Code

Add 'git rev-parse --show-toplevel' option.
authorSteven Drake <sdrake@xnet.co.nz>
Mon, 11 Jan 2010 22:33:48 +0000 (11:33 +1300)
committerJunio C Hamano <gitster@pobox.com>
Tue, 12 Jan 2010 03:47:35 +0000 (19:47 -0800)
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>
Documentation/git-rev-parse.txt
builtin-rev-parse.c

index 82045a2522799ccf3a03479bf4f4cd1fa1809879..dc829b333d9bda935c01581655fe62910b8f6e8f 100644 (file)
@@ -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
index 37d02335212dea9672e2472970f66dc4ac95dfd1..cbe5b428ad23708338dc7b11cb0105f53b045527 100644 (file)
@@ -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)
+                                       puts(work_tree);
+                               continue;
+                       }
                        if (!strcmp(arg, "--show-prefix")) {
                                if (prefix)
                                        puts(prefix);