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

[PATCH 2/3] t9902: add completion tests for "odd" filenames

From
Jeff King <peff@peff.net>
Date
Sep 26, 2012, 21:51 UTC
Message-ID
<20120926215106.GB18653@sigill.intra.peff.net>
In-Reply-To
<20120926214653.GA18628@sigill.intra.peff.net>

We correctly handle completion items with spaces just fine, since we pass the lists around with newline delimiters. However, we do not handle filenames with shell metacharacters, as "compgen -W" performs expansion on the list we give it.

Signed-off-by: Jeff King <peff@peff.net>
---
Actually, these vectors are not strictly correct, as I think ultimately
we would like to return
  'name with spaces'

with quotes. But this lets us test that at least the basics work, and we can update the test vectors later.

It would be nice to test completion on a file with an embedded newline (which will also not work), but I'm not even sure what the result is supposed to look like, so I couldn't write a sane test case. Since I don't plan on fixing that anytime soon anyway, I think it's sane to just leave it until later if somebody actually cares.

 t/t9902-completion.sh | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 2fc833a..cbd0fb6 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -269,4 +269,23 @@ test_expect_success '<ref>: completes paths' '
 	EOF
 '
 
+test_expect_success 'complete tree filename with spaces' '
+	echo content >"name with spaces" &&
+	git add . &&
+	git commit -m spaces &&
+	test_completion_long "git show HEAD:nam" <<-\EOF
+	name with spaces_
+	EOF
+'
+
+test_expect_failure 'complete tree filename with metacharacters' '
+	echo content >"name with \${meta}" &&
+	git add . &&
+	git commit -m meta &&
+	test_completion_long "git show HEAD:nam" <<-\EOF
+	name with ${meta}_
+	name with spaces_
+	EOF
+'
+
 test_done
-- 
1.7.12.10.g31da6dd
Previous: Jeff KingNext: Jeff King
Message 13 of 37 in “completion: fix shell expansion of items”
  1. completion: fix shell expansion of itemsFelipe Contreras, Sep 20, 2012
  2. Jeff KingSep 20, 2012
  3. Junio C HamanoSep 20, 2012
  4. SZEDER GáborSep 20, 2012
  5. Jeff KingSep 20, 2012
  6. Felipe ContrerasSep 20, 2012
  7. Revert "completion: fix shell expansion of items"Jeff King, Sep 25, 2012
  8. Junio C HamanoSep 25, 2012
  9. SZEDER GáborSep 25, 2012
  10. Junio C HamanoSep 25, 2012
  11. Jeff KingSep 26, 2012
  12. 1/3 t9902: add a few basic completion testsJeff King, Sep 26, 2012
  13. 2/3 t9902: add completion tests for "odd" filenamesJeff King, Sep 26, 2012
  14. 3/3 completion: improve shell expansion of itemsJeff King, Sep 26, 2012
  15. 4/3 completion: quote completions we findJeff King, Sep 26, 2012
  16. SZEDER GáborSep 27, 2012
  17. Junio C HamanoSep 27, 2012
  18. SZEDER GáborSep 27, 2012
  19. SZEDER GáborSep 27, 2012
  20. Jeff KingSep 27, 2012
  21. Jeff KingSep 27, 2012
  22. Jeff KingSep 27, 2012
  23. SZEDER GáborSep 28, 2012
  24. 1/5 completion: fix non-critical bugs in __gitcomp() testsSZEDER Gábor, Sep 28, 2012
  25. 2/5 completion: fix args of run_completion() test helperSZEDER Gábor, Sep 28, 2012
  26. Junio C HamanoSep 28, 2012
  27. SZEDER GáborSep 28, 2012
  28. Junio C HamanoSep 28, 2012
  29. Jeff KingSep 28, 2012
  30. Junio C HamanoSep 28, 2012
  31. Jeff KingSep 28, 2012
  32. SZEDER GáborSep 28, 2012
  33. 3/5 completion: add tests for the __gitcomp_nl() completion helper functionSZEDER Gábor, Sep 28, 2012
  34. 4/5 completion: test __gitcomp() and __gitcomp_nl() with expandable wordsSZEDER Gábor, Sep 28, 2012
  35. 5/5 completion: avoid compgen to fix expansion issues in __gitcomp_nl()SZEDER Gábor, Sep 28, 2012
  36. SZEDER GáborSep 28, 2012
  37. Jeff KingSep 28, 2012

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.