[PATCH 10/22] run-command: optionally clear git environment
From: Sven Verdoolaege <skimo@kotnet.org>
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
---
run-command.c | 9 +++++++++
run-command.h | 2 ++
2 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/run-command.c b/run-command.c
index 043b570..806af46 100644
--- a/run-command.c
+++ b/run-command.c
@@ -76,6 +76,14 @@ int start_command(struct child_process *cmd)
if (cmd->dir && chdir(cmd->dir))
die("exec %s: cd to %s failed (%s)", cmd->argv[0],
cmd->dir, strerror(errno));
+ if (cmd->clear_git_env) {
+ unsetenv(ALTERNATE_DB_ENVIRONMENT);
+ unsetenv(DB_ENVIRONMENT);
+ unsetenv(CONFIG_ENVIRONMENT);
+ unsetenv(GIT_DIR_ENVIRONMENT);
+ unsetenv(GRAFT_ENVIRONMENT);
+ unsetenv(INDEX_ENVIRONMENT);
+ }
if (cmd->git_cmd) {
execv_git_cmd(cmd->argv);
} else {
@@ -144,6 +152,7 @@ static void prepare_run_command_v_opt(struct child_process *cmd,
cmd->no_stdin = opt & RUN_COMMAND_NO_STDIN ? 1 : 0;
cmd->git_cmd = opt & RUN_GIT_CMD ? 1 : 0;
cmd->stdout_to_stderr = opt & RUN_COMMAND_STDOUT_TO_STDERR ? 1 : 0;
+ cmd->clear_git_env = opt & RUN_COMMAND_CLEAR_GIT_ENV ? 1 : 0;
}
int run_command_v_opt(const char **argv, int opt)
diff --git a/run-command.h b/run-command.h
index cbd7484..7724118 100644
--- a/run-command.h
+++ b/run-command.h
@@ -23,6 +23,7 @@ struct child_process {
unsigned no_stdout:1;
unsigned git_cmd:1; /* if this is to be git sub-command */
unsigned stdout_to_stderr:1;
+ unsigned clear_git_env:1;
};
int start_command(struct child_process *);
@@ -32,6 +33,7 @@ int run_command(struct child_process *);
#define RUN_COMMAND_NO_STDIN 1
#define RUN_GIT_CMD 2 /*If this is to be git sub-command */
#define RUN_COMMAND_STDOUT_TO_STDERR 4
+#define RUN_COMMAND_CLEAR_GIT_ENV (1 << 3)
int run_command_v_opt(const char **argv, int opt);
int run_command_v_opt_cd(const char **argv, int opt, const char *dir);
--
1.5.2.784.g5532e