From 7b18e6d7f5f31deb5a727d64a20c3a0e1323e6c9 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Sat, 16 May 2020 12:15:05 -0700 Subject: [PATCH] filter-repo: fix --prune-degenerate=never with path filtering When combining `--prune-degenerate never` with a `--path` specification, we could end up trying to write a parent out to the fast-import stream whose value was actually None. The problem occurs when the parents of a merge commit are filtered out by the path specification, leaving us only with no-longer-extant parents. In such a case, we need to filter out these 'None' (i.e. invalid) parents. The point of `--prune-degenerate never` is to avoid removing parents that are either the same as or an ancestor of another parent, not to avoid removing non-existent parents. Remove the non-existent parent(s). Reported-by: Gaurav Kanoongo (@gauravkanoongo on GitHub) Signed-off-by: Elijah Newren --- git-filter-repo | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/git-filter-repo b/git-filter-repo index ce8eee8..452cf72 100755 --- a/git-filter-repo +++ b/git-filter-repo @@ -3025,8 +3025,6 @@ class RepoFilter(object): Returns a tuple: (parents, new_first_parent_if_would_become_non_merge)''' - if self._args.prune_degenerate == 'never': - return parents, None always_prune = (self._args.prune_degenerate == 'always') # Pruning of empty commits means multiple things: @@ -3051,6 +3049,10 @@ class RepoFilter(object): if len(parents) < 2: return parents, None + # Don't remove redundant parents if user doesn't want us to + if self._args.prune_degenerate == 'never': + return parents, None + # Remove duplicate parents (if both sides of history have lots of commits # which become empty due to pruning, the most recent ancestor on both # sides may be the same commit), except only remove parents that have