Skip to content

Commit 53b3042

Browse files
committed
Merge branch 'jn/paginate-fix'
* jn/paginate-fix: git --paginate: paginate external commands again git --paginate: do not commit pager choice too early tests: local config file should be honored from subdirs of toplevel t7006: test pager configuration for several git commands t7006 (pager): introduce helper for parameterized tests Conflicts: t/t7006-pager.sh
2 parents ea56a7e + 030149a commit 53b3042

File tree

2 files changed

+200
-46
lines changed

2 files changed

+200
-46
lines changed

git.c

Lines changed: 4 additions & 1 deletion
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
/*
@@ -511,12 +514,12 @@ int main(int argc, const char **argv)
511514
argv++;
512515
argc--;
513516
handle_options(&argv, &argc, NULL);
514-
commit_pager_choice();
515517
if (argc > 0) {
516518
if (!prefixcmp(argv[0], "--"))
517519
argv[0] += 2;
518520
} else {
519521
/* The user didn't specify a command; give them help */
522+
commit_pager_choice();
520523
printf("usage: %s\n\n", git_usage_string);
521524
list_common_cmds_help();
522525
printf("\n%s\n", git_more_info_string);

t/t7006-pager.sh

Lines changed: 196 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -164,58 +164,209 @@ then
164164
test_set_prereq SIMPLEPAGERTTY
165165
fi
166166

167-
test_expect_success SIMPLEPAGERTTY 'default pager is used by default' '
168-
unset PAGER GIT_PAGER;
169-
test_might_fail git config --unset core.pager &&
170-
rm -f default_pager_used ||
171-
cleanup_fail &&
167+
# Use this helper to make it easy for the caller of your
168+
# terminal-using function to specify whether it should fail.
169+
# If you write
170+
#
171+
# your_test() {
172+
# parse_args "$@"
173+
#
174+
# $test_expectation "$cmd - behaves well" "
175+
# ...
176+
# $full_command &&
177+
# ...
178+
# "
179+
# }
180+
#
181+
# then your test can be used like this:
182+
#
183+
# your_test expect_(success|failure) [test_must_fail] 'git foo'
184+
#
185+
parse_args() {
186+
test_expectation="test_$1"
187+
shift
188+
if test "$1" = test_must_fail
189+
then
190+
full_command="test_must_fail test_terminal "
191+
shift
192+
else
193+
full_command="test_terminal "
194+
fi
195+
cmd=$1
196+
full_command="$full_command $1"
197+
}
172198

173-
cat >$less <<-\EOF &&
174-
#!/bin/sh
175-
wc >default_pager_used
176-
EOF
177-
chmod +x $less &&
178-
(
179-
PATH=.:$PATH &&
180-
export PATH &&
181-
test_terminal git log
182-
) &&
183-
test -e default_pager_used
184-
'
199+
test_default_pager() {
200+
parse_args "$@"
201+
202+
$test_expectation SIMPLEPAGERTTY "$cmd - default pager is used by default" "
203+
unset PAGER GIT_PAGER;
204+
test_might_fail git config --unset core.pager &&
205+
rm -f default_pager_used ||
206+
cleanup_fail &&
207+
208+
cat >\$less <<-\EOF &&
209+
#!/bin/sh
210+
wc >default_pager_used
211+
EOF
212+
chmod +x \$less &&
213+
(
214+
PATH=.:\$PATH &&
215+
export PATH &&
216+
$full_command
217+
) &&
218+
test -e default_pager_used
219+
"
220+
}
185221

186-
test_expect_success TTY 'PAGER overrides default pager' '
187-
unset GIT_PAGER;
188-
test_might_fail git config --unset core.pager &&
189-
rm -f PAGER_used ||
190-
cleanup_fail &&
222+
test_PAGER_overrides() {
223+
parse_args "$@"
191224

192-
PAGER="wc >PAGER_used" &&
193-
export PAGER &&
194-
test_terminal git log &&
195-
test -e PAGER_used
196-
'
225+
$test_expectation TTY "$cmd - PAGER overrides default pager" "
226+
unset GIT_PAGER;
227+
test_might_fail git config --unset core.pager &&
228+
rm -f PAGER_used ||
229+
cleanup_fail &&
197230
198-
test_expect_success TTY 'core.pager overrides PAGER' '
199-
unset GIT_PAGER;
200-
rm -f core.pager_used ||
201-
cleanup_fail &&
231+
PAGER='wc >PAGER_used' &&
232+
export PAGER &&
233+
$full_command &&
234+
test -e PAGER_used
235+
"
236+
}
202237

203-
PAGER=wc &&
204-
export PAGER &&
205-
git config core.pager "wc >core.pager_used" &&
206-
test_terminal git log &&
207-
test -e core.pager_used
208-
'
238+
test_core_pager_overrides() {
239+
if_local_config=
240+
used_if_wanted='overrides PAGER'
241+
test_core_pager "$@"
242+
}
209243

210-
test_expect_success TTY 'GIT_PAGER overrides core.pager' '
211-
rm -f GIT_PAGER_used ||
212-
cleanup_fail &&
244+
test_local_config_ignored() {
245+
if_local_config='! '
246+
used_if_wanted='is not used'
247+
test_core_pager "$@"
248+
}
213249

