Skip to content

Commit dd6c136

Browse files
Marcel M. Carygitster
authored andcommitted
git-sh-setup: Fix scripts whose PWD is a symlink to a work-dir on OS X
On Mac OS X and possibly BSDs, /bin/pwd reads PWD from the environment if available and shows the logical path by default rather than the physical one. Unset PWD before running /bin/pwd in both cd_to_toplevel and its test. Still use the external /bin/pwd because in my Bash on Linux, the builtin pwd prints the same result whether or not PWD is set. Signed-off-by: Marcel M. Cary <[email protected]> Tested-by: Wincent Colaiuta <[email protected]> (on Mac OS X 10.5.5) Tested-by: Marcel Koeppen <[email protected]> (on Mac OS X 10.5.6) Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8104ebf commit dd6c136

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

git-sh-setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ cd_to_toplevel () {
9696
..|../*|*/..|*/../*)
9797
# Interpret $cdup relative to the physical, not logical, cwd.
9898
# Probably /bin/pwd is more portable than passing -P to cd or pwd.
99-
phys="$(/bin/pwd)/$cdup"
99+
phys="$(unset PWD; /bin/pwd)/$cdup"
100100
;;
101101
*)
102102
# There's no "..", so no need to make things absolute.

t/t2300-cd-to-toplevel.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ test_cd_to_toplevel () {
1010
cd '"'$1'"' &&
1111
. git-sh-setup &&
1212
cd_to_toplevel &&
13-
[ "$(/bin/pwd)" = "$TOPLEVEL" ]
13+
[ "$(unset PWD; /bin/pwd)" = "$TOPLEVEL" ]
1414
)
1515
'
1616
}
1717

18-
TOPLEVEL="$(/bin/pwd)/repo"
18+
TOPLEVEL="$(unset PWD; /bin/pwd)/repo"
1919
mkdir -p repo/sub/dir
2020
mv .git repo/
2121
SUBDIRECTORY_OK=1

0 commit comments

Comments
 (0)