@matheusbsbs / matheus-bagliano / commits / 38a94bb6ba
Fork 0

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>

Tay Ray Chuan committed Nov 23, 2010 at 11:16 UTC 38a94bb6bae683ba5a92969e63f1d3f2cbf41ac0
2 files changed +25
builtin/log.c
+2
@@ -1159,6 +1159,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1159
1160 if (!use_stdout)
1161 output_directory = set_outdir(prefix, output_directory);
1162 + else
1163 + setup_pager();
1164
1165 if (output_directory) {
1166 if (use_stdout)
t/t4014-format-patch.sh
+23
@@ -6,6 +6,7 @@
6 test_description='various format-patch tests'
7
8 . ./test-lib.sh
9 +. "$TEST_DIRECTORY"/lib-terminal.sh
10
11 test_expect_success setup '
12
@@ -686,4 +687,26 @@ test_expect_success 'format-patch --signature="" supresses signatures' '
687 ! grep "^-- \$" output
688 '
689
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 +
712 test_done