Skip to content

Commit 59d9442

Browse files
avargitster
authored andcommitted
completion tests: re-source git-completion.bash in a subshell
Change tests of git-completion.bash that re-source it to do so inside a subshell. Re-sourcing it will clobber variables it sets, and in the case of the "GIT_COMPLETION_SHOW_ALL=1" test added in ca2d62b (parse-options: don't complete option aliases by default, 2021-07-16) change the behavior of the completion persistently. Aside from the addition of "(" and ")" on new lines this is an indentation-only change, only the "(" and ")" lines are changed under "git diff -w". So let's change that test, and for good measure do the same for the three tests that precede it, which were added in 8b0eaa4 (completion: clear cached --options when sourcing the completion script, 2018-03-22). The may not be wrong, but doing this establishes a more reliable pattern for future tests, which might use these as a template to copy. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5d01301 commit 59d9442

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

t/t9902-completion.sh

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,40 +2396,48 @@ test_expect_success 'options with value' '
23962396
'
23972397

23982398
test_expect_success 'sourcing the completion script clears cached commands' '
2399-
__git_compute_all_commands &&
2400-
verbose test -n "$__git_all_commands" &&
2401-
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2402-
verbose test -z "$__git_all_commands"
2399+
(
2400+
__git_compute_all_commands &&
2401+
verbose test -n "$__git_all_commands" &&
2402+
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2403+
verbose test -z "$__git_all_commands"
2404+
)
24032405
'
24042406

24052407
test_expect_success 'sourcing the completion script clears cached merge strategies' '
2406-
__git_compute_merge_strategies &&
2407-
verbose test -n "$__git_merge_strategies" &&
2408-
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2409-
verbose test -z "$__git_merge_strategies"
2408+
(
2409+
__git_compute_merge_strategies &&
2410+
verbose test -n "$__git_merge_strategies" &&
2411+
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2412+
verbose test -z "$__git_merge_strategies"
2413+
)
24102414
'
24112415

24122416
test_expect_success 'sourcing the completion script clears cached --options' '
2413-
__gitcomp_builtin checkout &&
2414-
verbose test -n "$__gitcomp_builtin_checkout" &&
2415-
__gitcomp_builtin notes_edit &&
2416-
verbose test -n "$__gitcomp_builtin_notes_edit" &&
2417-
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2418-
verbose test -z "$__gitcomp_builtin_checkout" &&
2419-
verbose test -z "$__gitcomp_builtin_notes_edit"
2417+
(
2418+
__gitcomp_builtin checkout &&
2419+
verbose test -n "$__gitcomp_builtin_checkout" &&
2420+
__gitcomp_builtin notes_edit &&
2421+
verbose test -n "$__gitcomp_builtin_notes_edit" &&
2422+
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2423+
verbose test -z "$__gitcomp_builtin_checkout" &&
2424+
verbose test -z "$__gitcomp_builtin_notes_edit"
2425+
)
24202426
'
24212427

24222428
test_expect_success 'option aliases are not shown by default' '
24232429
test_completion "git clone --recurs" "--recurse-submodules "
24242430
'
24252431

24262432
test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '
2427-
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2428-
GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&
2429-
test_completion "git clone --recurs" <<-\EOF
2430-
--recurse-submodules Z
2431-
--recursive Z
2432-
EOF
2433+
(
2434+
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2435+
GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&
2436+
test_completion "git clone --recurs" <<-\EOF
2437+
--recurse-submodules Z
2438+
--recursive Z
2439+
EOF
2440+
)
24332441
'
24342442

24352443
test_expect_success '__git_complete' '

0 commit comments

Comments
 (0)