

def smart_merge(branch, allow_rebase=True):
    repo_check()
    from_branch = get_current_branch_name()
    merges = repo.git.execute([git, 'log', '--merges', '{0}..{1}'.format(branch, from_branch)])
    if allow_rebase:
        verb = ('merge' if merges.count('commit') else 'rebase')
    else:
        verb = 'merge'
    try:
        return repo.git.execute([git, verb, branch])
    except GitCommandError as why:
        log = repo.git.execute([git, verb, '--abort'])
        abort('Merge failed. Reverting.', log='{0}\n{1}'.format(why, log), type='merge')

dataset/ETHPy150Open kennethreitz/legit/legit/scm.py smart_merge/original