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

[PATCH 02/20] t9300: make the series B tests self-contained

From
Karthik Nayak <karthik.188@gmail.com>
Date
Nov 10, 2026, 11:49 UTC
Message-ID
<20261110-kn-fast-import-tests-1-v1-2-dbd9ee502aae@gmail.com>
In-Reply-To
<20261110-kn-fast-import-tests-1-v1-0-dbd9ee502aae@gmail.com>

The 't/t9300-fast-import.sh' test file contains numerous tests and is currently just shy of 4000 lines. This is because the file contains tests over multiple series, each series testing particular functionality or sections of 'git-fast-import(1)'. In upcoming commits, we want to split out these tests into individual files for better discoverability.

First, we need to remove the dependency tests have on preceding tests. Modify the tests in 'series B' to each run in a new repository, which is removed when the test completes, so that they neither depend on nor leave behind any state.

The 'B: fail on invalid blob sha1' and 'B: accept branch name "TEMP_TAG"' tests import on top of 'main', which used to exist from earlier tests. Create it with 'test_commit', so that the first import can only fail because of the invalid blob ID.

The 'fsck' tests require the whole repository to be free of unreachable objects. They only passed because of the garbage collection in the cleanup of other tests. A new repository makes that unnecessary.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 t/t9300-fast-import.sh | 472 ++++++++++++++++++++++++++++---------------------
 1 file changed, 275 insertions(+), 197 deletions(-)
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index fb23492202..1b34f6491c 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -358,274 +358,352 @@ test_expect_success 'A: export marks with large values' '
 ###
 
 test_expect_success 'B: fail on invalid blob sha1' '
-	test_tick &&
-	cat >input <<-INPUT_END &&
-	commit refs/heads/branch
-	mark :1
-	committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	corrupt
-	COMMIT
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		test_commit base &&
 
-	from refs/heads/main
-	M 755 $(echo $ZERO_OID | sed -e "s/0$/1/") zero1
+		test_tick &&
+		cat >input <<-INPUT_END &&
+		commit refs/heads/branch
+		mark :1
+		committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		corrupt
+		COMMIT
 
-	INPUT_END
+		from refs/heads/main
+		M 755 $(echo $ZERO_OID | sed -e "s/0$/1/") zero1
 
-	test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
-	test_must_fail git fast-import <input
+		INPUT_END
+
+		test_must_fail git fast-import <input
+	)
 '
 
 test_expect_success 'B: accept branch name "TEMP_TAG"' '
-	cat >input <<-INPUT_END &&
-	commit TEMP_TAG
-	committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	tag base
-	COMMIT
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		test_commit new &&
 
-	from refs/heads/main
+		cat >input <<-INPUT_END &&
+		commit TEMP_TAG
+		committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		tag base
+		COMMIT
 
-	INPUT_END
+		from refs/heads/main
 
-	test_when_finished "rm -f .git/TEMP_TAG && git gc --prune=now" &&
-	git fast-import <input &&
-	test $(test-tool ref-store main resolve-ref TEMP_TAG 0 | cut -f1 -d " " ) != "$ZERO_OID" &&
-	test $(git rev-parse main) = $(git rev-parse TEMP_TAG^)
+		INPUT_END
+
+		git fast-import <input &&
+		test $(test-tool ref-store main resolve-ref TEMP_TAG 0 | cut -f1 -d " " ) != "$ZERO_OID" &&
+		test $(git rev-parse main) = $(git rev-parse TEMP_TAG^)
+	)
 '
 
 test_expect_success 'B: accept empty committer' '
-	cat >input <<-INPUT_END &&
-	commit refs/heads/empty-committer-1
-	committer  <> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	empty commit
-	COMMIT
-	INPUT_END
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		cat >input <<-INPUT_END &&
+		commit refs/heads/empty-committer-1
+		committer  <> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		empty commit
+		COMMIT
+		INPUT_END
 
-	test_when_finished "git update-ref -d refs/heads/empty-committer-1
-		git gc --prune=now" &&
-	git fast-import <input &&
-	out=$(git fsck) &&
-	echo "$out" &&
-	test -z "$out"
+		git fast-import <input &&
+		out=$(git fsck) &&
+		echo "$out" &&
+		test -z "$out"
+	)
 '
 
 test_expect_success 'B: reject invalid timezone' '
-	cat >input <<-INPUT_END &&
-	commit refs/heads/invalid-timezone
-	committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800
-	data <<COMMIT
-	empty commit
-	COMMIT
-	INPUT_END
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-	test_when_finished "git update-ref -d refs/heads/invalid-timezone" &&
-	test_must_fail git fast-import <input
+		cat >input <<-INPUT_END &&
+		commit refs/heads/invalid-timezone
+		committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800
+		data <<COMMIT
+		empty commit
+		COMMIT
+		INPUT_END
+
+		test_must_fail git fast-import <input
+	)
 '
 
 test_expect_success 'B: accept invalid timezone with raw-permissive' '
