Skip to content

Commit a3773fd

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 d998d58 commit a3773fd

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
@@ -323,10 +323,16 @@ case $(uname -s) in
323323
/usr/bin/find "$@"
324324
}
325325
fi
326-
# git sees Windows-style pwd
327-
pwd () {
328-
builtin pwd -W
329-
}
326+
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
327+
# Unix-style paths. At least in Bash, we have a builtin pwd that
328+
# understands the -W option to force "mixed" paths, i.e. with drive
329+
# prefix but still with forward slashes. Let's use that, if available.
330+
if type builtin >/dev/null 2>&1
331+
then
332+
pwd () {
333+
builtin pwd -W
334+
}
335+
fi
330336
is_absolute_path () {
331337
case "$1" in
332338
[/\\]* | [A-Za-z]:*)

t/test-lib.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,10 +1576,16 @@ case $uname_s in
15761576
/usr/bin/find "$@"
15771577
}
15781578
fi
1579-
# git sees Windows-style pwd
1580-
pwd () {
1581-
builtin pwd -W
1582-
}
1579+
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
1580+
# Unix-style paths. At least in Bash, we have a builtin pwd that
1581+
# understands the -W option to force "mixed" paths, i.e. with drive
1582+
# prefix but still with forward slashes. Let's use that, if available.
1583+
if type builtin >/dev/null 2>&1
1584+
then
1585+
pwd () {
1586+
builtin pwd -W
1587+
}
1588+
fi
15831589
# no POSIX permissions
15841590
# backslashes in pathspec are converted to '/'
15851591
# exec does not inherit the PID

0 commit comments

Comments
 (0)