Skip to content

Commit 030149a

Browse files
jrngitster
authored andcommitted
git --paginate: paginate external commands again
73e25e7 (git --paginate: do not commit pager choice too early, 2010-06-26) failed to take some cases into account. 1b. Builtins that do not use RUN_SETUP (like git config) do not find GIT_DIR set correctly when the pager is launched from run_builtin(). So the core.pager configuration is not honored from subdirectories of the toplevel for them. 4a. External git commands (like git request-pull) relied on the early pager launch to take care of handling the -p option. Ever since 73e25e7, they do not honor the -p option at all. 4b. Commands invoked through ! aliases (like ls) were also relying on the early pager launch. Fix (4a) by launching the pager (if requested) before running such a “dashed external”. For simplicity, this still does not search for a .git directory before running the external command; when run from a subdirectory of the toplevel, therefore, the “[core] pager” configuration is still not honored. Fix (4b) by launching pager if requested before carrying out such an alias. Actually doing this has no effect, since the pager (if any) would have already been launched in a failed attempt to try a dashed external first. The choice-of-pager-not-honored-from- subdirectory bug still applies here, too. (1b) is not a regression. There is no need to fix it yet. Noticed by Junio. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 73e25e7 commit 030149a

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

git.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ static int handle_alias(int *argcp, const char ***argv)
167167
alias_string = alias_lookup(alias_command);
168168
if (alias_string) {
169169
if (alias_string[0] == '!') {
170+
commit_pager_choice();
170171
if (*argcp > 1) {
171172
struct strbuf buf;
172173

@@ -432,6 +433,8 @@ static void execv_dashed_external(const char **argv)
432433
const char *tmp;
433434
int status;
434435

436+
commit_pager_choice();
437+
435438
strbuf_addf(&cmd, "git-%s", argv[0]);
436439

437440
/*

t/t7006-pager.sh

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -334,24 +334,47 @@ test_doesnt_paginate() {
334334
"
335335
}
336336

337-
test_default_pager expect_success 'git log'
338-
test_PAGER_overrides expect_success 'git log'
339-
test_core_pager_overrides expect_success 'git log'
340-
test_core_pager_subdir expect_success 'git log'
341-
test_GIT_PAGER_overrides expect_success 'git log'
342-
343-
test_default_pager expect_success 'git -p log'
344-
test_PAGER_overrides expect_success 'git -p log'
345-
test_core_pager_overrides expect_success 'git -p log'
346-
test_core_pager_subdir expect_success 'git -p log'
347-
test_GIT_PAGER_overrides expect_success 'git -p log'
337+
test_pager_choices() {
338+
test_default_pager expect_success "$@"
339+
test_PAGER_overrides expect_success "$@"
340+
test_core_pager_overrides expect_success "$@"
341+
test_core_pager_subdir expect_success "$@"
342+
test_GIT_PAGER_overrides expect_success "$@"
343+
}
344+
345+
test_expect_success 'setup: some aliases' '
346+
git config alias.aliasedlog log &&
347+
git config alias.true "!true"
348+
'
349+
350+
test_pager_choices 'git log'
351+
test_pager_choices 'git -p log'
352+
test_pager_choices 'git aliasedlog'
353+
354+
test_default_pager expect_success 'git -p aliasedlog'
355+
test_PAGER_overrides expect_success 'git -p aliasedlog'
356+
test_core_pager_overrides expect_success 'git -p aliasedlog'
357+
test_core_pager_subdir expect_failure 'git -p aliasedlog'
358+
test_GIT_PAGER_overrides expect_success 'git -p aliasedlog'
359+
360+
test_default_pager expect_success 'git -p true'
361+
test_PAGER_overrides expect_success 'git -p true'
362+
test_core_pager_overrides expect_success 'git -p true'
363+
test_core_pager_subdir expect_failure 'git -p true'
364+
test_GIT_PAGER_overrides expect_success 'git -p true'
365+
366+
test_default_pager expect_success test_must_fail 'git -p request-pull'
367+
test_PAGER_overrides expect_success test_must_fail 'git -p request-pull'
368+
test_core_pager_overrides expect_success test_must_fail 'git -p request-pull'
369+
test_core_pager_subdir expect_failure test_must_fail 'git -p request-pull'
370+
test_GIT_PAGER_overrides expect_success test_must_fail 'git -p request-pull'
348371

349372
test_default_pager expect_success test_must_fail 'git -p'
350373
test_PAGER_overrides expect_success test_must_fail 'git -p'
351374
test_local_config_ignored expect_failure test_must_fail 'git -p'
352375
test_no_local_config_subdir expect_success test_must_fail 'git -p'
353376
test_GIT_PAGER_overrides expect_success test_must_fail 'git -p'
354377

355-
test_doesnt_paginate expect_success test_must_fail 'git -p nonsense'
378+
test_doesnt_paginate expect_failure test_must_fail 'git -p nonsense'
356379

357380
test_done

0 commit comments

Comments
 (0)