Skip to content

Commit 3e71edc

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 c0d03ff commit 3e71edc

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
@@ -1543,10 +1543,16 @@ case $uname_s in
15431543
/usr/bin/find "$@"
15441544
}
15451545
fi
1546-
# git sees Windows-style pwd
1547-
pwd () {
1548-
builtin pwd -W
1549-
}
1546+
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
1547+
# Unix-style paths. At least in Bash, we have a builtin pwd that
1548+
# understands the -W option to force "mixed" paths, i.e. with drive
1549+
# prefix but still with forward slashes. Let's use that, if available.
1550+
if type builtin >/dev/null 2>&1
1551+
then
1552+
pwd () {
1553+
builtin pwd -W
1554+
}
1555+
fi
15501556
# no POSIX permissions
15511557
# backslashes in pathspec are converted to '/'
15521558
# exec does not inherit the PID

0 commit comments

Comments
 (0)