From 057947f6ffd6109148d5902cb6754e69d635c873 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Wed, 7 Nov 2018 11:46:26 -0800 Subject: [PATCH] filter-repo: prune commits that started empty if they now have no parents If ancient history that pre-dated some subdirectory had a few empty commits, we would rather those all got pruned as well. Empty commits from the original repository should only be retained if they have at least one retained parent. Signed-off-by: Elijah Newren --- git-filter-repo | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/git-filter-repo b/git-filter-repo index 993bc6e..4ffa584 100755 --- a/git-filter-repo +++ b/git-filter-repo @@ -987,9 +987,10 @@ class FastExportFilter(object): # Now print the resulting commit, unless all its changes were dropped and # it was a non-merge commit - merge_commit = len(commit.get_parents()) > 1 + merge_commit = len(parents) > 1 if not commit.dumped: - if merge_commit or not had_file_changes or commit.file_changes: + if (commit.file_changes or merge_commit or + (not had_file_changes and len(parents) >= 1)): commit.dump(self._output) new_id = None # Determine the mapping of old commit hash to new one