]> asedeno.scripts.mit.edu Git - git.git/blobdiff - t/t7006-pager.sh
git --paginate: do not commit pager choice too early
[git.git] / t / t7006-pager.sh
index b117ebb5a7d6c38804b1396c2f30628e25744636..eefef45cc39fc91e44e9645569b8f08828ea2652 100755 (executable)
@@ -204,62 +204,154 @@ parse_args() {
        full_command="$full_command $1"
 }
 
-parse_args expect_success 'git log'
-$test_expectation SIMPLEPAGER "$cmd - default pager is used by default" "
-       unset PAGER GIT_PAGER;
-       test_might_fail git config --unset core.pager &&
-       rm -f default_pager_used ||
-       cleanup_fail &&
+test_default_pager() {
+       parse_args "$@"
+
+       $test_expectation SIMPLEPAGER "$cmd - default pager is used by default" "
+               unset PAGER GIT_PAGER;
+               test_might_fail git config --unset core.pager &&
+               rm -f default_pager_used ||
+               cleanup_fail &&
+
+               cat >\$less <<-\EOF &&
+               #!/bin/sh
+               wc >default_pager_used
+               EOF
+               chmod +x \$less &&
+               (
+                       PATH=.:\$PATH &&
+                       export PATH &&
+                       $full_command
+               ) &&
+               test -e default_pager_used
+       "
+}
 
-       cat >\$less <<-\EOF &&
-       #!/bin/sh
-       wc >default_pager_used
-       EOF
-       chmod +x \$less &&
-       (
-               PATH=.:\$PATH &&
-               export PATH &&
-               $full_command
-       ) &&
-       test -e default_pager_used
-"
+test_PAGER_overrides() {
+       parse_args "$@"
 
-parse_args expect_success 'git log'
-$test_expectation TTY "$cmd - PAGER overrides default pager" "
-       unset GIT_PAGER;
-       test_might_fail git config --unset core.pager &&
-       rm -f PAGER_used ||
-       cleanup_fail &&
+       $test_expectation TTY "$cmd - PAGER overrides default pager" "
+               unset GIT_PAGER;
+               test_might_fail git config --unset core.pager &&
+               rm -f PAGER_used ||
+               cleanup_fail &&
 
-       PAGER='wc >PAGER_used' &&
-       export PAGER &&
-       $full_command &&
-       test -e PAGER_used
-"
-
-parse_args expect_success 'git log'
-$test_expectation TTY "$cmd - core.pager overrides PAGER" "
-       unset GIT_PAGER;
-       rm -f core.pager_used ||
-       cleanup_fail &&
+               PAGER='wc >PAGER_used' &&
+               export PAGER &&
+               $full_command &&
+               test -e PAGER_used
+       "
+}
 
-       PAGER=wc &&
-       export PAGER &&
-       git config core.pager 'wc >core.pager_used' &&
-       $full_command &&
-       test -e core.pager_used
-"
-
-parse_args expect_success 'git log'
-$test_expectation TTY "$cmd - GIT_PAGER overrides core.pager" "
-       rm -f GIT_PAGER_used ||
-       cleanup_fail &&
+test_core_pager_overrides() {
+       if_local_config=
+       used_if_wanted='overrides PAGER'
+       test_core_pager "$@"
+}
+
+test_local_config_ignored() {
+       if_local_config='! '
+       used_if_wanted='is not used'
+       test_core_pager "$@"
+}
+
+test_core_pager() {
+       parse_args "$@"
+
+       $test_expectation TTY "$cmd - repository-local core.pager setting $used_if_wanted" "
+               unset GIT_PAGER;
+               rm -f core.pager_used ||
+               cleanup_fail &&
+
+               PAGER=wc &&
+               export PAGER &&
+               git config core.pager 'wc >core.pager_used' &&
+               $full_command &&
+               ${if_local_config}test -e core.pager_used
+       "
+}
+
+test_core_pager_subdir() {
+       if_local_config=
+       used_if_wanted='overrides PAGER'
+       test_pager_subdir_helper "$@"
+}
+
+test_no_local_config_subdir() {
+       if_local_config='! '
+       used_if_wanted='is not used'
+       test_pager_subdir_helper "$@"
+}
+
+test_pager_subdir_helper() {
+       parse_args "$@"
+
+       $test_expectation TTY "$cmd - core.pager $used_if_wanted from subdirectory" "
+               unset GIT_PAGER;
+               rm -f core.pager_used &&
+               rm -fr sub ||
+               cleanup_fail &&
+
+               PAGER=wc &&
+               stampname=\$(pwd)/core.pager_used &&
+               export PAGER stampname &&
+               git config core.pager 'wc >\"\$stampname\"' &&
+               mkdir sub &&
+               (
+                       cd sub &&
+                       $full_command
+               ) &&
+               ${if_local_config}test -e core.pager_used
+       "
+}
+
+test_GIT_PAGER_overrides() {
+       parse_args "$@"
+
+       $test_expectation TTY "$cmd - GIT_PAGER overrides core.pager" "
+               rm -f GIT_PAGER_used ||
+               cleanup_fail &&
+
+               git config core.pager wc &&
+               GIT_PAGER='wc >GIT_PAGER_used' &&
+               export GIT_PAGER &&
+               $full_command &&
+               test -e GIT_PAGER_used
+       "
+}
+
+test_doesnt_paginate() {
+       parse_args "$@"
+
+       $test_expectation TTY "no pager for '$cmd'" "
+               rm -f GIT_PAGER_used ||
+               cleanup_fail &&
+
+               GIT_PAGER='wc >GIT_PAGER_used' &&
+               export GIT_PAGER &&
+               $full_command &&
+               ! test -e GIT_PAGER_used
+       "
+}
 
-       git config core.pager wc &&
-       GIT_PAGER='wc >GIT_PAGER_used' &&
-       export GIT_PAGER &&
-       $full_command &&
-       test -e GIT_PAGER_used
-"
+test_default_pager        expect_success 'git log'
+test_PAGER_overrides      expect_success 'git log'
+test_core_pager_overrides expect_success 'git log'
+test_core_pager_subdir    expect_success 'git log'
+test_GIT_PAGER_overrides  expect_success 'git log'
+
+test_default_pager        expect_success 'git -p log'
+test_PAGER_overrides      expect_success 'git -p log'
+test_core_pager_overrides expect_success 'git -p log'
+test_core_pager_subdir    expect_success 'git -p log'
+test_GIT_PAGER_overrides  expect_success 'git -p log'
+
+test_default_pager        expect_success test_must_fail 'git -p'
+test_PAGER_overrides      expect_success test_must_fail 'git -p'
+test_local_config_ignored expect_failure test_must_fail 'git -p'
+test_no_local_config_subdir expect_success test_must_fail 'git -p'
+test_GIT_PAGER_overrides  expect_success test_must_fail 'git -p'
+
+test_doesnt_paginate      expect_success test_must_fail 'git -p nonsense'
 
 test_done