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

[PATCH 12/12] t0612: add tests to exercise Git/JGit reftable compatibility

From
Patrick Steinhardt <ps@pks.im>
Date
Apr 4, 2024, 13:25 UTC
Message-ID
<db66dd4155d80b714719e80ff90f64c1d36b97d0.1712235356.git.ps@pks.im>
In-Reply-To
<cover.1712235356.git.ps@pks.im>

While the reftable format is a recent introduction in Git, JGit already knows to read and write reftables since 2017. Given the complexity of the format there is a very real risk of incompatibilities between those two implementations, which is something that we really want to avoid.

Add some basic tests that verify that reftables written by Git and JGit can be read by the respective other implementation. For now this test suite is rather small, only covering basic functionality. But it serves as a good starting point and can be extended over time.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 t/t0612-reftable-jgit-compatibility.sh | 115 +++++++++++++++++++++++++
 1 file changed, 115 insertions(+)
 create mode 100755 t/t0612-reftable-jgit-compatibility.sh
diff --git a/t/t0612-reftable-jgit-compatibility.sh b/t/t0612-reftable-jgit-compatibility.sh
new file mode 100755
index 0000000000..f25ea880a0
--- /dev/null
+++ b/t/t0612-reftable-jgit-compatibility.sh
@@ -0,0 +1,115 @@
+#!/bin/sh
+
+test_description='reftables are compatible with JGit'
+
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+GIT_TEST_DEFAULT_REF_FORMAT=reftable
+export GIT_TEST_DEFAULT_REF_FORMAT
+
+# JGit does not support the 'link' DIRC extension.
+GIT_TEST_SPLIT_INDEX=0
+export GIT_TEST_SPLIT_INDEX
+
+. ./test-lib.sh
+
+if ! test_have_prereq JGIT
+then
+	skip_all='skipping reftable JGit tests'
+	test_done
+fi
+
+if ! test_have_prereq SHA1
+then
+	skip_all='skipping reftable JGit tests; JGit does not support SHA256 reftables'
+	test_done
+fi
+
+test_commit_jgit () {
+	touch "$1" &&
+	jgit add "$1" &&
+	jgit commit -m "$1"
+}
+
+test_same_refs () {
+	git show-ref --head >cgit.actual &&
+	jgit show-ref >jgit-tabs.actual &&
+	tr "\t" " " <jgit-tabs.actual >jgit.actual &&
+	test_cmp cgit.actual jgit.actual
+}
+
+test_same_reflog () {
+	git reflog "$*" >cgit.actual &&
+	jgit reflog "$*" >jgit-newline.actual &&
+	sed '/^$/d' <jgit-newline.actual >jgit.actual &&
+	test_cmp cgit.actual jgit.actual
+}
+
+test_expect_success 'CGit repository can be read by JGit' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		test_commit A &&
+		test_same_refs &&
+		test_same_reflog HEAD
+	)
+'
+
+test_expect_success 'JGit repository can be read by CGit' '
+	test_when_finished "rm -rf repo" &&
+	# JGit does not provide a way to create a reftable-enabled repository.
+	git init repo &&
+	(
+		cd repo &&
+		touch file &&
+		jgit add file &&
+		jgit commit -m "initial commit" &&
+
+		test_same_refs &&
+		# Interestingly, JGit cannot read its own reflog here. CGit can
+		# though.
+		printf "%s HEAD@{0}: commit (initial): initial commit" "$(git rev-parse --short HEAD)" >expect &&
+		git reflog HEAD >actual &&
+		test_cmp expect actual
+	)
+'
+
+test_expect_success 'mixed writes from JGit and CGit' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+
+		test_commit A &&
+		test_commit_jgit B &&
+		test_commit C &&
+		test_commit_jgit D &&
+
+		test_same_refs &&
+		test_same_reflog HEAD
+	)
+'
+
+test_expect_success 'JGit can read multi-level index' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+
+		test_commit A &&
+		awk "
+		    BEGIN {
+			print \"start\";
+			for (i = 0; i < 10000; i++)
+			    printf \"create refs/heads/branch-%d HEAD\n\", i;
+			print \"commit\";
+		    }
+		" >input &&
+		git update-ref --stdin <input &&
+
+		test_same_refs
+	)
+'
+
+test_done
-- 
2.44.GIT
Previous: Patrick SteinhardtNext: Han-Wen Nienhuys
Message 25 of 106 in “t: exercise Git/JGit reftable compatibility”
  1. 00/12 t: exercise Git/JGit reftable compatibilityPatrick Steinhardt, Apr 4, 2024
  2. 01/12 ci: rename "runs_on_pool" to "distro"Patrick Steinhardt, Apr 4, 2024
  3. 02/12 ci: expose distro name in dockerized GitHub jobsPatrick Steinhardt, Apr 4, 2024
  4. 03/12 ci: allow skipping sudo on dockerized jobsPatrick Steinhardt, Apr 4, 2024
  5. 04/12 ci: drop duplicate package installation for "linux-gcc-default"Patrick Steinhardt, Apr 4, 2024
  6. 05/12 ci: convert "install-dependencies.sh" to use "/bin/sh"Patrick Steinhardt, Apr 4, 2024
  7. 06/12 ci: merge custom PATH directoriesPatrick Steinhardt, Apr 4, 2024
  8. 07/12 ci: merge scripts which install dependenciesPatrick Steinhardt, Apr 4, 2024
  9. 08/12 ci: make Perforce binaries executable for all usersPatrick Steinhardt, Apr 4, 2024
  10. Josh SteadmonApr 5, 2024
  11. Patrick SteinhardtApr 8, 2024
  12. 09/12 ci: install JGit dependencyPatrick Steinhardt, Apr 4, 2024
  13. 10/12 t06xx: always execute backend-specific testsPatrick Steinhardt, Apr 4, 2024
  14. 11/12 t0610: fix non-portable variable assignmentPatrick Steinhardt, Apr 4, 2024
  15. Eric SunshineApr 5, 2024
  16. Patrick SteinhardtApr 5, 2024
  17. Junio C HamanoApr 5, 2024
  18. CodingGuidelines: quote assigned value with "local" and "export"Junio C Hamano, Apr 5, 2024
  19. Junio C HamanoApr 5, 2024
  20. Jeff KingApr 5, 2024
  21. Junio C HamanoApr 5, 2024
  22. Junio C HamanoApr 5, 2024
  23. Jeff KingApr 7, 2024
  24. Patrick SteinhardtApr 5, 2024
  25. 12/12 t0612: add tests to exercise Git/JGit reftable compatibilityPatrick Steinhardt, Apr 4, 2024
  26. Han-Wen NienhuysApr 4, 2024
  27. Patrick SteinhardtApr 5, 2024
  28. Han-Wen NienhuysApr 6, 2024
  29. Patrick SteinhardtApr 6, 2024
  30. Patrick SteinhardtApr 8, 2024
  31. Patrick SteinhardtApr 4, 2024
  32. 00/12 t: exercise Git/JGit reftable compatibilityPatrick Steinhardt, Apr 8, 2024
  33. 02/12 ci: expose distro name in dockerized GitHub jobsPatrick Steinhardt, Apr 8, 2024
  34. 03/12 ci: allow skipping sudo on dockerized jobsPatrick Steinhardt, Apr 8, 2024
  35. Toon claesApr 10, 2024
  36. Junio C HamanoApr 10, 2024
  37. Patrick SteinhardtApr 11, 2024
  38. 04/12 ci: drop duplicate package installation for "linux-gcc-default"Patrick Steinhardt, Apr 8, 2024
  39. 05/12 ci: convert "install-dependencies.sh" to use "/bin/sh"Patrick Steinhardt, Apr 8, 2024
  40. Justin ToblerApr 10, 2024
  41. Patrick SteinhardtApr 11, 2024
  42. 06/12 ci: merge custom PATH directoriesPatrick Steinhardt, Apr 8, 2024
  43. 07/12 ci: merge scripts which install dependenciesPatrick Steinhardt, Apr 8, 2024
  44. 08/12 ci: make Perforce binaries executable for all usersPatrick Steinhardt, Apr 8, 2024
  45. 09/12 ci: install JGit dependencyPatrick Steinhardt, Apr 8, 2024
  46. 10/12 t06xx: always execute backend-specific testsPatrick Steinhardt, Apr 8, 2024
  47. 11/12 t0610: fix non-portable variable assignmentPatrick Steinhardt, Apr 8, 2024
  48. Eric SunshineApr 8, 2024
  49. Patrick SteinhardtApr 8, 2024
  50. 12/12 t0612: add tests to exercise Git/JGit reftable compatibilityPatrick Steinhardt, Apr 8, 2024
  51. Eric SunshineApr 8, 2024
  52. Junio C HamanoApr 8, 2024
  53. Eric SunshineApr 8, 2024
  54. Eric SunshineApr 8, 2024
  55. Patrick SteinhardtApr 8, 2024
  56. Jeff KingApr 8, 2024
  57. Junio C HamanoApr 8, 2024
  58. Junio C HamanoApr 8, 2024
  59. Justin ToblerApr 10, 2024
  60. Patrick SteinhardtApr 11, 2024
  61. 01/12 ci: rename "runs_on_pool" to "distro"Patrick Steinhardt, Apr 8, 2024
  62. Junio C HamanoApr 9, 2024
  63. Patrick SteinhardtApr 9, 2024
  64. Junio C HamanoApr 9, 2024
  65. Patrick SteinhardtApr 9, 2024
  66. 0/2 t0610: fix umask testsPatrick Steinhardt, Apr 9, 2024
  67. 1/2 t0610: make `--shared=` tests reusablePatrick Steinhardt, Apr 9, 2024
  68. 2/2 t0610: execute git-pack-refs(1) with specified umaskPatrick Steinhardt, Apr 9, 2024
  69. Justin ToblerApr 10, 2024
  70. 00/13 t: exercise Git/JGit reftable compatibilityPatrick Steinhardt, Apr 11, 2024
  71. 01/13 ci: rename "runs_on_pool" to "distro"Patrick Steinhardt, Apr 11, 2024
  72. 02/13 ci: expose distro name in dockerized GitHub jobsPatrick Steinhardt, Apr 11, 2024
  73. 03/13 ci: skip sudo when we are already rootPatrick Steinhardt, Apr 11, 2024
  74. 04/13 ci: drop duplicate package installation for "linux-gcc-default"Patrick Steinhardt, Apr 11, 2024
  75. 05/13 ci: convert "install-dependencies.sh" to use "/bin/sh"Patrick Steinhardt, Apr 11, 2024
  76. 06/13 ci: merge custom PATH directoriesPatrick Steinhardt, Apr 11, 2024
  77. 07/13 ci: fix setup of custom path for GitLab CIPatrick Steinhardt, Apr 11, 2024
  78. Eric SunshineApr 11, 2024
  79. Patrick SteinhardtApr 11, 2024
  80. 08/13 ci: merge scripts which install dependenciesPatrick Steinhardt, Apr 11, 2024
  81. 09/13 ci: make Perforce binaries executable for all usersPatrick Steinhardt, Apr 11, 2024
  82. 10/13 ci: install JGit dependencyPatrick Steinhardt, Apr 11, 2024
  83. 11/13 t06xx: always execute backend-specific testsPatrick Steinhardt, Apr 11, 2024
  84. 12/13 t0610: fix non-portable variable assignmentPatrick Steinhardt, Apr 11, 2024
  85. 13/13 t0612: add tests to exercise Git/JGit reftable compatibilityPatrick Steinhardt, Apr 11, 2024
  86. 00/13 t: exercise Git/JGit reftable compatibilityPatrick Steinhardt, Apr 12, 2024
  87. 01/13 ci: rename "runs_on_pool" to "distro"Patrick Steinhardt, Apr 12, 2024
  88. 02/13 ci: expose distro name in dockerized GitHub jobsPatrick Steinhardt, Apr 12, 2024
  89. 03/13 ci: skip sudo when we are already rootPatrick Steinhardt, Apr 12, 2024
  90. 04/13 ci: drop duplicate package installation for "linux-gcc-default"Patrick Steinhardt, Apr 12, 2024
  91. 05/13 ci: convert "install-dependencies.sh" to use "/bin/sh"Patrick Steinhardt, Apr 12, 2024
  92. 06/13 ci: merge custom PATH directoriesPatrick Steinhardt, Apr 12, 2024
  93. 07/13 ci: fix setup of custom path for GitLab CIPatrick Steinhardt, Apr 12, 2024
  94. 08/13 ci: merge scripts which install dependenciesPatrick Steinhardt, Apr 12, 2024
  95. 09/13 ci: make Perforce binaries executable for all usersPatrick Steinhardt, Apr 12, 2024
  96. 10/13 ci: install JGit dependencyPatrick Steinhardt, Apr 12, 2024
  97. 11/13 t06xx: always execute backend-specific testsPatrick Steinhardt, Apr 12, 2024
  98. 12/13 t0610: fix non-portable variable assignmentPatrick Steinhardt, Apr 12, 2024
  99. 13/13 t0612: add tests to exercise Git/JGit reftable compatibilityPatrick Steinhardt, Apr 12, 2024
  100. Justin ToblerMay 3, 2024
  101. Patrick SteinhardtMay 3, 2024
  102. Patrick SteinhardtMay 3, 2024
  103. Justin ToblerMay 3, 2024
  104. Patrick SteinhardtMay 3, 2024
  105. Justin ToblerMay 4, 2024
  106. Patrick SteinhardtMay 6, 2024

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.