diff --git a/git_upstream/lib/searchers.py b/git_upstream/lib/searchers.py index 59dce2c..5c124d0 100644 --- a/git_upstream/lib/searchers.py +++ b/git_upstream/lib/searchers.py @@ -128,7 +128,9 @@ class Searcher(GitMixin): self.log.debug("Merge base is not the same as root merge base") return None, [], None - other_parents = [p.hexsha for p in mergecommit.parents if p != parent] + other_parents = set( + p.hexsha for p in mergecommit.parents if p != parent + ) self.log.debug("Merge base is same: other_parents: %s", other_parents) # if the merge base of the parent against any of the other parents @@ -145,6 +147,11 @@ class Searcher(GitMixin): if exclude_commits: return None, [], exclude_commits + # handle case where merges are always created in GitHub even when + # not needed. + if other_parents.issubset(ancestry_commits): + return None, [], [] + # otherwise looking at the previous import merge commit and the parent # from the previous import branch, so exclude all other parents. return mergecommit, ["^%s" % ip for ip in other_parents], None diff --git a/git_upstream/tests/searchers/scenarios/explict-merge-treesame.yaml b/git_upstream/tests/searchers/scenarios/explict-merge-treesame.yaml new file mode 100644 index 0000000..1029b71 --- /dev/null +++ b/git_upstream/tests/searchers/scenarios/explict-merge-treesame.yaml @@ -0,0 +1,37 @@ +- desc: | + Construct a repo layout where using a complex layout where no + previous import from upstream having been completed, test that if a + change has been explicitly merged (common with GitHub PR's) without + it being necessary, then the searcher will correct include the + change and not detect it as a possible import merge + + will the searcher correctly include 'O' below even though there was + no need for a merge 'D' to be created. + + Repository layout being tested + + O + / \ + B---C---D---G master + / + A---E---F---L---M upstream/master + + + tree: + - [A, []] + - [B, [A]] + - [C, [B]] + - [O, [C]] + - [D, [C, =O]] + - [E, [A]] + - [F, [E]] + - [G, [D]] + - [L, [F]] + - [M, [L]] + + branches: + head: [master, G] + upstream: [upstream/master, M] + + expected-changes: [B, C, O, D, G] +