]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rebase --exec: respect --quiet
authorMatheus Tavares <matheus.tavb@gmail.com>
Wed, 21 Aug 2024 01:31:52 +0000 (22:31 -0300)
committerJunio C Hamano <gitster@pobox.com>
Wed, 21 Aug 2024 15:57:51 +0000 (08:57 -0700)
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 <lincolnyuji@hotmail.com>
Reported-by: Rodrigo Siqueira <siqueirajordao@riseup.net>
Signed-off-by: Matheus Tavares <matheus.tavb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pager.c
sequencer.c
t/t3400-rebase.sh

diff --git a/pager.c b/pager.c
index 896f40fcd24c8ec4e8856496bebd5095b3e6ee64..9c24ce6263385eb4af306453c1eb2668edd3af1e 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -234,6 +234,8 @@ int term_columns(void)
  */
 void term_clear_line(void)
 {
+       if (!isatty(2))
+               return;
        if (is_terminal_dumb())
                /*
                 * Fall back to print a terminal width worth of space
index 0291920f0b753fe30eb6c6e456017d4f9cc43607..65c485d783ba807c4deabeb883efba10d7189c78 100644 (file)
@@ -3793,12 +3793,13 @@ static int error_failed_squash(struct repository *r,
        return error_with_patch(r, commit, subject, subject_len, opts, 1, 0);
 }
 
-static int do_exec(struct repository *r, const char *command_line)
+static int do_exec(struct repository *r, const char *command_line, int quiet)
 {
        struct child_process cmd = CHILD_PROCESS_INIT;
        int dirty, status;
 
-       fprintf(stderr, _("Executing: %s\n"), command_line);
+       if (!quiet)
+               fprintf(stderr, _("Executing: %s\n"), command_line);
        cmd.use_shell = 1;
        strvec_push(&cmd.args, command_line);
        strvec_push(&cmd.env, "GIT_CHERRY_PICK_HELP");
@@ -5013,7 +5014,7 @@ static int pick_commits(struct repository *r,
                        if (!opts->verbose)
                                term_clear_line();
                        *end_of_arg = '\0';
-                       res = do_exec(r, arg);
+                       res = do_exec(r, arg, opts->quiet);
                        *end_of_arg = saved;
 
                        if (res) {
index ae34bfad6071fbb40973eb3b01f1d28e360aa0d9..bd8bcc381ad867b9bcb626a6c59965c821ccadd7 100755 (executable)
@@ -235,6 +235,12 @@ test_expect_success 'rebase --merge -q is quiet' '
        test_must_be_empty output.out
 '
 
+test_expect_success 'rebase --exec -q is quiet' '
+       git checkout -B quiet topic &&
+       git rebase --exec true -q main >output.out 2>&1 &&
+       test_must_be_empty output.out
+'
+
 test_expect_success 'Rebase a commit that sprinkles CRs in' '
        (
                echo "One" &&