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

[PATCH 1/2] worktree: demonstrate data lost to auto-gc

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 8, 2017, 12:17 UTC
Message-ID
<674c16ee94c7609d82d14cac498ba62e5df65ab1.1486556262.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1486556262.git.johannes.schindelin@gmx.de>

When gc --auto is called in the presence of worktrees, it fails to take *all* reflogs into account when trying to retain reachable objects, and as a consequence data integrity goes pretty much to hell.

This patch provides a test case in the hopes that this bug gets fixed, after an initial attempt has stalled for eight months already.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 t/t6500-gc.sh | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh
index 1762dfa6a3..e24a4fb611 100755
--- a/t/t6500-gc.sh
+++ b/t/t6500-gc.sh
@@ -67,5 +67,44 @@ test_expect_success 'auto gc with too many loose objects does not attempt to cre
 	test_line_count = 2 new # There is one new pack and its .idx
 '
 
+trigger_auto_gc () {
+	# This is unfortunately very, very ugly
+	gdir="$(git rev-parse --git-common-dir)" &&
+	mkdir -p "$gdir"/objects/17 &&
+	touch "$gdir"/objects/17/17171717171717171717171717171717171717 &&
+	touch "$gdir"/objects/17/17171717171717171717171717171717171718 &&
+	git -c gc.auto=1 -c gc.pruneexpire=now -c gc.autodetach=0 gc --auto
+}
+
+test_expect_failure 'gc respects refs/reflogs in all worktrees' '
+	test_commit something &&
+	git worktree add worktree &&
+	(
+		cd worktree &&
+		git checkout --detach &&
+		# avoid implicit tagging of test_commit
+		echo 1 >something.t &&
+		test_tick &&
+		git commit -m worktree-reflog something.t &&
+		git rev-parse --verify HEAD >../commit-reflog &&
+		echo 2 >something.t &&
+		test_tick &&
+		git commit -m worktree-ref something.t &&
+		git rev-parse --verify HEAD >../commit-ref
+	) &&
+	trigger_auto_gc &&
+	git rev-parse --verify $(cat commit-ref)^{commit} &&
+	git rev-parse --verify $(cat commit-reflog)^{commit} &&
+
+	# Now, add a reflog in the top-level dir and verify that `git gc` in
+	# the worktree does not purge that
+	git checkout --detach &&
+	echo 3 >something.t &&
+	test_tick &&
+	git commit -m commondir-reflog something.t &&
+	git rev-parse --verify HEAD >commondir-reflog &&
+	(cd worktree && trigger_auto_gc) &&
+	git rev-parse --verify $(cat commondir-reflog)^{commit}
+'
 
 test_done
-- 
2.11.1.windows.1
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 2 of 4 in “Demonstrate a critical worktree/gc bug”
  1. 0/2 Demonstrate a critical worktree/gc bugJohannes Schindelin, Feb 8, 2017
  2. 1/2 worktree: demonstrate data lost to auto-gcJohannes Schindelin, Feb 8, 2017
  3. 2/2 worktree: demonstrate a half-working workaround for auto-gcJohannes Schindelin, Feb 8, 2017
  4. Duy NguyenFeb 8, 2017

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.