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 <newren@gmail.com>
This commit is contained in:
Elijah Newren 2020-10-08 00:38:09 -07:00
parent b1606ba8ac
commit 7eaaf191de
2 changed files with 27 additions and 0 deletions

View File

@ -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):
"""

View File

@ -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 &&
(