From 7eaaf191de209b0013ed1b97db5c9be0a24e3de9 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Thu, 8 Oct 2020 00:38:09 -0700 Subject: [PATCH] filter-repo: correctly prune nested tags not matching filtering criteria When the user specifies some kind of criteria to filter commits by (e.g. --subdirectory-filter mysubdir), we rewrite parents commits that are entirely filtered out to the most recent ancestor that still exists, or just prune the parent if there isn't one. That works great when the parent is a commit, but nested tags have parents that are tags. If we only prune the first tag (i.e. the tag of a commit), then letting any tags through that had that tag as a parent will result in a fast-import crash with a message of the form fatal: mark :35390 not declared Ensure that when a tag gets pruned, the pruning is recorded as such...so that any children tags will get pruned as well. Signed-off-by: Elijah Newren --- git-filter-repo | 2 ++ t/t9390-filter-repo.sh | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/git-filter-repo b/git-filter-repo index ac039ec..3c7fd0c 100755 --- a/git-filter-repo +++ b/git-filter-repo @@ -1314,6 +1314,8 @@ class FastExportParser(object): if not tag.dumped: self._imported_refs.add(b'refs/tags/'+tag.ref) tag.dump(self._output) + else: + tag.skip() def _parse_progress(self): """ diff --git a/t/t9390-filter-repo.sh b/t/t9390-filter-repo.sh index 14bdeaa..d2186b0 100755 --- a/t/t9390-filter-repo.sh +++ b/t/t9390-filter-repo.sh @@ -317,6 +317,31 @@ test_expect_success '--tag-rename' ' ) ' +test_expect_success 'tag of tag before relevant portion of history' ' + test_create_repo filtered_tag_of_tag && + ( + cd filtered_tag_of_tag && + echo contents >file && + git add file && + git commit -m "Initial" && + + git tag -a -m "Inner Tag" inner_tag HEAD && + git tag -a -m "Outer Tag" outer_tag inner_tag && + + mkdir subdir && + echo stuff >subdir/whatever && + git add subdir && + git commit -m "Add file in subdir" && + + git filter-repo --force --subdirectory-filter subdir && + + git show-ref >refs && + ! grep refs/tags refs && + git log --all --oneline >commits && + test_line_count = 1 commits + ) +' + test_expect_success '--subdirectory-filter' ' setup_metasyntactic_repo && (