Skip to content

Commit 510c2d6

Browse files
committed
mingw: only use Bash-ism builtin pwd -W when available
Traditionally, Git for Windows' SDK uses Bash as its default shell. However, other Unix shells are available, too. Most notably, the Win32 port of BusyBox comes with `ash` whose `pwd` command already prints Windows paths as Git for Windows wants them, while there is not even a `builtin` command. Therefore, let's be careful not to override `pwd` unless we know that the `builtin` command is available. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 4235305 commit 510c2d6

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

git-sh-setup.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,16 @@ case $(uname -s) in
346346
/usr/bin/find "$@"
347347
}
348348
fi
349-
# git sees Windows-style pwd
350-
pwd () {
351-
builtin pwd -W
352-
}
349+
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
350+
# Unix-style paths. At least in Bash, we have a builtin pwd that
351+
# understands the -W option to force "mixed" paths, i.e. with drive
352+
# prefix but still with forward slashes. Let's use that, if available.
353+
if type builtin >/dev/null 2>&1
354+
then
355+
pwd () {
356+
builtin pwd -W
357+
}
358+
fi
353359
is_absolute_path () {
354360
case "$1" in
355361
[/\\]* | [A-Za-z]:*)

t/test-lib.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,10 +1058,16 @@ case $uname_s in
10581058
/usr/bin/find "$@"
10591059
}
10601060
fi
1061-
# git sees Windows-style pwd
1062-
pwd () {
1063-
builtin pwd -W
1064-
}
1061+
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
1062+
# Unix-style paths. At least in Bash, we have a builtin pwd that
1063+
# understands the -W option to force "mixed" paths, i.e. with drive
1064+
# prefix but still with forward slashes. Let's use that, if available.
1065+
if type builtin >/dev/null 2>&1
1066+
then
1067+
pwd () {
1068+
builtin pwd -W
1069+
}
1070+
fi
10651071
# no POSIX permissions
10661072
# backslashes in pathspec are converted to '/'
10671073
# exec does not inherit the PID

0 commit comments

Comments
 (0)