git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/2] completion tests: re-source git-completion.bash in a subshell

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Feb 2, 2022, 11:15 UTC
Message-ID
<patch-v2-1.2-cf09546e079-20220202T111228Z-avarab@gmail.com>
In-Reply-To
<cover-v2-0.2-00000000000-20220202T111228Z-avarab@gmail.com>

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>
---
 t/t9902-completion.sh | 50 +++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 21 deletions(-)
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 98c62806328..c9805f2147d 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -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' '
-- 
2.35.0.913.g12b4baa2536
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 12 of 17 in “Some sub-commands can't be completed by TAB key.”
  1. Hongyi ZhaoJan 22, 2022
  2. Johannes SixtJan 22, 2022
  3. Hongyi ZhaoJan 23, 2022
  4. Philippe BlainJan 23, 2022
  5. Junio C HamanoJan 23, 2022
  6. Hongyi ZhaoJan 24, 2022
  7. João Victor BonfimJan 24, 2022
  8. Junio C HamanoJan 25, 2022
  9. completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDSÆvar Arnfjörð Bjarmason, Jan 25, 2022
  10. Junio C HamanoJan 26, 2022
  11. 0/2 completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDSÆvar Arnfjörð Bjarmason, Feb 2, 2022
  12. 1/2 completion tests: re-source git-completion.bash in a subshellÆvar Arnfjörð Bjarmason, Feb 2, 2022
  13. 2/2 completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDSÆvar Arnfjörð Bjarmason, Feb 2, 2022
  14. SZEDER GáborFeb 6, 2022
  15. Junio C HamanoFeb 6, 2022
  16. SZEDER GáborFeb 6, 2022
  17. Junio C HamanoFeb 7, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.