Skip to content

Commit 1429175

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 b54cc08 commit 1429175

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

git-sh-setup.sh

+10-4
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,16 @@ case $(uname -s) in
306306
/usr/bin/find "$@"
307307
}
308308
fi
309-
# git sees Windows-style pwd
310-
pwd () {
311-
builtin pwd -W
312-
}
309+
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
310+
# Unix-style paths. At least in Bash, we have a builtin pwd that
311+
# understands the -W option to force "mixed" paths, i.e. with drive
312+
# prefix but still with forward slashes. Let's use that, if available.
313+
if type builtin >/dev/null 2>&1
314+
then
315+
pwd () {
316+
builtin pwd -W
317+
}
318+
fi
313319
is_absolute_path () {
314320
case "$1" in
315321
[/\\]* | [A-Za-z]:*)

t/test-lib.sh

+10-4
Original file line numberDiff line numberDiff line change
@@ -1720,10 +1720,16 @@ case $uname_s in
17201720
/usr/bin/find "$@"
17211721
}
17221722
fi
1723-
# git sees Windows-style pwd
1724-
pwd () {
1725-
builtin pwd -W
1726-
}
1723+
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
1724+
# Unix-style paths. At least in Bash, we have a builtin pwd that
1725+
# understands the -W option to force "mixed" paths, i.e. with drive
1726+
# prefix but still with forward slashes. Let's use that, if available.
1727+
if type builtin >/dev/null 2>&1
1728+
then
1729+
pwd () {
1730+
builtin pwd -W
1731+
}
1732+
fi
17271733
# no POSIX permissions
17281734
# backslashes in pathspec are converted to '/'
17291735
# exec does not inherit the PID

0 commit comments

Comments
 (0)