X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-sh-setup.sh;h=2142308bcc6d2e2c4962859d18e12070cd4c1b1d;hb=26be15f09db15d2b53a13d0f184d77fb54367f33;hp=dbdf209ec0e7d6468c199d1905c3e7788a9cd246;hpb=847d10f56d7853cd0e139a7c2e6ad0ad2de5c464;p=git.git diff --git a/git-sh-setup.sh b/git-sh-setup.sh index dbdf209ec..2142308bc 100755 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -85,8 +85,27 @@ cd_to_toplevel () { cdup=$(git rev-parse --show-cdup) if test ! -z "$cdup" then - cd "$cdup" || { - echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree" + 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" exit 1 } fi