mirror of
https://github.com/git/git.git
synced 2026-01-27 02:48:32 +00:00
run_command_opt(): optionally hide stderr when the command succeeds
This will be needed to hide the output of `git commit` when the sequencer handles an interactive rebase's script. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
@@ -575,6 +575,29 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const
|
||||
cmd.clean_on_exit = opt & RUN_CLEAN_ON_EXIT ? 1 : 0;
|
||||
cmd.dir = dir;
|
||||
cmd.env = env;
|
||||
|
||||
if (opt & RUN_HIDE_STDERR_ON_SUCCESS) {
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
int res;
|
||||
|
||||
cmd.err = -1;
|
||||
if (start_command(&cmd) < 0)
|
||||
return -1;
|
||||
|
||||
if (strbuf_read(&buf, cmd.err, 0) < 0) {
|
||||
close(cmd.err);
|
||||
finish_command(&cmd); /* throw away exit code */
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(cmd.err);
|
||||
res = finish_command(&cmd);
|
||||
if (res)
|
||||
fputs(buf.buf, stderr);
|
||||
strbuf_release(&buf);
|
||||
return res;
|
||||
}
|
||||
|
||||
return run_command(&cmd);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ extern int run_hook_ve(const char *const *env, const char *name, va_list args);
|
||||
#define RUN_SILENT_EXEC_FAILURE 8
|
||||
#define RUN_USING_SHELL 16
|
||||
#define RUN_CLEAN_ON_EXIT 32
|
||||
#define RUN_HIDE_STDERR_ON_SUCCESS 64
|
||||
int run_command_v_opt(const char **argv, int opt);
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user