From 3427b375b594b93ed47ae80ca1d6bb361d7d8f5e Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Wed, 23 May 2007 22:21:39 +0200 Subject: 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 Signed-off-by: Junio C Hamano --- run-command.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'run-command.c') diff --git a/run-command.c b/run-command.c index 4ee4bdf16..7e779d33e 100644 --- a/run-command.c +++ b/run-command.c @@ -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); -- cgit v1.2.1