Beispiel #1
0
def main():
    logging.basicConfig(stream=sys.stdout, level=logging.INFO)
    options = _get_argument_parser().parse_args()

    try:
        repo = git.Repo('.', search_parent_directories=True)
    except git.exc.InvalidGitRepositoryError:
        print bright_red('This is not a valid git repository!')
        return

    try:
        branch = repo.branches[options.branch]
    except IndexError:
        print bright_red('"{}" is not a valid branch!'.format(options.branch))
        return

    active_branch = repo.active_branch

    if options.into:
        to_merge = repo.active_branch
        base = branch
    else:
        to_merge = branch
        base = repo.active_branch

    if _needs_rebase(base, to_merge):
        print bright_red('To merge "{}" into "{}" you must rebase its '
                         'contents first!'.format(to_merge, base))
        print "To do that, run:"
        print "  git checkout {} && git rebase {}".format(to_merge, base)
        return

    if options.skip_tests:
        print bright_yellow('Skipping tests')
        tests_passed = True
    else:
        to_merge.checkout()
        tests_passed = _run_tests()

    if tests_passed:
        print bright_green('Merging "{}" into "{}"'.format(to_merge, base))
        base.checkout()
        try:
            if subprocess.call(['git', 'merge', '--no-ff',
                                to_merge.name]) != 0:
                print bright_red('Something went wrong while merging. '
                                 'Restoring original branch')
                active_branch.checkout()
        except Exception:
            active_branch.checkout()
            raise
    else:
        print bright_red('Tests FAILED! Not merging.')
        active_branch.checkout()
Beispiel #2
0
 def warn(cls, format_str, *args, **kwargs):
     format_str = color.bright_yellow(u"[?] " + format_str)
     return cls._log(format_str, *args, **kwargs)