Skip to content

Commit d816637

Browse files
10ne1gitster
authored andcommitted
hook: allow separate std[out|err] streams
The hook API assumes that all hooks merge stdout to stderr. This assumption is proven wrong by pre-push: some of its users actually expect separate stdout and stderr streams and merging them will cause a regression. Therefore this adds a mechanism to allow pre-push to separate the streams, which will be used in the next commit. The mechanism is generic via struct run_hooks_opt just in case there are any more surprise exceptions like this. Reported-by: Chris Darroch <chrisd@apache.org> Suggested-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent e8ee80c commit d816637

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

hook.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static int pick_next_hook(struct child_process *cp,
8181
cp->in = -1;
8282
}
8383

84-
cp->stdout_to_stderr = 1;
84+
cp->stdout_to_stderr = hook_cb->options->stdout_to_stderr;
8585
cp->trace2_hook_name = hook_cb->hook_name;
8686
cp->dir = hook_cb->options->dir;
8787

hook.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ struct run_hooks_opt
3434
*/
3535
int *invoked_hook;
3636

37+
/**
38+
* Send the hook's stdout to stderr.
39+
*
40+
* This is the default behavior for all hooks except pre-push,
41+
* which has separate stdout and stderr streams for backwards
42+
* compatibility reasons.
43+
*/
44+
unsigned int stdout_to_stderr:1;
45+
3746
/**
3847
* Path to file which should be piped to stdin for each hook.
3948
*/
@@ -80,6 +89,7 @@ struct run_hooks_opt
8089
#define RUN_HOOKS_OPT_INIT { \
8190
.env = STRVEC_INIT, \
8291
.args = STRVEC_INIT, \
92+
.stdout_to_stderr = 1, \
8393
}
8494

8595
struct hook_cb_data {

0 commit comments

Comments
 (0)