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

[PATCH 2/8] submodule tests: add tests for top-level flag output

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Nov 2, 2022, 07:53 UTC
Message-ID
<patch-2.8-cda36b5b6e0-20221102T074148Z-avarab@gmail.com>
In-Reply-To
<cover-0.8-00000000000-20221102T074148Z-avarab@gmail.com>

Exhaustively test for how combining various "mixed-level" "git submodule" option works. "Mixed-level" here means options that are accepted by a mixture of the top-level "submodule" command, and e.g. the "status" sub-command.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t7400-submodule-basic.sh  |  10 +++
 t/t7422-submodule-output.sh | 169 ++++++++++++++++++++++++++++++++++++
 2 files changed, 179 insertions(+)
 create mode 100755 t/t7422-submodule-output.sh
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index a989aafaf57..eae6a46ef3d 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -579,6 +579,16 @@ test_expect_success 'status should be "modified" after submodule commit' '
 	grep "^+$rev2" list
 '
 
+test_expect_success '"submodule --cached" command forms should be identical' '
+	git submodule status --cached >expect &&
+
+	git submodule --cached >actual &&
+	test_cmp expect actual &&
+
+	git submodule --cached status >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'the --cached sha1 should be rev1' '
 	git submodule --cached status >list &&
 	grep "^+$rev1" list
