From 37c92d9352fdb9e166a0a135840992c235a2582b Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Sat, 10 Nov 2018 16:06:42 -0800 Subject: [PATCH] filter-repo: handle tags pointing at commits pruned along with their history If a tag points at a commit whose changes are all filtered out and thus becomes empty and gets pruned, and all of its ancestors are likewise pruned, then there is no need for the tag; just nuke it. Signed-off-by: Elijah Newren --- git-filter-repo | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/git-filter-repo b/git-filter-repo index 63ca715..8312559 100755 --- a/git-filter-repo +++ b/git-filter-repo @@ -1154,8 +1154,6 @@ class FastExportFilter(object): # Parse the Tag tag = self._parse_ref_line('tag') from_ref = self._parse_optional_parent_ref('from') - if from_ref is None: - raise SystemExit("Expected 'from' line while parsing tag %s" % tag) original_id = None if self._currentline.startswith('original-oid'): @@ -1177,8 +1175,17 @@ class FastExportFilter(object): if self._everything_callback: self._everything_callback('tag', tag) - # Now print the resulting reset - if not tag.dumped: + # The tag might not point at anything that still exists ( self.from_ref + # will be None if the commit it pointed to and all its ancestors were + # pruned due to being empty) + if not tag.from_ref: + # If everything in the history of this tag was pruned, we need to delete + # the fact that it was seen so that refs_to_nuke will include it and + # wipe out the original version of that tag. + full_ref = 'refs/tags/{}'.format(tag.ref) + if full_ref in self._seen_refs: + del self._seen_refs[full_ref] + elif not tag.dumped: tag.dump(self._output) def _parse_progress(self):