From ed104fa9e1016f8ac5f85642ed11e16b09510bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C3=85gren?= Date: Sun, 19 Nov 2017 16:03:48 +0100 Subject: t7006: add tests for how git branch paginates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The next couple of commits will change how `git branch` handles `pager.branch`, similar to how de121ffe5 (tag: respect `pager.tag` in list-mode only, 2017-08-02) and ff1e72483 (tag: change default of `pager.tag` to "on", 2017-08-02) changed `git tag`. Add tests in this area to make sure that we don't regress and so that the upcoming commits can be made clearer by adapting the tests. Add some tests for `--list` (implied), one for `--edit-description`, and one for `--set-upstream-to` as a representative of "something other than the first two". In particular, use `test_expect_failure` to document that we currently respect the pager-configuration with `--edit-description`. The current behavior is buggy since the pager interferes with the editor and makes the end result completely broken. See also b3ee740c8 (t7006: add tests for how git tag paginates, 2017-08-02). Signed-off-by: Martin Ågren Signed-off-by: Junio C Hamano --- t/t7006-pager.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index 9128ec5acd..12c72ef967 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -214,6 +214,44 @@ test_expect_success TTY 'git tag as alias respects pager.tag with -l' ' ! test -e paginated.out ' +test_expect_success TTY 'git branch defaults to not paging' ' + rm -f paginated.out && + test_terminal git branch && + ! test -e paginated.out +' + +test_expect_success TTY 'git branch respects pager.branch' ' + rm -f paginated.out && + test_terminal git -c pager.branch branch && + test -e paginated.out +' + +test_expect_success TTY 'git branch respects --no-pager' ' + rm -f paginated.out && + test_terminal git -c pager.branch --no-pager branch && + ! test -e paginated.out +' + +test_expect_failure TTY 'git branch --edit-description ignores pager.branch' ' + rm -f paginated.out editor.used && + write_script editor <<-\EOF && + echo "New description" >"$1" + touch editor.used + EOF + EDITOR=./editor test_terminal git -c pager.branch branch --edit-description && + ! test -e paginated.out && + test -e editor.used +' + +test_expect_success TTY 'git branch --set-upstream-to respects pager.branch' ' + rm -f paginated.out && + git branch other && + test_when_finished "git branch -D other" && + test_terminal git -c pager.branch branch --set-upstream-to=other && + test_when_finished "git branch --unset-upstream" && + test -e paginated.out +' + # A colored commit log will begin with an appropriate ANSI escape # for the first color; the text "commit" comes later. colorful() { -- cgit v1.2.1 From d74b541e0b40be0bf35e836bd8c6cbf653283d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C3=85gren?= Date: Sun, 19 Nov 2017 16:03:49 +0100 Subject: branch: respect `pager.branch` in list-mode only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similar to de121ffe5 (tag: respect `pager.tag` in list-mode only, 2017-08-02), use the DELAY_PAGER_CONFIG-mechanism to only respect `pager.branch` when we are listing branches. We have two possibilities of generalizing what that earlier commit made to `git tag`. One is to interpret, e.g., --set-upstream-to as "it does not use an editor, so we should page". Another, the one taken by this commit, is to say "it does not list, so let's not page". That is in line with the approach of the series on `pager.tag` and in particular the wording in Documentation/git-tag.txt, which this commit reuses for git-branch.txt. This fixes the failing test added in the previous commit. Also adapt the test for whether `git branch --set-upstream-to` respects `pager.branch`. Signed-off-by: Martin Ågren Signed-off-by: Junio C Hamano --- Documentation/git-branch.txt | 6 ++++++ builtin/branch.c | 3 +++ git.c | 2 +- t/t7006-pager.sh | 6 +++--- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt index 81bd0a7b77..9dae1ea295 100644 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@ -271,6 +271,12 @@ start-point is either a local or remote-tracking branch. pointed at by a ref being shown. The format is the same as that of linkgit:git-for-each-ref[1]. +CONFIGURATION +------------- +`pager.branch` is only respected when listing branches, i.e., when +`--list` is used or implied. +See linkgit:git-config[1]. + Examples -------- diff --git a/builtin/branch.c b/builtin/branch.c index 8a0595e115..3eb31cd1ed 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -648,6 +648,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix) rename *= 2; } + if (list) + setup_auto_pager("branch", 0); + if (delete) { if (!argc) die(_("branch name required")); diff --git a/git.c b/git.c index 6b6d9f68e1..df66b8b2e0 100644 --- a/git.c +++ b/git.c @@ -368,7 +368,7 @@ static struct cmd_struct commands[] = { { "archive", cmd_archive, RUN_SETUP_GENTLY }, { "bisect--helper", cmd_bisect__helper, RUN_SETUP }, { "blame", cmd_blame, RUN_SETUP }, - { "branch", cmd_branch, RUN_SETUP }, + { "branch", cmd_branch, RUN_SETUP | DELAY_PAGER_CONFIG }, { "bundle", cmd_bundle, RUN_SETUP_GENTLY }, { "cat-file", cmd_cat_file, RUN_SETUP }, { "check-attr", cmd_check_attr, RUN_SETUP }, diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index 12c72ef967..5998f7135b 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -232,7 +232,7 @@ test_expect_success TTY 'git branch respects --no-pager' ' ! test -e paginated.out ' -test_expect_failure TTY 'git branch --edit-description ignores pager.branch' ' +test_expect_success TTY 'git branch --edit-description ignores pager.branch' ' rm -f paginated.out editor.used && write_script editor <<-\EOF && echo "New description" >"$1" @@ -243,13 +243,13 @@ test_expect_failure TTY 'git branch --edit-description ignores pager.branch' ' test -e editor.used ' -test_expect_success TTY 'git branch --set-upstream-to respects pager.branch' ' +test_expect_success TTY 'git branch --set-upstream-to ignores pager.branch' ' rm -f paginated.out && git branch other && test_when_finished "git branch -D other" && test_terminal git -c pager.branch branch --set-upstream-to=other && test_when_finished "git branch --unset-upstream" && - test -e paginated.out + ! test -e paginated.out ' # A colored commit log will begin with an appropriate ANSI escape -- cgit v1.2.1 From 0ae19de74f6f5d6c6f9c80899e1ecd611c5b9827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C3=85gren?= Date: Sun, 19 Nov 2017 16:03:50 +0100 Subject: branch: change default of `pager.branch` to "on" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is similar to ff1e72483 (tag: change default of `pager.tag` to "on", 2017-08-02) and is safe now that we do not consider `pager.branch` at all when we are not listing branches. This change will help with listing many branches, but will not hurt users of `git branch --edit-description` as it would have before the previous commit. Signed-off-by: Martin Ågren Signed-off-by: Junio C Hamano --- Documentation/git-branch.txt | 2 +- builtin/branch.c | 2 +- t/t7006-pager.sh | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt index 9dae1ea295..ef187ba7cf 100644 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@ -274,7 +274,7 @@ start-point is either a local or remote-tracking branch. CONFIGURATION ------------- `pager.branch` is only respected when listing branches, i.e., when -`--list` is used or implied. +`--list` is used or implied. The default is to use a pager. See linkgit:git-config[1]. Examples diff --git a/builtin/branch.c b/builtin/branch.c index 3eb31cd1ed..39fa99bba7 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -649,7 +649,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) } if (list) - setup_auto_pager("branch", 0); + setup_auto_pager("branch", 1); if (delete) { if (!argc) diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index 5998f7135b..f59dfd1432 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -214,21 +214,21 @@ test_expect_success TTY 'git tag as alias respects pager.tag with -l' ' ! test -e paginated.out ' -test_expect_success TTY 'git branch defaults to not paging' ' +test_expect_success TTY 'git branch defaults to paging' ' rm -f paginated.out && test_terminal git branch && - ! test -e paginated.out + test -e paginated.out ' test_expect_success TTY 'git branch respects pager.branch' ' rm -f paginated.out && - test_terminal git -c pager.branch branch && - test -e paginated.out + test_terminal git -c pager.branch=false branch && + ! test -e paginated.out ' test_expect_success TTY 'git branch respects --no-pager' ' rm -f paginated.out && - test_terminal git -c pager.branch --no-pager branch && + test_terminal git --no-pager branch && ! test -e paginated.out ' -- cgit v1.2.1