Thread (12 messages) 12 messages, 4 authors, 1d ago

Re: [PATCH] fiter-branch: fix commit map init from state branch

From: Michele Locati <hidden>
Date: 2026-09-30 20:41:35

Hi Patrick,
Michele, it seems like you have already invested some time into
reproducing the issue. Can this maybe be put into a proper test case
that directly exercises your issues (that is, the swapped entries and
such)?
Sure. The test below performs an incremental rewrite in two runs:
the second run must attach the new commit to the parent rewritten by
the first run, and the saved state must contain "original:rewritten"
entries. Without the fix the new commit is attached to the original
parent, and the test fails at test_cmp_rev.

I checked it against master (a018953): it fails without the fix and
passes with it, and the other tests of t7003 still pass. It also
passes with v2.49.1, the last version before the regression.

Grant, feel free to squash it into your patch.
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -126,6 +126,27 @@ test_expect_success 'using --state-branch to skip already rewritten commits' '
 	test_cmp_rev $W HEAD
 '
 
+test_expect_success '--state-branch incremental rewrite uses the rewritten parents' '
+	git init incremental &&
+	(
+		cd incremental &&
+		mkdir sub &&
+		test_commit first sub/file &&
+		test_commit outside root-file &&
+		git filter-branch --state-branch refs/state \
+			--prune-empty --subdirectory-filter sub -- HEAD &&
+		rewritten_first=$(git rev-parse HEAD) &&
+		git reset --hard outside &&
+		test_commit second sub/file &&
+		git filter-branch -f --state-branch refs/state \
+			--prune-empty --subdirectory-filter sub -- outside..HEAD &&
+		test_cmp_rev $rewritten_first HEAD^ &&
+		git show refs/state:filter.map >map &&
+		echo "$(git rev-parse second):$(git rev-parse HEAD)" >expect &&
+		grep "^$(git rev-parse second):" map >actual &&
+		test_cmp expect actual
+	)
+'
+
 git tag oldD HEAD~4
 test_expect_success 'rewrite one branch, keeping a side branch' '
 	git branch modD oldD &&
Thanks,
Michele
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help