diff --git a/git_upstream/lib/searchers.py b/git_upstream/lib/searchers.py index 81300fc..3d6f8ca 100644 --- a/git_upstream/lib/searchers.py +++ b/git_upstream/lib/searchers.py @@ -132,10 +132,15 @@ class Searcher(GitMixin): # happens to be in a list of commits directly between the tip and # previous upstream import, then it is simply a merge of an obsolete # commit. These are very difficult to strip out normally - if any(self.git.merge_base( - parent, p, with_exceptions=False) in ancestry_commits - for p in other_parents): - return None, [], other_parents + exclude_commits = [] + for p in other_parents: + if self.git.merge_base( + p, parent, with_exceptions=False) in ancestry_commits: + exclude_commits.extend( + self.git.rev_list("%s..%s" % (parent, p)).splitlines()) + + if exclude_commits: + return None, [], exclude_commits # otherwise looking at the previous import merge commit and the parent # from the previous import branch, so exclude all other parents. diff --git a/git_upstream/tests/searchers/scenarios/treesame_change_approved_after_import_merge.yaml b/git_upstream/tests/searchers/scenarios/treesame_change_approved_after_import_merge.yaml index 51c7199..cabf3a6 100644 --- a/git_upstream/tests/searchers/scenarios/treesame_change_approved_after_import_merge.yaml +++ b/git_upstream/tests/searchers/scenarios/treesame_change_approved_after_import_merge.yaml @@ -12,7 +12,7 @@ Repository layout being tested - O------------ + O---P-------- / \ B---C---D---G---H---I---J---K master / / @@ -26,6 +26,7 @@ - [B, [A]] - [C, [B]] - [O, [C]] + - [P, [O]] - [D, [C]] - [E, [A]] - [F, [E]] @@ -35,7 +36,7 @@ - [D1, [C1]] - [H, [G, =D1]] # next node definition ensures I is TREESAME to H - - [I, [=H, O]] + - [I, [=H, P]] - [J, [I]] - [K, [J]] - [L, [F]] diff --git a/git_upstream/tests/searchers/scenarios/treesame_change_approved_no_previous_import.yaml b/git_upstream/tests/searchers/scenarios/treesame_change_approved_no_previous_import.yaml index 5ed9185..da9668f 100644 --- a/git_upstream/tests/searchers/scenarios/treesame_change_approved_no_previous_import.yaml +++ b/git_upstream/tests/searchers/scenarios/treesame_change_approved_no_previous_import.yaml @@ -12,7 +12,7 @@ Repository layout being tested - O---- + O---P / \ B---C---D---G---H master / @@ -24,10 +24,11 @@ - [B, [A]] - [C, [B]] - [O, [C]] + - [P, [O]] - [D, [C]] - [E, [A]] - [F, [E]] - - [G, [=D, O]] + - [G, [=D, P]] - [H, [G]] - [L, [F]] - [M, [L]]