-	cat >input <<-INPUT_END &&
-	commit refs/heads/invalid-timezone
-	committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800
-	data <<COMMIT
-	empty commit
-	COMMIT
-	INPUT_END
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-	git init invalid-timezone &&
-	git -C invalid-timezone fast-import --date-format=raw-permissive <input &&
-	git -C invalid-timezone cat-file -p invalid-timezone >out &&
-	test_grep "1234567890 [+]051800" out
+		cat >input <<-INPUT_END &&
+		commit refs/heads/invalid-timezone
+		committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800
+		data <<COMMIT
+		empty commit
+		COMMIT
+		INPUT_END
+
+		git fast-import --date-format=raw-permissive <input &&
+		git cat-file -p invalid-timezone >out &&
+		test_grep "1234567890 [+]051800" out
+	)
 '
 
 test_expect_success 'B: accept and fixup committer with no name' '
-	cat >input <<-INPUT_END &&
-	commit refs/heads/empty-committer-2
-	committer <a@b.com> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	empty commit
-	COMMIT
-	INPUT_END
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		cat >input <<-INPUT_END &&
+		commit refs/heads/empty-committer-2
+		committer <a@b.com> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		empty commit
+		COMMIT
+		INPUT_END
 
-	test_when_finished "git update-ref -d refs/heads/empty-committer-2
-		git gc --prune=now" &&
-	git fast-import <input &&
-	out=$(git fsck) &&
-	echo "$out" &&
-	test -z "$out"
+		git fast-import <input &&
+		out=$(git fsck) &&
+		echo "$out" &&
+		test -z "$out"
+	)
 '
 
 test_expect_success 'B: fail on invalid committer (1)' '
-	cat >input <<-INPUT_END &&
-	commit refs/heads/invalid-committer
-	committer Name email> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	empty commit
-	COMMIT
-	INPUT_END
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-	test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
-	test_must_fail git fast-import <input
+		cat >input <<-INPUT_END &&
+		commit refs/heads/invalid-committer
+		committer Name email> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		empty commit
+		COMMIT
+		INPUT_END
+
+		test_must_fail git fast-import <input
+	)
 '
 
 test_expect_success 'B: fail on invalid committer (2)' '
-	cat >input <<-INPUT_END &&
-	commit refs/heads/invalid-committer
-	committer Name <e<mail> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	empty commit
-	COMMIT
-	INPUT_END
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-	test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
-	test_must_fail git fast-import <input
+		cat >input <<-INPUT_END &&
+		commit refs/heads/invalid-committer
+		committer Name <e<mail> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		empty commit
+		COMMIT
+		INPUT_END
+
+		test_must_fail git fast-import <input
+	)
 '
 
 test_expect_success 'B: fail on invalid committer (3)' '
-	cat >input <<-INPUT_END &&
-	commit refs/heads/invalid-committer
-	committer Name <email>> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	empty commit
-	COMMIT
-	INPUT_END
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-	test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
-	test_must_fail git fast-import <input
+		cat >input <<-INPUT_END &&
+		commit refs/heads/invalid-committer
+		committer Name <email>> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		empty commit
+		COMMIT
+		INPUT_END
+
+		test_must_fail git fast-import <input
+	)
 '
 
 test_expect_success 'B: fail on invalid committer (4)' '
-	cat >input <<-INPUT_END &&
-	commit refs/heads/invalid-committer
-	committer Name <email $GIT_COMMITTER_DATE
-	data <<COMMIT
-	empty commit
-	COMMIT
-	INPUT_END
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-	test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
-	test_must_fail git fast-import <input
+		cat >input <<-INPUT_END &&
+		commit refs/heads/invalid-committer
+		committer Name <email $GIT_COMMITTER_DATE
+		data <<COMMIT
+		empty commit
+		COMMIT
+		INPUT_END
+
+		test_must_fail git fast-import <input
+	)
 '
 
 test_expect_success 'B: fail on invalid committer (5)' '
-	cat >input <<-INPUT_END &&
-	commit refs/heads/invalid-committer
-	committer Name<email> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	empty commit
-	COMMIT
-	INPUT_END
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-	test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
-	test_must_fail git fast-import <input
+		cat >input <<-INPUT_END &&
+		commit refs/heads/invalid-committer
+		committer Name<email> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		empty commit
+		COMMIT
+		INPUT_END
+
+		test_must_fail git fast-import <input
+	)
 '
 
 test_expect_success 'B: fail on invalid file path of ..' '
