Skip to content

Commit

Permalink
Merge branch 'mc/setup-cd-p'
Browse files Browse the repository at this point in the history
* mc/setup-cd-p:
  git-sh-setup: Use "cd" option, not /bin/pwd, for symlinked work tree
  • Loading branch information
Junio C Hamano committed Feb 15, 2009
2 parents 7b83a92 + 2c3c395 commit f7a2bdb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
29 changes: 8 additions & 21 deletions git-sh-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,14 @@ cd_to_toplevel () {
cdup=$(git rev-parse --show-cdup)
if test ! -z "$cdup"
then
case "$cdup" in
/*)
# Not quite the same as if we did "cd -P '$cdup'" when
# $cdup contains ".." after symlink path components.
# Don't fix that case at least until Git switches to
# "cd -P" across the board.
phys="$cdup"
;;
..|../*|*/..|*/../*)
# Interpret $cdup relative to the physical, not logical, cwd.
# Probably /bin/pwd is more portable than passing -P to cd or pwd.
phys="$(unset PWD; /bin/pwd)/$cdup"
;;
*)
# There's no "..", so no need to make things absolute.
phys="$cdup"
;;
esac

cd "$phys" || {
echo >&2 "Cannot chdir to $phys, the toplevel of the working tree"
# 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
Expand Down
4 changes: 2 additions & 2 deletions t/t2300-cd-to-toplevel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ test_cd_to_toplevel () {
cd '"'$1'"' &&
. git-sh-setup &&
cd_to_toplevel &&
[ "$(unset PWD; /bin/pwd)" = "$TOPLEVEL" ]
[ "$(pwd -P)" = "$TOPLEVEL" ]
)
'
}

TOPLEVEL="$(unset PWD; /bin/pwd)/repo"
TOPLEVEL="$(pwd -P)/repo"
mkdir -p repo/sub/dir
mv .git repo/
SUBDIRECTORY_OK=1
Expand Down

0 comments on commit f7a2bdb

Please sign in to comment.