Skip to content

Commit fdec756

Browse files
committed
mingw: respect core.shell when executing scripts
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]>
1 parent 0246cd9 commit fdec756

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

compat/mingw.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,10 @@ static char *path_lookup(const char *cmd, int exe_only)
12771277
if (strpbrk(cmd, "/\\"))
12781278
return xstrdup(cmd);
12791279

1280+
if (!strcmp(cmd, "sh") &&
1281+
(prog = xstrdup_or_null(get_shell_path(NULL))))
1282+
return prog;
1283+
12801284
path = mingw_getenv("PATH");
12811285
if (!path)
12821286
return NULL;
@@ -1463,6 +1467,12 @@ static int is_msys2_sh(const char *cmd)
14631467
if (ret >= 0)
14641468
return ret;
14651469

1470+
if (get_shell_path(NULL)) {
1471+
/* Assume an overridden shell is not MSYS2 */
1472+
ret = 0;
1473+
return ret;
1474+
}
1475+
14661476
p = path_lookup(cmd, 0);
14671477
if (!p)
14681478
ret = 0;

0 commit comments

Comments
 (0)