Skip to content

Commit 92058e4

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c9bfb95 commit 92058e4

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

git.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ static void execv_dashed_external(const char **argv)
467467
const char *tmp;
468468
int status;
469469

470+
if (use_pager == -1)
471+
use_pager = check_pager_config(argv[0]);
470472
commit_pager_choice();
471473

472474
strbuf_addf(&cmd, "git-%s", argv[0]);

t/t7006-pager.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,4 +450,40 @@ test_expect_success TTY 'command-specific pager overridden by environment' '
450450
test_cmp expect actual
451451
'
452452

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+
453489
test_done

0 commit comments

Comments
 (0)