def get_merge_commit(commit, branch=u'master'):
 commit_range = u'{}..{}'.format(commit, branch)
 ancestry_paths = git.rev_list(commit_range, ancestry_path=True).splitlines()
 first_parents = git.rev_list(commit_range, first_parent=True).splitlines()
 both = (set(ancestry_paths) & set(first_parents))
 for commit_hash in reversed(ancestry_paths):
  if (commit_hash in both):
   return repo.commit(commit_hash)
 msg = u'No merge commit for {commit} in {branch}!'.format(commit=commit, branch=branch)
 raise DoesNotExist(msg, commit, branch)

def get_merge_commit ( commit , branch = u'master' ) : commit_range = u'{}..{}' . format ( commit , branch ) ancestry_paths = git . rev_list ( commit_range , ancestry_path = True ) . splitlines ( ) first_parents = git . rev_list ( commit_range , first_parent = True ) . splitlines ( ) both = ( set ( ancestry_paths ) & set ( first_parents ) ) for commit_hash in reversed ( ancestry_paths ) : if ( commit_hash in both ) : return repo . commit ( commit_hash ) msg = u'No merge commit for {commit} in {branch}!' . format ( commit = commit , branch = branch ) raise DoesNotExist ( msg , commit , branch )
given a commit that was merged into the given branch .