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

[PATCH 4/6] t9107: switch inverted single/double quotes in test

From
Jeff King <peff@peff.net>
Date
May 13, 2016, 20:47 UTC
Message-ID
<20160513204724.GD15391@sigill.intra.peff.net>
In-Reply-To
<20160513204654.GA10684@sigill.intra.peff.net>

One of the test snippets in t9107 is enclosed in double quotes, but then uses single quotes to surround an interpolated variable inside the snippet, like:

  test_expect_success '...' "
	test -n '$head'
  "

This happens to work because the variable is interpolated _before_ the snippet is run, and the result is eval'd. So as long as the variable does not contain any single quotes, the two are equivalent. And it doesn't, as we know it is a sha1 from rev-parse above. But this construct is unnecessarily confusing.

But we can go a step further in cleaning up. The test is really checking that a particular ref has a value. Rather than checking if rev-parse produced output, we can just move rev-parse into the test itself, and rely on the exit code from --verify. Nobody else cares about the $head variable at all.

Signed-off-by: Jeff King <peff@peff.net>
---
 t/t9107-git-svn-migrate.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/t/t9107-git-svn-migrate.sh b/t/t9107-git-svn-migrate.sh
index 2908aef..bb03722 100755
--- a/t/t9107-git-svn-migrate.sh
+++ b/t/t9107-git-svn-migrate.sh
@@ -24,8 +24,9 @@ test_expect_success 'setup old-looking metadata' '
 	git update-ref -d refs/remotes/git-svn refs/remotes/git-svn
 	'
 
-head=$(git rev-parse --verify refs/heads/git-svn-HEAD^0)
-test_expect_success 'git-svn-HEAD is a real HEAD' "test -n '$head'"
+test_expect_success 'git-svn-HEAD is a real HEAD' '
+	git rev-parse --verify refs/heads/git-svn-HEAD^0
+'
 
 svnrepo_escaped=$(echo $svnrepo | sed 's/ /%20/')
 
-- 
2.8.2.825.gea31738
Previous: Jeff KingNext: Jeff King
Message 16 of 19 in “t3404 static check of bad SHA-1 failure”
  1. Armin KunaschikMay 13, 2016
  2. Jeff KingMay 13, 2016
  3. Junio C HamanoMay 13, 2016
  4. Jeff KingMay 13, 2016
  5. Jeff KingMay 13, 2016
  6. Junio C HamanoMay 13, 2016
  7. 0/6 test -z/-n quoting fix + misc cleanupsJeff King, May 13, 2016
  8. 1/6 t/lib-git-svn: drop $remote_git_svn and $git_svn_idJeff King, May 13, 2016
  9. 2/6 t9100,t3419: enclose all test code in single-quotesJeff King, May 13, 2016
  10. 3/6 t9107: use "return 1" instead of "exit 1"Jeff King, May 13, 2016
  11. Eric WongMay 13, 2016
  12. Eric SunshineMay 13, 2016
  13. Jeff KingMay 13, 2016
  14. Junio C HamanoMay 14, 2016
  15. Jeff KingMay 14, 2016
  16. 4/6 t9107: switch inverted single/double quotes in testJeff King, May 13, 2016
  17. 5/6 t9103: modernize test styleJeff King, May 13, 2016
  18. 6/6 always quote shell arguments to test -z/-nJeff King, May 13, 2016
  19. Junio C HamanoMay 13, 2016

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.