Skip to content

Commit 92fe7c7

Browse files
dschogitster
authored andcommitted
run-command(win32): resolve the path to the Unix shell early
In 7762975 (Do not use SHELL_PATH from build system in prepare_shell_cmd on Windows, 2012-04-17), the hard-coded path to the Unix shell was replaced by passing `sh` instead when executing Unix shell scripts in Git. This was done because the hard-coded path to the Unix shell is incorrect on Windows because it not only is a Unix-style absolute path instead of a Windows one, but Git uses the runtime prefix feature on Windows, i.e. the correct path cannot be hard-coded. Naturally, the `sh` argument will be resolved to the full path of said executable eventually. To help fixing the bug where `git var GIT_SHELL_PATH` currently does not reflect that logic, but shows that incorrect hard-coded Unix-style absolute path, let's resolve the full path to the `sh` executable early in the `git_shell_path()` function so that we can use it in `git var`, too, and be sure that the output is equivalent to what `run_command()` does when it is asked to execute a command-line using a Unix shell. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f1ed769 commit 92fe7c7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

run-command.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,14 @@ int sane_execvp(const char *file, char * const argv[])
274274
return -1;
275275
}
276276

277-
static const char *git_shell_path(void)
277+
static char *git_shell_path(void)
278278
{
279279
#ifndef GIT_WINDOWS_NATIVE
280-
return SHELL_PATH;
280+
return xstrdup(SHELL_PATH);
281281
#else
282-
return "sh";
282+
char *p = locate_in_PATH("sh");
283+
convert_slashes(p);
284+
return p;
283285
#endif
284286
}
285287

@@ -289,7 +291,7 @@ static const char **prepare_shell_cmd(struct strvec *out, const char **argv)
289291
BUG("shell command is empty");
290292

291293
if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) {
292-
strvec_push(out, git_shell_path());
294+
strvec_push_nodup(out, git_shell_path());
293295
strvec_push(out, "-c");
294296

295297
/*

0 commit comments

Comments
 (0)