Skip to content

Commit

Permalink
Use $(git rev-parse --show-toplevel) in cd_to_toplevel().
Browse files Browse the repository at this point in the history
rev-parse --show-toplevel gives the absolute (aka "physical") path of the
toplevel directory and is more portable as 'cd -P' is not supported by all
shell implementations.

This is also closer to what setup_work_tree() does.

Signed-off-by: Steven Drake <sdrake@xnet.co.nz>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Steven Drake authored and Junio C Hamano committed Jan 12, 2010
1 parent 7cceca5 commit 91dc602
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions git-sh-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,11 @@ is_bare_repository () {
}
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 () {
Expand Down

0 comments on commit 91dc602

Please sign in to comment.