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

[PATCH v2 10/20] t9300: make the ref update tests self-contained

From
Karthik Nayak <karthik.188@gmail.com>
Date
Nov 12, 2026, 17:34 UTC
Message-ID
<20261112-kn-fast-import-tests-1-v2-10-b8c3a0ab27e8@gmail.com>
In-Reply-To
<20261112-kn-fast-import-tests-1-v2-0-b8c3a0ab27e8@gmail.com>

Similar to the previous commits, modify the reference update tests in series 'F', 'G', 'J' and 'K' to make them independent of state from previous tests. Add a 'setup_two_commit_repo()' function which creates a repository with two commits on 'main', so each test can invoke it.

Fold the tests which only check the result of an import into the tests performing it, as they can't run on their own. As 'fastimport.unpackLimit' is no longer set by an earlier test, set it for the 'F' and 'G' imports so that a pack is written, and verify it with an inline loop in place of 'verify_packs()'.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 t/t9300-fast-import.sh | 214 +++++++++++++++++++++++++++----------------------
 1 file changed, 119 insertions(+), 95 deletions(-)
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 2231e1bdab..446cf0c51a 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -865,43 +865,53 @@ test_expect_success 'E: verify commit' '
 ### series F
 ###
 
+setup_two_commit_repo () {
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	test_commit -C repo one &&
+	test_commit -C repo two
+}
+
 test_expect_success 'F: non-fast-forward update skips' '
