|
9 | 9 | #include "quote.h" |
10 | 10 | #include "config.h" |
11 | 11 |
|
| 12 | +const char *get_shell_path(const char *fallback) |
| 13 | +{ |
| 14 | + static const char *shell; |
| 15 | + static int initialized; |
| 16 | + |
| 17 | + if (!initialized) { |
| 18 | + if (!git_config_get_pathname("core.shell", &shell)) |
| 19 | + setenv("SHELL", shell, 1); |
| 20 | + initialized = 1; |
| 21 | + } |
| 22 | + |
| 23 | + return shell ? shell : fallback; |
| 24 | +} |
| 25 | + |
12 | 26 | void child_process_init(struct child_process *child) |
13 | 27 | { |
14 | 28 | memset(child, 0, sizeof(*child)); |
@@ -271,9 +285,9 @@ static const char **prepare_shell_cmd(struct strvec *out, const char **argv) |
271 | 285 |
|
272 | 286 | if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) { |
273 | 287 | #ifndef GIT_WINDOWS_NATIVE |
274 | | - strvec_push(out, SHELL_PATH); |
| 288 | + strvec_push(out, get_shell_path(SHELL_PATH)); |
275 | 289 | #else |
276 | | - strvec_push(out, "sh"); |
| 290 | + strvec_push(out, get_shell_path("sh")); |
277 | 291 | #endif |
278 | 292 | strvec_push(out, "-c"); |
279 | 293 |
|
@@ -411,7 +425,7 @@ static int prepare_cmd(struct strvec *out, const struct child_process *cmd) |
411 | 425 | * Add SHELL_PATH so in the event exec fails with ENOEXEC we can |
412 | 426 | * attempt to interpret the command with 'sh'. |
413 | 427 | */ |
414 | | - strvec_push(out, SHELL_PATH); |
| 428 | + strvec_push(out, get_shell_path(SHELL_PATH)); |
415 | 429 |
|
416 | 430 | if (cmd->git_cmd) { |
417 | 431 | prepare_git_cmd(out, cmd->argv); |
|
0 commit comments