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

[PATCH 12/12] t0001: drop subshells just for "cd"

From
Jeff King <peff@peff.net>
Date
Mar 20, 2014, 23:23 UTC
Message-ID
<20140320232306.GL8479@sigill.intra.peff.net>
In-Reply-To
<20140320231159.GA7774@sigill.intra.peff.net>
Many tests do something like:
  (
	mkdir foo &&
	cd foo &&
	git init
  )

You can do the same these days with "git init foo", which makes the tests shorter and simpler to read.

Signed-off-by: Jeff King <peff@peff.net>
---
Unlike the last patch, this one _could_ have an affect. I made the
assumption that "git init foo" would behave sanely, but that other
complex things should be left alone. E.g., ones that set GIT_DIR in the
environment to a relative path might be affected based on when git does
the "chdir".
 t/t0001-init.sh | 56 +++++++++-----------------------------------------------
 1 file changed, 9 insertions(+), 47 deletions(-)
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 55a68bc..68549d1 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -24,11 +24,7 @@ check_config () {
 }
 
 test_expect_success 'plain' '
-	(
-		mkdir plain &&
-		cd plain &&
-		git init
-	) &&
+	git init plain &&
 	check_config plain/.git false unset
 '
 
@@ -90,11 +86,7 @@ test_expect_success 'plain with GIT_WORK_TREE' '
 '
 
 test_expect_success 'plain bare' '
-	(
-		mkdir plain-bare-1 &&
-		cd plain-bare-1 &&
-		git --bare init
-	) &&
+	git --bare init plain-bare-1 &&
 	check_config plain-bare-1 true unset
 '
 
@@ -112,12 +104,7 @@ test_expect_success 'GIT_DIR bare' '
 '
 
 test_expect_success 'init --bare' '
-
-	(
-		mkdir init-bare.git &&
-		cd init-bare.git &&
-		git init --bare
-	) &&
+	git init --bare init-bare.git &&
 	check_config init-bare.git true unset
 '
 
@@ -166,26 +153,14 @@ test_expect_success 'reinit' '
 test_expect_success 'init with --template' '
 	mkdir template-source &&
 	echo content >template-source/file &&
-	(
-		mkdir template-custom &&
-		cd template-custom &&
-		git init --template=../template-source
-	) &&
+	git init --template=../template-source template-custom &&
 	test_cmp template-source/file template-custom/.git/file
 '
 
 test_expect_success 'init with --template (blank)' '
-	(
-		mkdir template-plain &&
-		cd template-plain &&
-		git init
-	) &&
+	git init template-plain &&
 	test_path_is_file template-plain/.git/info/exclude &&
-	(
-		mkdir template-blank &&
-		cd template-blank &&
-		git init --template=
-	) &&
+	git init --template= template-blank &&
 	test_path_is_missing template-blank/.git/info/exclude
 '
 
@@ -207,11 +182,7 @@ test_expect_success 'init with init.templatedir set' '
 test_expect_success 'init --bare/--shared overrides system/global config' '
 	test_config_global core.bare false &&
 	test_config_global core.sharedRepository 0640 &&
-	(
-		mkdir init-bare-shared-override &&
-		cd init-bare-shared-override &&
-		git init --bare --shared=0666
-	) &&
+	git init --bare --shared=0666 init-bare-shared-override &&
 	check_config init-bare-shared-override true unset &&
 	test x0666 = \
 	x`git config -f init-bare-shared-override/config core.sharedRepository`
@@ -219,22 +190,13 @@ test_expect_success 'init --bare/--shared overrides system/global config' '
 
 test_expect_success 'init honors global core.sharedRepository' '
 	test_config_global core.sharedRepository 0666 &&
-	(
-		mkdir shared-honor-global &&
-		cd shared-honor-global &&
-		git init
-	) &&
+	git init shared-honor-global &&
 	test x0666 = \
 	x`git config -f shared-honor-global/.git/config core.sharedRepository`
 '
 
 test_expect_success 'init rejects insanely long --template' '
-	(
-		insane=$(printf "x%09999dx" 1) &&
-		mkdir test &&
-		cd test &&
-		test_must_fail git init --template=$insane
-	)
+	test_must_fail git init --template=$(printf "x%09999dx" 1) test
 '
 
 test_expect_success 'init creates a new directory' '
-- 
1.9.0.560.g01ceb46
Previous: Eric SunshineNext: Eric Sunshine
Message 26 of 28 in “tests: set temp variables using 'env' in test function instead of subshell”
  1. tests: set temp variables using 'env' in test function instead of subshellDavid Tran, Mar 18, 2014
  2. Junio C HamanoMar 18, 2014
  3. Jeff KingMar 18, 2014
  4. Junio C HamanoMar 18, 2014
  5. Jeff KingMar 18, 2014
  6. Junio C HamanoMar 19, 2014
  7. 0/12 GIT_CONFIG in the test suiteJeff King, Mar 20, 2014
  8. 01/12 t/Makefile: stop setting GIT_CONFIGJeff King, Mar 20, 2014
  9. 02/12 t/test-lib: drop redundant unset of GIT_CONFIGJeff King, Mar 20, 2014
  10. 03/12 t: drop useless sane_unset GIT_* callsJeff King, Mar 20, 2014
  11. Junio C HamanoMar 21, 2014
  12. Jeff KingMar 24, 2014
  13. Junio C HamanoMar 24, 2014
  14. Junio C HamanoMar 25, 2014
  15. 04/12 t: stop using GIT_CONFIG to cross repo boundariesJeff King, Mar 20, 2014
  16. Junio C HamanoMar 21, 2014
  17. Jeff KingMar 24, 2014
  18. 05/12 t: prefer "git config --file" to GIT_CONFIG with test_must_failJeff King, Mar 20, 2014
  19. 06/12 t: prefer "git config --file" to GIT_CONFIGJeff King, Mar 20, 2014
  20. 07/12 t0001: make symlink reinit test more carefulJeff King, Mar 20, 2014
  21. 08/12 t0001: use test_path_is_*Jeff King, Mar 20, 2014
  22. 09/12 t0001: use test_config_globalJeff King, Mar 20, 2014
  23. 10/12 t0001: use test_must_failJeff King, Mar 20, 2014
  24. 11/12 t0001: drop useless subshellsJeff King, Mar 20, 2014
  25. Eric SunshineMar 21, 2014
  26. 12/12 t0001: drop subshells just for "cd"Jeff King, Mar 20, 2014
  27. Eric SunshineMar 18, 2014
  28. Eric SunshineMar 18, 2014

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.