Skip to content

Commit a3d468f

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 918563b commit a3d468f

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

t/test-lib.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,10 +1630,16 @@ case $uname_s in
16301630
/usr/bin/find "$@"
16311631
}
16321632
fi
1633-
# git sees Windows-style pwd
1634-
pwd () {
1635-
builtin pwd -W
1636-
}
1633+
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
1634+
# Unix-style paths. At least in Bash, we have a builtin pwd that
1635+
# understands the -W option to force "mixed" paths, i.e. with drive
1636+
# prefix but still with forward slashes. Let's use that, if available.
1637+
if type builtin >/dev/null 2>&1
1638+
then
1639+
pwd () {
1640+
builtin pwd -W
1641+
}
1642+
fi
16371643
# no POSIX permissions
16381644
# backslashes in pathspec are converted to '/'
16391645
# exec does not inherit the PID

0 commit comments

Comments
 (0)