Skip to content

Commit 38a94bb

Browse files
rctaygitster
authored andcommitted
format-patch: page output with --stdout
Pass output through the pager if format-patch is run with --stdout. This saves the user the trouble of running git with '-p' or piping through a pager. setup_pager() already checks if stdout is a tty, so we don't have to worry about behaviour if the user redirects/pipes stdout. Paging can also be disabled with the config [pager] format-patch = false Add tests to check for these behaviour. Helped-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 03276d9 commit 38a94bb

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

builtin/log.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
11591159

11601160
if (!use_stdout)
11611161
output_directory = set_outdir(prefix, output_directory);
1162+
else
1163+
setup_pager();
11621164

11631165
if (output_directory) {
11641166
if (use_stdout)

t/t4014-format-patch.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
test_description='various format-patch tests'
77

88
. ./test-lib.sh
9+
. "$TEST_DIRECTORY"/lib-terminal.sh
910

1011
test_expect_success setup '
1112
@@ -686,4 +687,26 @@ test_expect_success 'format-patch --signature="" supresses signatures' '
686687
! grep "^-- \$" output
687688
'
688689

690+
test_expect_success TTY 'format-patch --stdout paginates' '
691+
rm -f pager_used &&
692+
(
693+
GIT_PAGER="wc >pager_used" &&
694+
export GIT_PAGER &&
695+
test_terminal git format-patch --stdout --all
696+
) &&
697+
test_path_is_file pager_used
698+
'
699+
700+
test_expect_success TTY 'format-patch --stdout pagination can be disabled' '
701+
rm -f pager_used &&
702+
(
703+
GIT_PAGER="wc >pager_used" &&
704+
export GIT_PAGER &&
705+
test_terminal git --no-pager format-patch --stdout --all &&
706+
test_terminal git -c "pager.format-patch=false" format-patch --stdout --all
707+
) &&
708+
test_path_is_missing pager_used &&
709+
test_path_is_missing .git/pager_used
710+
'
711+
689712
test_done

0 commit comments

Comments
 (0)