diff --git a/t/t7422-submodule-output.sh b/t/t7422-submodule-output.sh
new file mode 100755
index 00000000000..3ac56c23f72
--- /dev/null
+++ b/t/t7422-submodule-output.sh
@@ -0,0 +1,169 @@
+#!/bin/sh
+
+test_description='submodule --cached, --quiet etc. output'
+
+. ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-t3100.sh
+
+setup_sub () {
+	local d="$1" &&
+	shift &&
+	git $@ clone . "$d" &&
+	git $@ submodule add ./"$d"
+}
+
+normalize_status () {
+	sed -e 's/-g[0-9a-f]*/-gHASH/'
+}
+
+test_expect_success 'setup' '
+	test_commit A &&
+	test_commit B &&
+	setup_sub S  &&
+	setup_sub S.D &&
+	setup_sub S.C &&
+	setup_sub S.C.D &&
+	setup_sub X &&
+	git add S* &&
+	test_commit C &&
+
+	# recursive in X/
+	git -C X pull &&
+	GIT_ALLOW_PROTOCOL=file git -C X submodule update --init &&
+
+	# dirty p
+	for d in S.D X/S.D
+	do
+		echo dirty >S.D/A.t || return 1
+	done &&
+
+	# commit (for --cached)
+	for d in S.C* X/S.C*
+	do
+		git -C "$d" reset --hard A || return 1
+	done &&
+
+	# dirty
+	for d in S*.D X/S*.D
+	do
+		echo dirty >"$d/C2.t" || return 1
+	done &&
+
+	for ref in A B C
+	do
+		# Not different with SHA-1 and SHA-256, just (ab)usign
+		# test_oid_cache as a variable bag to avoid using
+		# $(git rev-parse ...).
+		oid=$(git rev-parse $ref) &&
+		test_oid_cache <<-EOF || return 1
+		$ref sha1:$oid
+		$ref sha256:$oid
+		EOF
+	done
+'
+
+for opts in "" "status"
+do
+	test_expect_success "git submodule $opts" '
+		sed -e "s/^>//" >expect <<-EOF &&
+		> $(test_oid B) S (B)
+		>+$(test_oid A) S.C (A)
+		>+$(test_oid A) S.C.D (A)
+		> $(test_oid B) S.D (B)
+		>+$(test_oid C) X (C)
+		EOF
+		git submodule $opts >actual.raw &&
+		normalize_status <actual.raw >actual &&
+		test_cmp expect actual
+	'
+done
+
+for opts in \
+	"status --recursive"
+do
+	test_expect_success "git submodule $opts" '
+		sed -e "s/^>//" >expect <<-EOF &&
+		> $(test_oid B) S (B)
+		>+$(test_oid A) S.C (A)
+		>+$(test_oid A) S.C.D (A)
+		> $(test_oid B) S.D (B)
+		>+$(test_oid C) X (C)
+		> $(test_oid B) X/S (B)
+		>+$(test_oid A) X/S.C (A)
+		>+$(test_oid A) X/S.C.D (A)
+		> $(test_oid B) X/S.D (B)
+		> $(test_oid B) X/X (B)
+		EOF
+		git submodule $opts >actual.raw &&
+		normalize_status <actual.raw >actual &&
+		test_cmp expect actual
+	'
+done
+
+for opts in \
+	"--quiet" \
+	"--quiet status" \
+	"status --quiet"
+do
+	test_expect_success "git submodule $opts" '
+		git submodule $opts >out &&
+		test_must_be_empty out
+	'
+done
+
+for opts in \
+	"--cached" \
+	"--cached status" \
+	"status --cached"
+do
+	test_expect_success "git submodule $opts" '
+		sed -e "s/^>//" >expect <<-EOF &&
+		> $(test_oid B) S (B)
+		>+$(test_oid B) S.C (B)
+		>+$(test_oid B) S.C.D (B)
+		> $(test_oid B) S.D (B)
+		>+$(test_oid B) X (B)
+		EOF
+		git submodule $opts >actual.raw &&
+		normalize_status <actual.raw >actual &&
+		test_cmp expect actual
+	'
+done
+
+for opts in \
+	"--cached --quiet" \
+	"--cached --quiet status" \
+	"--cached status --quiet" \
+	"--quiet status --cached" \
+	"status --cached --quiet"
+do
+	test_expect_success "git submodule $opts" '
+		git submodule $opts >out &&
+		test_must_be_empty out
+	'
+done
+
+for opts in \
+	"status --cached --recursive" \
+	"--cached status --recursive"
+do
+	test_expect_success "git submodule $opts" '
+		sed -e "s/^>//" >expect <<-EOF &&
+		> $(test_oid B) S (B)
+		>+$(test_oid B) S.C (B)
+		>+$(test_oid B) S.C.D (B)
+		> $(test_oid B) S.D (B)
+		>+$(test_oid B) X (B)
+		> $(test_oid B) X/S (B)
+		>+$(test_oid B) X/S.C (B)
+		>+$(test_oid B) X/S.C.D (B)
+		> $(test_oid B) X/S.D (B)
+		> $(test_oid B) X/X (B)
+		EOF
+		git submodule $opts >actual.raw &&
+		normalize_status <actual.raw >actual &&
+		test_cmp expect actual
+	'
+done
+
+test_done
-- 
2.38.0.1280.g8136eb6fab2
Previous: Glen ChooNext: Glen Choo
Message 4 of 35 in “submodule: tests, cleanup to prepare for built-in”
  1. 0/8 submodule: tests, cleanup to prepare for built-inÆvar Arnfjörð Bjarmason, Nov 2, 2022
  2. 1/8 submodule--helper: move "config" to a test-toolÆvar Arnfjörð Bjarmason, Nov 2, 2022
  3. Glen ChooNov 3, 2022
  4. 2/8 submodule tests: add tests for top-level flag outputÆvar Arnfjörð Bjarmason, Nov 2, 2022
  5. Glen ChooNov 3, 2022
  6. 3/8 submodule tests: test for a "foreach" blind-spotÆvar Arnfjörð Bjarmason, Nov 2, 2022
  7. 4/8 submodule.c: refactor recursive block out of absorb functionÆvar Arnfjörð Bjarmason, Nov 2, 2022
  8. 5/8 submodule API & "absorbgitdirs": remove "----recursive" optionÆvar Arnfjörð Bjarmason, Nov 2, 2022
  9. Glen ChooNov 3, 2022
  10. Ævar Arnfjörð BjarmasonNov 4, 2022
  11. FW: [PATCH 5/8] submodule API & "absorbgitdirs": remove "----recursive" optionSimpson, Phyllis, Nov 4, 2022
  12. Glen ChooNov 4, 2022
  13. 6/8 submodule--helper: remove --prefix from "absorbgitdirs"Ævar Arnfjörð Bjarmason, Nov 2, 2022
  14. 7/8 submodule--helper: drop "update --prefix <pfx>" for "-C <pfx> update"Ævar Arnfjörð Bjarmason, Nov 2, 2022
  15. 8/8 submodule--helper: use OPT_SUBCOMMAND() APIÆvar Arnfjörð Bjarmason, Nov 2, 2022
  16. Glen ChooNov 3, 2022
  17. Ævar Arnfjörð BjarmasonNov 4, 2022
  18. Glen ChooNov 4, 2022
  19. Ævar Arnfjörð BjarmasonNov 5, 2022
  20. Glen ChooNov 7, 2022
  21. Glen ChooNov 4, 2022
  22. Taylor BlauNov 4, 2022
  23. 0/9 submodule: tests, cleanup to prepare for built-inÆvar Arnfjörð Bjarmason, Nov 8, 2022
  24. 1/9 submodule--helper: move "config" to a test-toolÆvar Arnfjörð Bjarmason, Nov 8, 2022
  25. 2/9 submodule tests: add tests for top-level flag outputÆvar Arnfjörð Bjarmason, Nov 8, 2022
  26. 3/9 submodule--helper: fix a memory leak in "status"Ævar Arnfjörð Bjarmason, Nov 8, 2022
  27. 5/9 submodule.c: refactor recursive block out of absorb functionÆvar Arnfjörð Bjarmason, Nov 8, 2022
  28. 6/9 submodule API & "absorbgitdirs": remove "----recursive" optionÆvar Arnfjörð Bjarmason, Nov 8, 2022
  29. 7/9 submodule--helper: remove --prefix from "absorbgitdirs"Ævar Arnfjörð Bjarmason, Nov 8, 2022
  30. 4/9 submodule tests: test for a "foreach" blind-spotÆvar Arnfjörð Bjarmason, Nov 8, 2022
  31. 8/9 submodule--helper: drop "update --prefix <pfx>" for "-C <pfx> update"Ævar Arnfjörð Bjarmason, Nov 8, 2022
  32. 9/9 submodule--helper: use OPT_SUBCOMMAND() APIÆvar Arnfjörð Bjarmason, Nov 8, 2022
  33. Glen ChooNov 8, 2022
  34. Ævar Arnfjörð BjarmasonNov 8, 2022
  35. Glen ChooNov 8, 2022

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.