Skip to content

Commit 1277ea4

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 cb90e57 commit 1277ea4

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
@@ -1675,10 +1675,16 @@ Darwin)
16751675
/usr/bin/find "$@"
16761676
}
16771677
fi
1678-
# git sees Windows-style pwd
1679-
pwd () {
1680-
builtin pwd -W
1681-
}
1678+
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
1679+
# Unix-style paths. At least in Bash, we have a builtin pwd that
1680+
# understands the -W option to force "mixed" paths, i.e. with drive
1681+
# prefix but still with forward slashes. Let's use that, if available.
1682+
if type builtin >/dev/null 2>&1
1683+
then
1684+
pwd () {
1685+
builtin pwd -W
1686+
}
1687+
fi
16821688
# no POSIX permissions
16831689
# backslashes in pathspec are converted to '/'
16841690
# exec does not inherit the PID

0 commit comments

Comments
 (0)