|
1 | 1 | #define DISABLE_SIGN_COMPARE_WARNINGS |
| 2 | +#define USE_THE_REPOSITORY_VARIABLE |
2 | 3 |
|
3 | 4 | #include "git-compat-util.h" |
4 | 5 | #include "run-command.h" |
|
18 | 19 | #include "packfile.h" |
19 | 20 | #include "compat/nonblock.h" |
20 | 21 |
|
| 22 | +const char *get_shell_path(const char *fallback) |
| 23 | +{ |
| 24 | + static char *shell; |
| 25 | + static int initialized; |
| 26 | + |
| 27 | + if (!initialized) { |
| 28 | + if (!repo_config_get_pathname(the_repository, "core.shell", &shell)) |
| 29 | + setenv("SHELL", shell, 1); |
| 30 | + initialized = 1; |
| 31 | + } |
| 32 | + |
| 33 | + return shell ? shell : fallback; |
| 34 | +} |
| 35 | + |
21 | 36 | void child_process_init(struct child_process *child) |
22 | 37 | { |
23 | 38 | struct child_process blank = CHILD_PROCESS_INIT; |
@@ -276,12 +291,19 @@ int sane_execvp(const char *file, char * const argv[]) |
276 | 291 |
|
277 | 292 | char *git_shell_path(void) |
278 | 293 | { |
| 294 | + const char *shell = get_shell_path(NULL); |
| 295 | + |
| 296 | + if (shell) |
| 297 | + return xstrdup(shell); |
| 298 | + |
279 | 299 | #ifndef GIT_WINDOWS_NATIVE |
280 | 300 | return xstrdup(SHELL_PATH); |
281 | 301 | #else |
282 | | - char *p = locate_in_PATH("sh"); |
283 | | - convert_slashes(p); |
284 | | - return p; |
| 302 | + { |
| 303 | + char *p = locate_in_PATH("sh"); |
| 304 | + convert_slashes(p); |
| 305 | + return p; |
| 306 | + } |
285 | 307 | #endif |
286 | 308 | } |
287 | 309 |
|
@@ -416,7 +438,7 @@ static int prepare_cmd(struct strvec *out, const struct child_process *cmd) |
416 | 438 | * Add SHELL_PATH so in the event exec fails with ENOEXEC we can |
417 | 439 | * attempt to interpret the command with 'sh'. |
418 | 440 | */ |
419 | | - strvec_push(out, SHELL_PATH); |
| 441 | + strvec_push(out, get_shell_path(SHELL_PATH)); |
420 | 442 |
|
421 | 443 | if (cmd->git_cmd) { |
422 | 444 | prepare_git_cmd(out, cmd->args.v); |
|
0 commit comments