]> git.ipfire.org Git - thirdparty/git.git/commitdiff
completion tests: re-source git-completion.bash in a subshell
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 2 Feb 2022 11:15:09 +0000 (12:15 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 2 Feb 2022 21:09:05 +0000 (13:09 -0800)
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
ca2d62b7879 (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
8b0eaa41f23 (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 <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t9902-completion.sh

index 98c628063288bca40f08664abf329340f05a28fa..c9805f2147dc331ee28808d7e737085cddf1d84d 100755 (executable)
@@ -2396,27 +2396,33 @@ test_expect_success 'options with value' '
 '
 
 test_expect_success 'sourcing the completion script clears cached commands' '
-       __git_compute_all_commands &&
-       verbose test -n "$__git_all_commands" &&
-       . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
-       verbose test -z "$__git_all_commands"
+       (
+               __git_compute_all_commands &&
+               verbose test -n "$__git_all_commands" &&
+               . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
+               verbose test -z "$__git_all_commands"
+       )
 '
 
 test_expect_success 'sourcing the completion script clears cached merge strategies' '
-       __git_compute_merge_strategies &&
-       verbose test -n "$__git_merge_strategies" &&
-       . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
-       verbose test -z "$__git_merge_strategies"
+       (
+               __git_compute_merge_strategies &&
+               verbose test -n "$__git_merge_strategies" &&
+               . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
+               verbose test -z "$__git_merge_strategies"
+       )
 '
 
 test_expect_success 'sourcing the completion script clears cached --options' '
-       __gitcomp_builtin checkout &&
-       verbose test -n "$__gitcomp_builtin_checkout" &&
-       __gitcomp_builtin notes_edit &&
-       verbose test -n "$__gitcomp_builtin_notes_edit" &&
-       . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
-       verbose test -z "$__gitcomp_builtin_checkout" &&
-       verbose test -z "$__gitcomp_builtin_notes_edit"
+       (
+               __gitcomp_builtin checkout &&
+               verbose test -n "$__gitcomp_builtin_checkout" &&
+               __gitcomp_builtin notes_edit &&
+               verbose test -n "$__gitcomp_builtin_notes_edit" &&
+               . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
+               verbose test -z "$__gitcomp_builtin_checkout" &&
+               verbose test -z "$__gitcomp_builtin_notes_edit"
+       )
 '
 
 test_expect_success 'option aliases are not shown by default' '
@@ -2424,12 +2430,14 @@ test_expect_success 'option aliases are not shown by default' '
 '
 
 test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '
-       . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
-       GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&
-       test_completion "git clone --recurs" <<-\EOF
-       --recurse-submodules Z
-       --recursive Z
-       EOF
+       (
+               . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
+               GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&
+               test_completion "git clone --recurs" <<-\EOF
+               --recurse-submodules Z
+               --recursive Z
+               EOF
+       )
 '
 
 test_expect_success '__git_complete' '