-	cat >input <<-INPUT_END &&
-	blob
-	mark :1
-	data <<EOF
-	File contents
-	EOF
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-	commit refs/heads/badpath
-	committer Name <email> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	Commit Message
-	COMMIT
-	M 100644 :1 ../invalid-path
-	INPUT_END
+		cat >input <<-INPUT_END &&
+		blob
+		mark :1
+		data <<EOF
+		File contents
+		EOF
 
-	test_when_finished "git update-ref -d refs/heads/badpath" &&
-	test_must_fail git fast-import <input
+		commit refs/heads/badpath
+		committer Name <email> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		Commit Message
+		COMMIT
+		M 100644 :1 ../invalid-path
+		INPUT_END
+
+		test_must_fail git fast-import <input
+	)
 '
 
 test_expect_success 'B: fail on invalid file path of .' '
-	cat >input <<-INPUT_END &&
-	blob
-	mark :1
-	data <<EOF
-	File contents
-	EOF
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-	commit refs/heads/badpath
-	committer Name <email> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	Good path
-	COMMIT
-	M 100644 :1 ok-path
+		cat >input <<-INPUT_END &&
+		blob
+		mark :1
+		data <<EOF
+		File contents
+		EOF
 
-	commit refs/heads/badpath
-	committer Name <email> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	Bad path
-	COMMIT
-	R ok-path ./invalid-path
-	INPUT_END
+		commit refs/heads/badpath
+		committer Name <email> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		Good path
+		COMMIT
+		M 100644 :1 ok-path
 
-	test_when_finished "git update-ref -d refs/heads/badpath" &&
-	test_must_fail git fast-import <input
+		commit refs/heads/badpath
+		committer Name <email> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		Bad path
+		COMMIT
+		R ok-path ./invalid-path
+		INPUT_END
+
+		test_must_fail git fast-import <input
+	)
 '
 
 test_expect_success WINDOWS 'B: fail on invalid file path of C:' '
-	cat >input <<-INPUT_END &&
-	blob
-	mark :1
-	data <<EOF
-	File contents
-	EOF
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-	commit refs/heads/badpath
-	committer Name <email> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	Commit Message
-	COMMIT
-	M 100644 :1 C:/invalid-path
-	INPUT_END
+		cat >input <<-INPUT_END &&
+		blob
+		mark :1
+		data <<EOF
+		File contents
+		EOF
 
-	test_when_finished "git update-ref -d refs/heads/badpath" &&
-	test_must_fail git fast-import <input
+		commit refs/heads/badpath
+		committer Name <email> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		Commit Message
+		COMMIT
+		M 100644 :1 C:/invalid-path
+		INPUT_END
+
+		test_must_fail git fast-import <input
+	)
 '
 
 test_expect_success 'B: fail on invalid file path of .git' '
-	cat >input <<-INPUT_END &&
-	blob
-	mark :1
-	data <<EOF
-	File contents
-	EOF
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-	commit refs/heads/badpath
-	committer Name <email> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	Commit Message
-	COMMIT
-	M 100644 :1 .git/invalid-path
-	INPUT_END
+		cat >input <<-INPUT_END &&
+		blob
+		mark :1
+		data <<EOF
+		File contents
+		EOF
 
-	test_when_finished "git update-ref -d refs/heads/badpath" &&
-	test_must_fail git fast-import <input
+		commit refs/heads/badpath
+		committer Name <email> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		Commit Message
+		COMMIT
+		M 100644 :1 .git/invalid-path
+		INPUT_END
+
+		test_must_fail git fast-import <input
+	)
 '
 
 test_expect_success 'B: fail on invalid file path of .gitmodules' '
-	cat >input <<-INPUT_END &&
-	blob
-	mark :1
-	data <<EOF
-	File contents
-	EOF
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-	commit refs/heads/badpath
-	committer Name <email> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	Commit Message
-	COMMIT
-	M 120000 :1 .gitmodules
-	INPUT_END
+		cat >input <<-INPUT_END &&
+		blob
+		mark :1
+		data <<EOF
+		File contents
+		EOF
 
-	test_when_finished "git update-ref -d refs/heads/badpath" &&
-	test_must_fail git fast-import <input
+		commit refs/heads/badpath
+		committer Name <email> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		Commit Message
+		COMMIT
+		M 120000 :1 .gitmodules
+		INPUT_END
+
+		test_must_fail git fast-import <input
+	)
 '
 
 ###
