Skip to content

Commit 4bdd6b7

Browse files
matheustavaresgitster
authored andcommitted
rebase --exec: respect --quiet
rebase --exec doesn't obey --quiet and ends up printing messages about the command being executed: git rebase HEAD~3 --quiet --exec true Executing: true Executing: true Executing: true Let's fix that by omitting the "Executing" messages when using --quiet. Furthermore, the sequencer code includes a few calls to term_clear_line(), which prints a special character sequence to erase the previous line displayed on stderr (even when nothing was printed yet). For an user running the command interactively, the net effect of calling this function with or without --quiet is the same as the characters are invisible in the terminal. However, when redirecting the output to a file or piping to another command, the presence of these invisible characters is noticeable, and it may break user expectation as --quiet is not being respected. We could skip the term_clear_line() calls when --quiet is used, like we are doing with the "Executing" messages, but it makes much more sense to condition the line cleaning upon stderr being TTY, since these characters are really only useful for TTY outputs. The added test checks for both these two changes. Reported-by: Lincoln Yuji <[email protected]> Reported-by: Rodrigo Siqueira <[email protected]> Signed-off-by: Matheus Tavares <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 87a1768 commit 4bdd6b7

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

pager.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ int term_columns(void)
234234
*/
235235
void term_clear_line(void)
236236
{
237+
if (!isatty(2))
238+
return;
237239
if (is_terminal_dumb())
238240
/*
239241
* Fall back to print a terminal width worth of space

sequencer.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3793,12 +3793,13 @@ static int error_failed_squash(struct repository *r,
37933793
return error_with_patch(r, commit, subject, subject_len, opts, 1, 0);
37943794
}
37953795

3796-
static int do_exec(struct repository *r, const char *command_line)
3796+
static int do_exec(struct repository *r, const char *command_line, int quiet)
37973797
{
37983798
struct child_process cmd = CHILD_PROCESS_INIT;
37993799
int dirty, status;
38003800

3801-
fprintf(stderr, _("Executing: %s\n"), command_line);
3801+
if (!quiet)
3802+
fprintf(stderr, _("Executing: %s\n"), command_line);
38023803
cmd.use_shell = 1;
38033804
strvec_push(&cmd.args, command_line);
38043805
strvec_push(&cmd.env, "GIT_CHERRY_PICK_HELP");
@@ -5013,7 +5014,7 @@ static int pick_commits(struct repository *r,
50135014
if (!opts->verbose)
50145015
term_clear_line();
50155016
*end_of_arg = '\0';
5016-
res = do_exec(r, arg);
5017+
res = do_exec(r, arg, opts->quiet);
50175018
*end_of_arg = saved;
50185019

50195020
if (res) {

t/t3400-rebase.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ test_expect_success 'rebase --merge -q is quiet' '
235235
test_must_be_empty output.out
236236
'
237237

238+
test_expect_success 'rebase --exec -q is quiet' '
239+
git checkout -B quiet topic &&
240+
git rebase --exec true -q main >output.out 2>&1 &&
241+
test_must_be_empty output.out
242+
'
243+
238244
test_expect_success 'Rebase a commit that sprinkles CRs in' '
239245
(
240246
echo "One" &&

0 commit comments

Comments
 (0)