Skip to content

Commit

Permalink
format-patch: page output with --stdout
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Tay Ray Chuan <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
rctay authored and gitster committed Nov 23, 2010
1 parent 03276d9 commit 38a94bb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)

if (!use_stdout)
output_directory = set_outdir(prefix, output_directory);
else
setup_pager();

if (output_directory) {
if (use_stdout)
Expand Down
23 changes: 23 additions & 0 deletions t/t4014-format-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
test_description='various format-patch tests'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-terminal.sh

test_expect_success setup '
Expand Down Expand Up @@ -686,4 +687,26 @@ test_expect_success 'format-patch --signature="" supresses signatures' '
! grep "^-- \$" output
'

test_expect_success TTY 'format-patch --stdout paginates' '
rm -f pager_used &&
(
GIT_PAGER="wc >pager_used" &&
export GIT_PAGER &&
test_terminal git format-patch --stdout --all
) &&
test_path_is_file pager_used
'

test_expect_success TTY 'format-patch --stdout pagination can be disabled' '
rm -f pager_used &&
(
GIT_PAGER="wc >pager_used" &&
export GIT_PAGER &&
test_terminal git --no-pager format-patch --stdout --all &&
test_terminal git -c "pager.format-patch=false" format-patch --stdout --all
) &&
test_path_is_missing pager_used &&
test_path_is_missing .git/pager_used
'

test_done

0 comments on commit 38a94bb

Please sign in to comment.