Skip to content

Commit 9d225b0

Browse files
rjustogitster
authored andcommitted
add-patch: do not show UI messages on stderr
There is no need to show some UI messages on stderr, and yet doing so may produce some undesirable results, such as messages appearing in an unexpected order. Let's use stdout for all UI messages, and adjusts the tests accordingly. Signed-off-by: Rubén Justo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ae3196a commit 9d225b0

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

add-patch.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,9 @@ static void err(struct add_p_state *s, const char *fmt, ...)
293293
va_list args;
294294

295295
va_start(args, fmt);
296-
fputs(s->s.error_color, stderr);
297-
vfprintf(stderr, fmt, args);
298-
fputs(s->s.reset_color, stderr);
299-
fputc('\n', stderr);
296+
fputs(s->s.error_color, stdout);
297+
vprintf(fmt, args);
298+
puts(s->s.reset_color);
300299
va_end(args);
301300
}
302301

@@ -1326,7 +1325,7 @@ static int apply_for_checkout(struct add_p_state *s, struct strbuf *diff,
13261325
err(s, _("Nothing was applied.\n"));
13271326
} else
13281327
/* As a last resort, show the diff to the user */
1329-
fwrite(diff->buf, diff->len, 1, stderr);
1328+
fwrite(diff->buf, diff->len, 1, stdout);
13301329

13311330
return 0;
13321331
}
@@ -1777,9 +1776,9 @@ int run_add_p(struct repository *r, enum add_p_mode mode,
17771776
break;
17781777

17791778
if (s.file_diff_nr == 0)
1780-
fprintf(stderr, _("No changes.\n"));
1779+
err(&s, _("No changes."));
17811780
else if (binary_count == s.file_diff_nr)
1782-
fprintf(stderr, _("Only binary files changed.\n"));
1781+
err(&s, _("Only binary files changed."));
17831782

17841783
add_p_state_clear(&s);
17851784
return 0;

t/t3701-add-interactive.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ test_expect_success 'warn about add.interactive.useBuiltin' '
4444
cat >expect <<-\EOF &&
4545
warning: the add.interactive.useBuiltin setting has been removed!
4646
See its entry in '\''git help config'\'' for details.
47-
No changes.
4847
EOF
48+
echo "No changes." >expect.out &&
4949
5050
for v in = =true =false
5151
do
5252
git -c "add.interactive.useBuiltin$v" add -p >out 2>actual &&
53-
test_must_be_empty out &&
53+
test_cmp expect.out out &&
5454
test_cmp expect actual || return 1
5555
done
5656
'
@@ -334,13 +334,13 @@ test_expect_success 'different prompts for mode change/deleted' '
334334

335335
test_expect_success 'correct message when there is nothing to do' '
336336
git reset --hard &&
337-
git add -p 2>err &&
338-
test_grep "No changes" err &&
337+
git add -p >out &&
338+
test_grep "No changes" out &&
339339
printf "\\0123" >binary &&
340340
git add binary &&
341341
printf "\\0abc" >binary &&
342-
git add -p 2>err &&
343-
test_grep "Only binary files changed" err
342+
git add -p >out &&
343+
test_grep "Only binary files changed" out
344344
'
345345

346346
test_expect_success 'setup again' '

0 commit comments

Comments
 (0)