Skip to content

Commit

Permalink
mingw: only use Bash-ism builtin pwd -W when available
Browse files Browse the repository at this point in the history
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 <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Sep 18, 2024
1 parent b4cfcbc commit 68ff010
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 10 additions & 4 deletions git-sh-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,16 @@ case $(uname -s) in
/usr/bin/find "$@"
}
fi
# git sees Windows-style pwd
pwd () {
builtin pwd -W
}
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
# Unix-style paths. At least in Bash, we have a builtin pwd that
# understands the -W option to force "mixed" paths, i.e. with drive
# prefix but still with forward slashes. Let's use that, if available.
if type builtin >/dev/null 2>&1
then
pwd () {
builtin pwd -W
}
fi
is_absolute_path () {
case "$1" in
[/\\]* | [A-Za-z]:*)
Expand Down
14 changes: 10 additions & 4 deletions t/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1724,10 +1724,16 @@ case $uname_s in
/usr/bin/find "$@"
}
fi
# git sees Windows-style pwd
pwd () {
builtin pwd -W
}
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
# Unix-style paths. At least in Bash, we have a builtin pwd that
# understands the -W option to force "mixed" paths, i.e. with drive
# prefix but still with forward slashes. Let's use that, if available.
if type builtin >/dev/null 2>&1
then
pwd () {
builtin pwd -W
}
fi
# no POSIX permissions
# backslashes in pathspec are converted to '/'
# exec does not inherit the PID
Expand Down

0 comments on commit 68ff010

Please sign in to comment.