Skip to content

Commit 3b49e1b

Browse files
committed
Merge branch 'ma/branch-list-paginate'
"git branch --list" learned to show its output through the pager by default when the output is going to a terminal, which is controlled by the pager.branch configuration variable. This is similar to a recent change to "git tag --list". * ma/branch-list-paginate: branch: change default of `pager.branch` to "on" branch: respect `pager.branch` in list-mode only t7006: add tests for how git branch paginates
2 parents 1616928 + 0ae19de commit 3b49e1b

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

Documentation/git-branch.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ start-point is either a local or remote-tracking branch.
281281
and the object it points at. The format is the same as
282282
that of linkgit:git-for-each-ref[1].
283283

284+
CONFIGURATION
285+
-------------
286+
`pager.branch` is only respected when listing branches, i.e., when
287+
`--list` is used or implied. The default is to use a pager.
288+
See linkgit:git-config[1].
289+
284290
Examples
285291
--------
286292

builtin/branch.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
675675
copy *= 2;
676676
}
677677

678+
if (list)
679+
setup_auto_pager("branch", 1);
680+
678681
if (delete) {
679682
if (!argc)
680683
die(_("branch name required"));

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ static struct cmd_struct commands[] = {
372372
{ "archive", cmd_archive, RUN_SETUP_GENTLY },
373373
{ "bisect--helper", cmd_bisect__helper, RUN_SETUP },
374374
{ "blame", cmd_blame, RUN_SETUP },
375-
{ "branch", cmd_branch, RUN_SETUP },
375+
{ "branch", cmd_branch, RUN_SETUP | DELAY_PAGER_CONFIG },
376376
{ "bundle", cmd_bundle, RUN_SETUP_GENTLY },
377377
{ "cat-file", cmd_cat_file, RUN_SETUP },
378378
{ "check-attr", cmd_check_attr, RUN_SETUP },

t/t7006-pager.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,44 @@ test_expect_success TTY 'git tag as alias respects pager.tag with -l' '
214214
! test -e paginated.out
215215
'
216216

217+
test_expect_success TTY 'git branch defaults to paging' '
218+
rm -f paginated.out &&
219+
test_terminal git branch &&
220+
test -e paginated.out
221+
'
222+
223+
test_expect_success TTY 'git branch respects pager.branch' '
224+
rm -f paginated.out &&
225+
test_terminal git -c pager.branch=false branch &&
226+
! test -e paginated.out
227+
'
228+
229+
test_expect_success TTY 'git branch respects --no-pager' '
230+
rm -f paginated.out &&
231+
test_terminal git --no-pager branch &&
232+
! test -e paginated.out
233+
'
234+
235+
test_expect_success TTY 'git branch --edit-description ignores pager.branch' '
236+
rm -f paginated.out editor.used &&
237+
write_script editor <<-\EOF &&
238+
echo "New description" >"$1"
239+
touch editor.used
240+
EOF
241+
EDITOR=./editor test_terminal git -c pager.branch branch --edit-description &&
242+
! test -e paginated.out &&
243+
test -e editor.used
244+
'
245+
246+
test_expect_success TTY 'git branch --set-upstream-to ignores pager.branch' '
247+
rm -f paginated.out &&
248+
git branch other &&
249+
test_when_finished "git branch -D other" &&
250+
test_terminal git -c pager.branch branch --set-upstream-to=other &&
251+
test_when_finished "git branch --unset-upstream" &&
252+
! test -e paginated.out
253+
'
254+
217255
# A colored commit log will begin with an appropriate ANSI escape
218256
# for the first color; the text "commit" comes later.
219257
colorful() {

0 commit comments

Comments
 (0)