author | Junio C Hamano <gitster@pobox.com> | |
Wed, 20 Jan 2010 22:38:30 +0000 (14:38 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 20 Jan 2010 22:38:30 +0000 (14:38 -0800) |
* sd/cd-p-show-toplevel:
Use $(git rev-parse --show-toplevel) in cd_to_toplevel().
Add 'git rev-parse --show-toplevel' option.
Use $(git rev-parse --show-toplevel) in cd_to_toplevel().
Add 'git rev-parse --show-toplevel' option.
Documentation/git-rev-parse.txt | patch | blob | history | |
builtin-rev-parse.c | patch | blob | history | |
git-sh-setup.sh | patch | blob | history |
index 82045a2522799ccf3a03479bf4f4cd1fa1809879..dc829b333d9bda935c01581655fe62910b8f6e8f 100644 (file)
--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 37d02335212dea9672e2472970f66dc4ac95dfd1..cbe5b428ad23708338dc7b11cb0105f53b045527 100644 (file)
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
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);
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index dfcb8078f508d6cc26d312d61b64e0185e90b74b..d56426dd396190a07de7d661cd22fb284b759ca8 100755 (executable)
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
}
cd_to_toplevel () {
- cdup=$(git rev-parse --show-cdup)
- if test ! -z "$cdup"
- then
- # The "-P" option says to follow "physical" directory
- # structure instead of following symbolic links. When cdup is
- # "../", this means following the ".." entry in the current
- # directory instead textually removing a symlink path element
- # from the PWD shell variable. The "-P" behavior is more
- # consistent with the C-style chdir used by most of Git.
- cd -P "$cdup" || {
- echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
- exit 1
- }
- fi
+ cdup=$(git rev-parse --show-toplevel) &&
+ cd "$cdup" || {
+ echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
+ exit 1
+ }
}
require_work_tree () {