Skip to content

Commit b44e0a1

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 cb214a9 commit b44e0a1

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
@@ -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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,10 +1648,16 @@ case $uname_s in
16481648
/usr/bin/find "$@"
16491649
}
16501650
fi
1651-
# git sees Windows-style pwd
1652-
pwd () {
1653-
builtin pwd -W
1654-
}
1651+
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
1652+
# Unix-style paths. At least in Bash, we have a builtin pwd that
1653+
# understands the -W option to force "mixed" paths, i.e. with drive
1654+
# prefix but still with forward slashes. Let's use that, if available.
1655+
if type builtin >/dev/null 2>&1
1656+
then
1657+
pwd () {
1658+
builtin pwd -W
1659+
}
1660+
fi
16551661
# no POSIX permissions
16561662
# backslashes in pathspec are converted to '/'
16571663
# exec does not inherit the PID

0 commit comments

Comments
 (0)