214-
git config core.pager wc &&
215-
GIT_PAGER="wc >GIT_PAGER_used" &&
216-
export GIT_PAGER &&
217-
test_terminal git log &&
218-
test -e GIT_PAGER_used
250+
test_core_pager() {
251+
parse_args "$@"
252+
253+
$test_expectation TTY "$cmd - repository-local core.pager setting $used_if_wanted" "
254+
unset GIT_PAGER;
255+
rm -f core.pager_used ||
256+
cleanup_fail &&
257+
258+
PAGER=wc &&
259+
export PAGER &&
260+
git config core.pager 'wc >core.pager_used' &&
261+
$full_command &&
262+
${if_local_config}test -e core.pager_used
263+
"
264+
}
265+
266+
test_core_pager_subdir() {
267+
if_local_config=
268+
used_if_wanted='overrides PAGER'
269+
test_pager_subdir_helper "$@"
270+
}
271+
272+
test_no_local_config_subdir() {
273+
if_local_config='! '
274+
used_if_wanted='is not used'
275+
test_pager_subdir_helper "$@"
276+
}
277+
278+
test_pager_subdir_helper() {
279+
parse_args "$@"
280+
281+
$test_expectation TTY "$cmd - core.pager $used_if_wanted from subdirectory" "
282+
unset GIT_PAGER;
283+
rm -f core.pager_used &&
284+
rm -fr sub ||
285+
cleanup_fail &&
286+
287+
PAGER=wc &&
288+
stampname=\$(pwd)/core.pager_used &&
289+
export PAGER stampname &&
290+
git config core.pager 'wc >\"\$stampname\"' &&
291+
mkdir sub &&
292+
(
293+
cd sub &&
294+
$full_command
295+
) &&
296+
${if_local_config}test -e core.pager_used
297+
"
298+
}
299+
300+
test_GIT_PAGER_overrides() {
301+
parse_args "$@"
302+
303+
$test_expectation TTY "$cmd - GIT_PAGER overrides core.pager" "
304+
rm -f GIT_PAGER_used ||
305+
cleanup_fail &&
306+
307+
git config core.pager wc &&
308+
GIT_PAGER='wc >GIT_PAGER_used' &&
309+
export GIT_PAGER &&
310+
$full_command &&
311+
test -e GIT_PAGER_used
312+
"
313+
}
314+
315+
test_doesnt_paginate() {
316+
parse_args "$@"
317+
318+
$test_expectation TTY "no pager for '$cmd'" "
319+
rm -f GIT_PAGER_used ||
320+
cleanup_fail &&
321+
322+
GIT_PAGER='wc >GIT_PAGER_used' &&
323+
export GIT_PAGER &&
324+
$full_command &&
325+
! test -e GIT_PAGER_used
326+
"
327+
}
328+
329+
test_pager_choices() {
330+
test_default_pager expect_success "$@"
331+
test_PAGER_overrides expect_success "$@"
332+
test_core_pager_overrides expect_success "$@"
333+
test_core_pager_subdir expect_success "$@"
334+
test_GIT_PAGER_overrides expect_success "$@"
335+
}
336+
337+
test_expect_success 'setup: some aliases' '
338+
git config alias.aliasedlog log &&
339+
git config alias.true "!true"
219340
'
220341

342+
test_pager_choices 'git log'
343+
test_pager_choices 'git -p log'
344+
test_pager_choices 'git aliasedlog'
345+
346+
test_default_pager expect_success 'git -p aliasedlog'
347+
test_PAGER_overrides expect_success 'git -p aliasedlog'
348+
test_core_pager_overrides expect_success 'git -p aliasedlog'
349+
test_core_pager_subdir expect_failure 'git -p aliasedlog'
350+
test_GIT_PAGER_overrides expect_success 'git -p aliasedlog'
351+
352+
test_default_pager expect_success 'git -p true'
353+
test_PAGER_overrides expect_success 'git -p true'
354+
test_core_pager_overrides expect_success 'git -p true'
355+
test_core_pager_subdir expect_failure 'git -p true'
356+
test_GIT_PAGER_overrides expect_success 'git -p true'
357+
358+
test_default_pager expect_success test_must_fail 'git -p request-pull'
359+
test_PAGER_overrides expect_success test_must_fail 'git -p request-pull'
360+
test_core_pager_overrides expect_success test_must_fail 'git -p request-pull'
361+
test_core_pager_subdir expect_failure test_must_fail 'git -p request-pull'
362+
test_GIT_PAGER_overrides expect_success test_must_fail 'git -p request-pull'
363+
364+
test_default_pager expect_success test_must_fail 'git -p'
365+
test_PAGER_overrides expect_success test_must_fail 'git -p'
366+
test_local_config_ignored expect_failure test_must_fail 'git -p'
367+
test_no_local_config_subdir expect_success test_must_fail 'git -p'
368+
test_GIT_PAGER_overrides expect_success test_must_fail 'git -p'
369+
370+
test_doesnt_paginate expect_failure test_must_fail 'git -p nonsense'
371+
221372
test_done

0 commit comments

Comments
 (0)