-- 
2.56.GIT
Previous: Karthik NayakNext: Karthik Nayak
Message 3 of 45 in “t9300: group and move tests to other files”
  1. 00/20 t9300: group and move tests to other filesKarthik Nayak, Nov 10, 2026
  2. 01/20 t9300: move 'fastimport.unpackLimit' to the required testKarthik Nayak, Nov 10, 2026
  3. 02/20 t9300: make the series B tests self-containedKarthik Nayak, Nov 10, 2026
  4. 03/20 t9300: make the series T tests self-containedKarthik Nayak, Nov 10, 2026
  5. 04/20 t9300: make the series S tests self-containedKarthik Nayak, Nov 10, 2026
  6. 05/20 t9300: make the series V tests self-containedKarthik Nayak, Nov 10, 2026
  7. 06/20 t9300: make the series Q tests self-containedKarthik Nayak, Nov 10, 2026
  8. 07/20 t9300: make the series P tests self-containedKarthik Nayak, Nov 10, 2026
  9. 08/20 t9300: make the series O tests self-containedKarthik Nayak, Nov 10, 2026
  10. 09/20 t9300: make the big blob tests self-containedKarthik Nayak, Nov 10, 2026
  11. 10/20 t9300: make the ref update tests self-containedKarthik Nayak, Nov 10, 2026
  12. 11/20 t9300: make the date format tests self-containedKarthik Nayak, Nov 10, 2026
  13. 12/20 t9300: make the pack edges test self-containedKarthik Nayak, Nov 10, 2026
  14. 13/20 t9300: make the marks tests self-containedKarthik Nayak, Nov 10, 2026
  15. 14/20 t9300: make the series Y tests self-containedKarthik Nayak, Nov 10, 2026
  16. 15/20 t9300: make the cat-blob tests self-containedKarthik Nayak, Nov 10, 2026
  17. 16/20 t9300: make the feature and option tests self-containedKarthik Nayak, Nov 10, 2026
  18. 17/20 t9300: make the stream tests self-containedKarthik Nayak, Nov 10, 2026
  19. 18/20 t9300: make the get-mark and encoding tests self-containedKarthik Nayak, Nov 10, 2026
  20. 19/20 t9300: move self-contained tests into dedicated filesKarthik Nayak, Nov 10, 2026
  21. 20/20 t93xx: drop the series letter from the moved test namesKarthik Nayak, Nov 10, 2026
  22. Junio C HamanoNov 10, 2026
  23. Junio C HamanoNov 10, 2026
  24. Karthik NayakNov 11, 2026
  25. 00/20 t9300: group and move tests to other filesKarthik Nayak, Nov 12, 2026
  26. 01/20 t9300: move 'fastimport.unpackLimit' to the required testKarthik Nayak, Nov 12, 2026
  27. 02/20 t9300: make the series B tests self-containedKarthik Nayak, Nov 12, 2026
  28. 03/20 t9300: make the series T tests self-containedKarthik Nayak, Nov 12, 2026
  29. 04/20 t9300: make the series S tests self-containedKarthik Nayak, Nov 12, 2026
  30. 05/20 t9300: make the series V tests self-containedKarthik Nayak, Nov 12, 2026
  31. 06/20 t9300: make the series Q tests self-containedKarthik Nayak, Nov 12, 2026
  32. 07/20 t9300: make the series P tests self-containedKarthik Nayak, Nov 12, 2026
  33. 08/20 t9300: make the series O tests self-containedKarthik Nayak, Nov 12, 2026
  34. 09/20 t9300: make the big blob tests self-containedKarthik Nayak, Nov 12, 2026
  35. 10/20 t9300: make the ref update tests self-containedKarthik Nayak, Nov 12, 2026
  36. 11/20 t9300: make the date format tests self-containedKarthik Nayak, Nov 12, 2026
  37. 12/20 t9300: make the pack edges test self-containedKarthik Nayak, Nov 12, 2026
  38. 13/20 t9300: make the marks tests self-containedKarthik Nayak, Nov 12, 2026
  39. 14/20 t9300: make the series Y tests self-containedKarthik Nayak, Nov 12, 2026
  40. 15/20 t9300: make the cat-blob tests self-containedKarthik Nayak, Nov 12, 2026
  41. 16/20 t9300: make the feature and option tests self-containedKarthik Nayak, Nov 12, 2026
  42. 17/20 t9300: make the stream tests self-containedKarthik Nayak, Nov 12, 2026
  43. 18/20 t9300: make the get-mark and encoding tests self-containedKarthik Nayak, Nov 12, 2026
  44. 19/20 t9300: move self-contained tests into dedicated filesKarthik Nayak, Nov 12, 2026
  45. 20/20 t93xx: drop the series letter from the moved test namesKarthik Nayak, Nov 12, 2026

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.