mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
Allow environment variables to be unset in the processes started by run_command
To unset a variable, just specify its name, without "=". For example: const char *env[] = {"GIT_DIR=.git", "PWD", NULL}; const char *argv[] = {"git-ls-files", "-s", NULL}; int err = run_command_v_opt_cd_env(argv, RUN_GIT_CMD, ".", env); The PWD will be unset before executing git-ls-files. Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
ee4931486b
commit
3427b375b5
@ -77,8 +77,12 @@ int start_command(struct child_process *cmd)
|
||||
die("exec %s: cd to %s failed (%s)", cmd->argv[0],
|
||||
cmd->dir, strerror(errno));
|
||||
if (cmd->env) {
|
||||
for (; *cmd->env; cmd->env++)
|
||||
putenv((char*)*cmd->env);
|
||||
for (; *cmd->env; cmd->env++) {
|
||||
if (strchr(*cmd->env, '='))
|
||||
putenv((char*)*cmd->env);
|
||||
else
|
||||
unsetenv(*cmd->env);
|
||||
}
|
||||
}
|
||||
if (cmd->git_cmd) {
|
||||
execv_git_cmd(cmd->argv);
|
||||
|
@ -35,6 +35,11 @@ int run_command(struct child_process *);
|
||||
#define RUN_COMMAND_STDOUT_TO_STDERR 4
|
||||
int run_command_v_opt(const char **argv, int opt);
|
||||
int run_command_v_opt_cd(const char **argv, int opt, const char *dir);
|
||||
|
||||
/*
|
||||
* env (the environment) is to be formatted like environ: "VAR=VALUE".
|
||||
* To unset an environment variable use just "VAR".
|
||||
*/
|
||||
int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const char *const *env);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user