diff --git a/run-command.c b/run-command.c index e70a8a387b9042..8b319630953a7d 100644 --- a/run-command.c +++ b/run-command.c @@ -280,6 +280,8 @@ char *git_shell_path(void) return xstrdup(SHELL_PATH); #else char *p = locate_in_PATH("sh"); + if (!p) + die(_("cannot find 'sh' in PATH")); convert_slashes(p); return p; #endif diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c index 4a56456894ccff..11da5f75b291ed 100644 --- a/t/helper/test-run-command.c +++ b/t/helper/test-run-command.c @@ -103,6 +103,16 @@ static int test_stdin_pipe_feed(int hook_stdin_fd, void *cb UNUSED, void *task_c return !(*lines_remaining); } +static int shell_path_without_path(void) +{ + char *path; + + unsetenv("PATH"); + path = git_shell_path(); + free(path); + return 0; +} + struct testsuite { struct string_list tests, failed; int next; @@ -450,6 +460,8 @@ int cmd__run_command(int argc, const char **argv) if (argc > 1 && !strcmp(argv[1], "testsuite")) return testsuite(argc - 1, argv + 1); + if (argc > 1 && !strcmp(argv[1], "shell-path-without-path")) + return shell_path_without_path(); if (!strcmp(argv[1], "inherited-handle")) return inherit_handle(argv[0]); if (!strcmp(argv[1], "inherited-handle-child")) diff --git a/t/t0061-run-command.sh b/t/t0061-run-command.sh index 905e90e1f72541..b74a767bfea64a 100755 --- a/t/t0061-run-command.sh +++ b/t/t0061-run-command.sh @@ -16,6 +16,11 @@ test_expect_success MINGW 'subprocess inherits only std handles' ' test-tool run-command inherited-handle ' +test_expect_success MINGW 'missing shell path is reported' ' + test_must_fail test-tool run-command shell-path-without-path 2>err && + test_grep "cannot find .sh. in PATH" err +' + test_expect_success 'start_command reports ENOENT (slash)' ' test-tool run-command start-command-ENOENT ./does-not-exist 2>err && test_grep "\./does-not-exist" err