Skip to content

Commit 4316520

Browse files
committed
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>
1 parent 350cb33 commit 4316520

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

run-command.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,29 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const
576576
cmd.clean_on_exit = opt & RUN_CLEAN_ON_EXIT ? 1 : 0;
577577
cmd.dir = dir;
578578
cmd.env = env;
579+
580+
if (opt & RUN_HIDE_STDERR_ON_SUCCESS) {
581+
struct strbuf buf = STRBUF_INIT;
582+
int res;
583+
584+
cmd.err = -1;
585+
if (start_command(&cmd) < 0)
586+
return -1;
587+
588+
if (strbuf_read(&buf, cmd.err, 0) < 0) {
589+
close(cmd.err);
590+
finish_command(&cmd); /* throw away exit code */
591+
return -1;
592+
}
593+
594+
close(cmd.err);
595+
res = finish_command(&cmd);
596+
if (res)
597+
fputs(buf.buf, stderr);
598+
strbuf_release(&buf);
599+
return res;
600+
}
601+
579602
return run_command(&cmd);
580603
}
581604

run-command.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ extern int run_hook_ve(const char *const *env, const char *name, va_list args);
7070
#define RUN_SILENT_EXEC_FAILURE 8
7171
#define RUN_USING_SHELL 16
7272
#define RUN_CLEAN_ON_EXIT 32
73+
#define RUN_HIDE_STDERR_ON_SUCCESS 64
7374
int run_command_v_opt(const char **argv, int opt);
7475

7576
/*

0 commit comments

Comments
 (0)