support pager.* for external commands

Without this patch, any commands that are not builtin would not respect pager.* config. For example: git config pager.stash false git stash list would still use a pager. With this patch, pager.stash now has an effect. If it is not specified, we will still fall back to pager.log when we invoke "log" from "stash list". Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 18, 2011 at 15:01 UTC 92058e4d3e032714da6d2df5fa1fe2cf612979a5
2 files changed +38
git.c
+2
@@ -467,6 +467,8 @@ static void execv_dashed_external(const char **argv)
467 const char *tmp;
468 int status;
469
470 + if (use_pager == -1)
471 + use_pager = check_pager_config(argv[0]);
472 commit_pager_choice();
473
474 strbuf_addf(&cmd, "git-%s", argv[0]);
t/t7006-pager.sh
+36
@@ -450,4 +450,40 @@ test_expect_success TTY 'command-specific pager overridden by environment' '
450 test_cmp expect actual
451 '
452
453 +test_expect_success 'setup external command' '
454 + cat >git-external <<-\EOF &&
455 + #!/bin/sh
456 + git "$@"
457 + EOF
458 + chmod +x git-external
459 +'
460 +
461 +test_expect_success TTY 'command-specific pager works for external commands' '
462 + sane_unset PAGER GIT_PAGER &&
463 + echo "foo:initial" >expect &&
464 + >actual &&
465 + test_config pager.external "sed s/^/foo:/ >actual" &&
466 + test_terminal git --exec-path="`pwd`" external log --format=%s -1 &&
467 + test_cmp expect actual
468 +'
469 +
470 +test_expect_success TTY 'sub-commands of externals use their own pager' '
471 + sane_unset PAGER GIT_PAGER &&
472 + echo "foo:initial" >expect &&
473 + >actual &&
474 + test_config pager.log "sed s/^/foo:/ >actual" &&
475 + test_terminal git --exec-path=. external log --format=%s -1 &&
476 + test_cmp expect actual
477 +'
478 +
479 +test_expect_success TTY 'external command pagers override sub-commands' '
480 + sane_unset PAGER GIT_PAGER &&
481 + >expect &&
482 + >actual &&
483 + test_config pager.external false &&
484 + test_config pager.log "sed s/^/log:/ >actual" &&
485 + test_terminal git --exec-path=. external log --format=%s -1 &&
486 + test_cmp expect actual
487 +'
488 +
489 test_done