Skip to content

Commit 7b0c52c

Browse files
dschovdye
authored andcommitted
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 ffe29a1 commit 7b0c52c

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
@@ -347,10 +347,16 @@ case $(uname -s) in
347347
/usr/bin/find "$@"
348348
}
349349
fi
350-
# git sees Windows-style pwd
351-
pwd () {
352-
builtin pwd -W
353-
}
350+
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
351+
# Unix-style paths. At least in Bash, we have a builtin pwd that
352+
# understands the -W option to force "mixed" paths, i.e. with drive
353+
# prefix but still with forward slashes. Let's use that, if available.
354+
if type builtin >/dev/null 2>&1
355+
then
356+
pwd () {
357+
builtin pwd -W
358+
}
359+
fi
354360
is_absolute_path () {
355361
case "$1" in
356362
[/\\]* | [A-Za-z]:*)

t/test-lib.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,10 +1498,16 @@ case $uname_s in
14981498
/usr/bin/find "$@"
14991499
}
15001500
fi
1501-
# git sees Windows-style pwd
1502-
pwd () {
1503-
builtin pwd -W
1504-
}
1501+
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
1502+
# Unix-style paths. At least in Bash, we have a builtin pwd that
1503+
# understands the -W option to force "mixed" paths, i.e. with drive
1504+
# prefix but still with forward slashes. Let's use that, if available.
1505+
if type builtin >/dev/null 2>&1
1506+
then
1507+
pwd () {
1508+
builtin pwd -W
1509+
}
1510+
fi
15051511
# no POSIX permissions
15061512
# backslashes in pathspec are converted to '/'
15071513
# exec does not inherit the PID

0 commit comments

Comments
 (0)