Skip to content

Commit 7eaaf19

Browse files
committed
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 <[email protected]>
1 parent b1606ba commit 7eaaf19

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

git-filter-repo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,8 @@ class FastExportParser(object):
13141314
if not tag.dumped:
13151315
self._imported_refs.add(b'refs/tags/'+tag.ref)
13161316
tag.dump(self._output)
1317+
else:
1318+
tag.skip()
13171319

13181320
def _parse_progress(self):
13191321
"""

t/t9390-filter-repo.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,31 @@ test_expect_success '--tag-rename' '
317317
)
318318
'
319319

320+
test_expect_success 'tag of tag before relevant portion of history' '
321+
test_create_repo filtered_tag_of_tag &&
322+
(
323+
cd filtered_tag_of_tag &&
324+
echo contents >file &&
325+
git add file &&
326+
git commit -m "Initial" &&
327+
328+
git tag -a -m "Inner Tag" inner_tag HEAD &&
329+
git tag -a -m "Outer Tag" outer_tag inner_tag &&
330+
331+
mkdir subdir &&
332+
echo stuff >subdir/whatever &&
333+
git add subdir &&
334+
git commit -m "Add file in subdir" &&
335+
336+
git filter-repo --force --subdirectory-filter subdir &&
337+
338+
git show-ref >refs &&
339+
! grep refs/tags refs &&
340+
git log --all --oneline >commits &&
341+
test_line_count = 1 commits
342+
)
343+
'
344+
320345
test_expect_success '--subdirectory-filter' '
321346
setup_metasyntactic_repo &&
322347
(

0 commit comments

Comments
 (0)