Skip to content

Commit

Permalink
mingw: respect core.shell when executing scripts
Browse files Browse the repository at this point in the history
On Windows, we have to emulate that Linux/Unix/macOS feature where a
file starting with a `#!` line and being marked as executable is run as
a script through the interpreter specified by said `#!` line.

Traditionally, we ignore the actual path specified in that line because
it will be a Unix-style path anyway, something that `git.exe` is not
even supposed to understand. We then go on to look up the actual path of
the interpreter by iterating over the components in the environment
variable `PATH`.

Let's special-case `sh` in that scenario when the config setting
`core.shell` exists: in this case, we want to use it instead.

This allows us to configure BusyBox' `ash` to be used for all of the
shell scripting needs of the BusyBox flavor of MinGit.

While at it, assume that any shell configured via `core.shell` is _not_
an MSYS2 shell, i.e. that we should use regular Win32 command-line
quoting, not MSYS2/Cygwin one.

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Jul 1, 2021
1 parent 0246cd9 commit fdec756
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,10 @@ static char *path_lookup(const char *cmd, int exe_only)
if (strpbrk(cmd, "/\\"))
return xstrdup(cmd);

if (!strcmp(cmd, "sh") &&
(prog = xstrdup_or_null(get_shell_path(NULL))))
return prog;

path = mingw_getenv("PATH");
if (!path)
return NULL;
Expand Down Expand Up @@ -1463,6 +1467,12 @@ static int is_msys2_sh(const char *cmd)
if (ret >= 0)
return ret;

if (get_shell_path(NULL)) {
/* Assume an overridden shell is not MSYS2 */
ret = 0;
return ret;
}

p = path_lookup(cmd, 0);
if (!p)
ret = 0;
Expand Down

0 comments on commit fdec756

Please sign in to comment.