Skip to content

Commit f9a2743

Browse files
j6tgitster
authored andcommitted
Windows: start_command: Support non-NULL dir in struct child_process
A caller of start_command can set the member 'dir' to a directory to request that the child process starts with that directory as CWD. The first user of this feature was added recently in eee49b6 (Teach diff --submodule and status to handle .git files in submodules). On Windows, we have been lazy and had not implemented support for this feature, yet. This fixes the shortcoming. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent eee49b6 commit f9a2743

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

compat/mingw.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ static int env_compare(const void *a, const void *b)
618618
}
619619

620620
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
621+
const char *dir,
621622
int prepend_cmd, int fhin, int fhout, int fherr)
622623
{
623624
STARTUPINFO si;
@@ -697,7 +698,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
697698

698699
memset(&pi, 0, sizeof(pi));
699700
ret = CreateProcess(cmd, args.buf, NULL, NULL, TRUE, flags,
700-
env ? envblk.buf : NULL, NULL, &si, &pi);
701+
env ? envblk.buf : NULL, dir, &si, &pi);
701702

702703
if (env)
703704
strbuf_release(&envblk);
@@ -714,10 +715,11 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
714715
static pid_t mingw_spawnve(const char *cmd, const char **argv, char **env,
715716
int prepend_cmd)
716717
{
717-
return mingw_spawnve_fd(cmd, argv, env, prepend_cmd, 0, 1, 2);
718+
return mingw_spawnve_fd(cmd, argv, env, NULL, prepend_cmd, 0, 1, 2);
718719
}
719720

720721
pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
722+
const char *dir,
721723
int fhin, int fhout, int fherr)
722724
{
723725
pid_t pid;
@@ -740,14 +742,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
740742
pid = -1;
741743
}
742744
else {
743-
pid = mingw_spawnve_fd(iprog, argv, env, 1,
745+
pid = mingw_spawnve_fd(iprog, argv, env, dir, 1,
744746
fhin, fhout, fherr);
745747
free(iprog);
746748
}
747749
argv[0] = argv0;
748750
}
749751
else
750-
pid = mingw_spawnve_fd(prog, argv, env, 0,
752+
pid = mingw_spawnve_fd(prog, argv, env, dir, 0,
751753
fhin, fhout, fherr);
752754
free(prog);
753755
}

compat/mingw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ int mingw_utime(const char *file_name, const struct utimbuf *times);
223223
#define utime mingw_utime
224224

225225
pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
226+
const char *dir,
226227
int fhin, int fhout, int fherr);
227228
void mingw_execvp(const char *cmd, char *const *argv);
228229
#define execvp mingw_execvp

run-command.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,6 @@ int start_command(struct child_process *cmd)
335335
else if (cmd->out > 1)
336336
fhout = dup(cmd->out);
337337

338-
if (cmd->dir)
339-
die("chdir in start_command() not implemented");
340338
if (cmd->env)
341339
env = make_augmented_environ(cmd->env);
342340

@@ -346,7 +344,7 @@ int start_command(struct child_process *cmd)
346344
cmd->argv = prepare_shell_cmd(cmd->argv);
347345
}
348346

349-
cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env,
347+
cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env, cmd->dir,
350348
fhin, fhout, fherr);
351349
failed_errno = errno;
352350
if (cmd->pid < 0 && (!cmd->silent_exec_failure || errno != ENOENT))

0 commit comments

Comments
 (0)