-	old_branch=$(git rev-parse --verify branch^0) &&
-	test_tick &&
-	cat >input <<-INPUT_END &&
-	commit refs/heads/branch
-	committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	losing things already?
-	COMMIT
+	setup_two_commit_repo &&
+	(
+		cd repo &&
+		old_branch=$(git rev-parse --verify main^0) &&
+		test_tick &&
+		cat >input <<-INPUT_END &&
+		commit refs/heads/main
+		committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		losing things already?
+		COMMIT
 
-	from refs/heads/branch~1
+		from refs/heads/main~1
 
-	reset refs/heads/other
-	from refs/heads/branch
+		reset refs/heads/other
+		from refs/heads/main
 
-	INPUT_END
+		INPUT_END
 
-	test_must_fail git fast-import <input &&
-	# branch must remain unaffected
-	test $old_branch = $(git rev-parse --verify branch^0)
-'
+		test_must_fail git -c fastimport.unpackLimit=0 fast-import <input &&
+		# branch must remain unaffected
+		test $old_branch = $(git rev-parse --verify main^0) &&
 
-test_expect_success 'F: verify pack' '
-	verify_packs
-'
+		for p in .git/objects/pack/*.pack
+		do
+			git verify-pack "$p" || return 1
+		done &&
 
-test_expect_success 'F: verify other commit' '
-	cat >expect <<-EOF &&
-	tree $(git rev-parse branch~1^{tree})
-	parent $(git rev-parse branch~1)
-	author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-	committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+		cat >expect <<-EOF &&
+		tree $(git rev-parse main~1^{tree})
+		parent $(git rev-parse main~1)
+		author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+		committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 
-	losing things already?
-	EOF
-	git cat-file commit other >actual &&
-	test_cmp expect actual
+		losing things already?
+		EOF
+		git cat-file commit other >actual &&
+		test_cmp expect actual
+	)
 '
 
 ###
@@ -909,28 +919,31 @@ test_expect_success 'F: verify other commit' '
 ###
 
 test_expect_success 'G: non-fast-forward update forced' '
-	old_branch=$(git rev-parse --verify branch^0) &&
-	test_tick &&
-	cat >input <<-INPUT_END &&
-	commit refs/heads/branch
-	committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	losing things already?
-	COMMIT
+	setup_two_commit_repo &&
+	(
+		cd repo &&
+		old_branch=$(git rev-parse --verify main^0) &&
+		test_tick &&
+		cat >input <<-INPUT_END &&
+		commit refs/heads/main
+		committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		losing things already?
+		COMMIT
 
-	from refs/heads/branch~1
+		from refs/heads/main~1
 
-	INPUT_END
-	git fast-import --force <input
-'
+		INPUT_END
+		git -c fastimport.unpackLimit=0 fast-import --force <input &&
+		# branch changed, but logged
+		test $old_branch != $(git rev-parse --verify main^0) &&
+		test $old_branch = $(git rev-parse --verify main@{1}) &&
 
-test_expect_success 'G: verify pack' '
-	verify_packs
-'
-
-test_expect_success 'G: branch changed, but logged' '
-	test $old_branch != $(git rev-parse --verify branch^0) &&
-	test $old_branch = $(git rev-parse --verify branch@{1})
+		for p in .git/objects/pack/*.pack
+		do
+			git verify-pack "$p" || return 1
+		done
+	)
 '
 
 ###
@@ -1042,42 +1055,50 @@ test_expect_success 'I: export-pack-edges via stdin' '
 ###
 
 test_expect_success 'J: reset existing branch creates empty commit' '
-	cat >input <<-INPUT_END &&
-	commit refs/heads/J
-	committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	create J
-	COMMIT
+	setup_two_commit_repo &&
+	(
+		cd repo &&
+		cat >input <<-INPUT_END &&
+		commit refs/heads/J
+		committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		create J
+		COMMIT
 
-	from refs/heads/branch
+		from refs/heads/main
 
-	reset refs/heads/J
+		reset refs/heads/J
 
-	commit refs/heads/J
-	committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	initialize J
-	COMMIT
+		commit refs/heads/J
+		committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		initialize J
+		COMMIT
 
-	INPUT_END
-	git fast-import <input
-'
-test_expect_success 'J: branch has 1 commit, empty tree' '
-	test 1 = $(git rev-list J | wc -l) &&
-	test 0 = $(git ls-tree J | wc -l)
+		INPUT_END
+		git fast-import <input &&
+		# branch has 1 commit, empty tree
+		test 1 = $(git rev-list J | wc -l) &&
+		test 0 = $(git ls-tree J | wc -l)
+	)
 '
 
 test_expect_success 'J: tag must fail on empty branch' '
-	cat >input <<-INPUT_END &&
-	reset refs/heads/J2
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		cat >input <<-INPUT_END &&
+		reset refs/heads/J2
 
-	tag wrong_tag
-	from refs/heads/J2
-	data <<EOF
-	Tag branch that was reset.
-	EOF
-	INPUT_END
-	test_must_fail git fast-import <input
+		tag wrong_tag
+		from refs/heads/J2
+		data <<EOF
+		Tag branch that was reset.
+		EOF
+		INPUT_END
+		test_must_fail git fast-import <input
+	)
 '
 
 ###
@@ -1085,29 +1106,32 @@ test_expect_success 'J: tag must fail on empty branch' '
 ###
 
 test_expect_success 'K: reinit branch with from' '
-	cat >input <<-INPUT_END &&
-	commit refs/heads/K
-	committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	create K
-	COMMIT
+	setup_two_commit_repo &&
+	(
+		cd repo &&
+		cat >input <<-INPUT_END &&
+		commit refs/heads/K
+		committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		create K
+		COMMIT
 
-	from refs/heads/branch
+		from refs/heads/main
 
-	commit refs/heads/K
-	committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-	data <<COMMIT
-	redo K
-	COMMIT
+		commit refs/heads/K
+		committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+		data <<COMMIT
+		redo K
+		COMMIT
 
-	from refs/heads/branch^1
+		from refs/heads/main^1
 
-	INPUT_END
-	git fast-import <input
-'
-test_expect_success 'K: verify K^1 = branch^1' '
-	test $(git rev-parse --verify branch^1) \
-		= $(git rev-parse --verify K^1)
+		INPUT_END
+		git fast-import <input &&
+		# K^1 = main^1
+		test $(git rev-parse --verify main^1) \
+			= $(git rev-parse --verify K^1)
+	)
 '
 
 ###
-- 
2.56.GIT
Previous: Karthik NayakNext: Karthik Nayak
Message 35 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.