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

[PATCH 1/2] t7700: add tests for `--keep-unreachable`

From
Patrick Steinhardt <ps@pks.im>
Date
Feb 3, 2025, 13:06 UTC
Message-ID
<20250203-b4-pks-repack-unreachable-objects-wo-packfiles-v1-1-7c4d69c5072c@pks.im>
In-Reply-To
<20250203-b4-pks-repack-unreachable-objects-wo-packfiles-v1-0-7c4d69c5072c@pks.im>

We don't have any tests for `git repack --keep-unreachable`. Add three tests that exercise its behaviour with different packed states for the unreachable object.

Note that the last test is failing. This will be fixed in the next commit.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 t/t7700-repack.sh | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index be1188e736..b26566473f 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -826,4 +826,77 @@ test_expect_success '-n overrides repack.updateServerInfo=true' '
 	test_server_info_missing
 '
 
+expect_object_count () {
+	find .git/objects \( -type d \( -name pack -o -name info \) -prune \) -o -type f -print >objects &&
+	test_line_count = "$1" objects
+}
+
+expect_object_in_idx () {
+	git verify-pack -v "$1" >objects &&
+	test_grep "^$2" objects
+}
+
+test_expect_success '--keep-unreachable appends unreachable packed objects to new pack' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		git config set core.logAllRefUpdates false &&
+
+		# Set up the repo so that all objects, including the
+		# unreachable one, are packed.
+		test_commit --no-tag unreachable &&
+		git repack -ad &&
+		expect_object_count 0 &&
+		unreachable_oid=$(git rev-parse --verify HEAD) &&
+		git commit --amend --message rewritten &&
+
+		git repack -ad --keep-unreachable &&
+		expect_object_count 0 &&
+		expect_object_in_idx .git/objects/pack/*.idx "$unreachable_oid"
+	)
+'
+
+test_expect_success '--keep-unreachable packs unreachable loose object with existing packs' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		git config set core.logAllRefUpdates false &&
+
+		# Set up the repo so that we have an existing packfile with
+		# reachable objects, only. The unreachable object as well as
+		# the rewritten commit are both loose.
+		test_commit --no-tag initial &&
+		git repack -ad &&
+		git commit --amend --message unreachable &&
+		unreachable_oid=$(git rev-parse --verify HEAD) &&
+		git commit --amend --message rewritten &&
+		expect_object_count 2 &&
+
+		git repack -ad --keep-unreachable &&
+		expect_object_count 0 &&
+		expect_object_in_idx .git/objects/pack/*.idx "$unreachable_oid"
+	)
+'
+
+test_expect_failure '--keep-unreachable packs unreachable loose object without existing packs' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		git config set core.logAllRefUpdates false &&
+
+		# Set up the repo so that all objects are unpacked.
+		test_commit --no-tag unreachable &&
+		unreachable_oid=$(git rev-parse --verify HEAD) &&
+		git commit --amend --message rewritten &&
+		expect_object_count 4 &&
+
+		git repack -ad --keep-unreachable &&
+		expect_object_count 0 &&
+		expect_object_in_idx .git/objects/pack/*.idx "$unreachable_oid"
+	)
+'
+
 test_done
-- 
2.48.1.502.g6dc24dfdaf.dirty
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 15 in “builtin/repack: fix `--keep-unreachable` when there are no packs”
  1. 0/2 builtin/repack: fix `--keep-unreachable` when there are no packsPatrick Steinhardt, Feb 3, 2025
  2. 2/2 builtin/repack: fix `--keep-unreachable` when there are no packsPatrick Steinhardt, Feb 3, 2025
  3. Jeff KingFeb 4, 2025
  4. Patrick SteinhardtFeb 4, 2025
  5. Jeff KingFeb 4, 2025
  6. Junio C HamanoFeb 4, 2025
  7. 1/2 t7700: add tests for `--keep-unreachable`Patrick Steinhardt, Feb 3, 2025
  8. Junio C HamanoFeb 3, 2025
  9. Jeff KingFeb 3, 2025
  10. Junio C HamanoFeb 3, 2025
  11. Jeff KingFeb 4, 2025
  12. Patrick SteinhardtFeb 4, 2025
  13. builtin/repack: fix `--keep-unreachable` when there are no packsPatrick Steinhardt, Feb 4, 2025
  14. Jeff KingFeb 4, 2025
  15. Patrick SteinhardtFeb 5, 2025

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.