Exemple #1
0
def merge_and_push(from_branch, to_branch):
    check_call(['git', 'fetch', 'upstream'])
    local_branch = 'merge/{0}-to-{1}'.format(from_branch, to_branch)
    existing_branches = get_branches()
    answer = 'd'
    if local_branch in existing_branches:
        answer = input(
            "Branch {0} exists.  Should I (d)estroy it and "
            "re-merge from scratch, or re(u)se it in case you "
            "were resolving merge conflicts just now? (D/u) ".format(
                local_branch),
            pattern=r'[dDuU]',
            default='d').lower()[0]

    if answer == 'd':
        check_call([
            'git', 'checkout', '-B', local_branch,
            'upstream/{0}'.format(to_branch)
        ])

    else:
        check_call(['git', 'checkout', local_branch])

    check_call(['git', 'merge', 'upstream/{0}'.format(from_branch)])
    check_call(
        ['git', 'push', 'upstream', '{0}:{1}'.format(local_branch, to_branch)])
    check_call(['git', 'checkout', 'master'])
    check_call(['git', 'branch', '-d', local_branch])
Exemple #2
0
def start(branch, remote='upstream', fetch_args=[], base_ref='upstream/master'):
    existing_branches = get_branches()
    if branch in existing_branches:
        answer = input("Branch %s exists, (s)witch to it or re(c)reate "
                       "it?  (S/c) " % branch, pattern=r'[sScC]',
                       default='s')
        answer = answer.lower()[0]

        if answer == 's':
            check_call(['git', 'checkout', branch])
            return

        elif answer == 'c':
            end_branch(branch, force=True)

    check_call(['git', 'fetch', remote] + fetch_args)
    check_call(['git', 'checkout', '-b', branch, '--no-track', base_ref])
Exemple #3
0
    def merge_config(self):
        email = utils.get_config('user.email')
        if not email:
            email = utils.getoutput(['git', 'config', 'user.email']).strip()
            if not email.endswith('@douban.com'):
                email = '*****@*****.**' % getuser()
            email = utils.input("Please enter your @douban.com email [%s]: " %
                                email,
                                default=email)
            utils.set_config('user.email', email)

        name = utils.get_user_name()
        if not name:
            name = email.split('@')[0]
            name = input("Please enter your name [%s]: " % name, default=name)
            utils.set_config('user.name', name)

        for key, value in utils.iter_config():
            utils.check_call(['git', 'config', key, value])
Exemple #4
0
    def merge_config(self):
        email = utils.get_config('user.email')
        if not email:
            email = utils.getoutput(['git', 'config', 'user.email']).strip()
            if not email.endswith('@douban.com'):
                email = '*****@*****.**' % getuser()
            email = utils.input(
                "Please enter your @douban.com email [%s]: " % email,
                default=email)
            utils.set_config('user.email', email)

        name = utils.get_user_name()
        if not name:
            name = email.split('@')[0]
            name = input("Please enter your name [%s]: " % name, default=name)
            utils.set_config('user.name', name)

        for key, value in utils.iter_config():
            utils.check_call(['git', 'config', key, value])
Exemple #5
0
def end_branch(branch, force):
    if branch == get_current_branch_name():
        check_call(['git', 'checkout', 'master'])
    if force:
        check_call(['git', 'branch', '-D', branch])
    else:
        try:
            check_call(['git', 'branch', '-d', branch])
        except subprocess.CalledProcessError:
            log_error("Failed to delete branch %s because it is not fully "
                      "merged (may cause commits loss)." % branch)
            answer = input("Do you want to force to delete it even so? (y/N) ",
                           pattern=r'[nNyY].*', default='n')
            if answer[0] in 'yY':
                check_call(['git', 'branch', '-D', branch])
            else:
                raise

    if does_branch_exist_on_origin(branch):
        check_call(['git', 'push', 'origin', ':%s' % branch])
Exemple #6
0
def start(branch,
          remote='upstream',
          fetch_args=[],
          base_ref='upstream/master'):
    existing_branches = get_branches()
    if branch in existing_branches:
        answer = input("Branch %s exists, (s)witch to it or re(c)reate "
                       "it?  (S/c) " % branch,
                       pattern=r'[sScC]',
                       default='s')
        answer = answer.lower()[0]

        if answer == 's':
            check_call(['git', 'checkout', branch])
            return

        elif answer == 'c':
            end_branch(branch, force=True)

    check_call(['git', 'fetch', remote] + fetch_args)
    check_call(['git', 'checkout', '-b', branch, '--no-track', base_ref])
Exemple #7
0
def end_branch(branch, force):
    if branch == get_current_branch_name():
        check_call(['git', 'checkout', 'master'])
    if force:
        check_call(['git', 'branch', '-D', branch])
    else:
        try:
            check_call(['git', 'branch', '-d', branch])
        except subprocess.CalledProcessError:
            log_error("Failed to delete branch %s because it is not fully "
                      "merged (may cause commits loss)." % branch)
            answer = input("Do you want to force to delete it even so? (y/N) ",
                           pattern=r'[nNyY].*',
                           default='n')
            if answer[0] in 'yY':
                check_call(['git', 'branch', '-D', branch])
            else:
                raise

    if does_branch_exist_on_origin(branch):
        check_call(['git', 'push', 'origin', ':%s' % branch])
Exemple #8
0
def merge_and_push(from_branch, to_branch):
    check_call(["git", "fetch", "upstream"])
    local_branch = "merge/{0}-to-{1}".format(from_branch, to_branch)
    existing_branches = get_branches()
    answer = "d"
    if local_branch in existing_branches:
        answer = input(
            "Branch {0} exists.  Should I (d)estroy it and "
            "re-merge from scratch, or re(u)se it in case you "
            "were resolving merge conflicts just now? (D/u) ".format(local_branch),
            pattern=r"[dDuU]",
            default="d",
        ).lower()[0]

    if answer == "d":
        check_call(["git", "checkout", "-B", local_branch, "upstream/{0}".format(to_branch)])

    else:
        check_call(["git", "checkout", local_branch])

    check_call(["git", "merge", "upstream/{0}".format(from_branch)])
    check_call(["git", "push", "upstream", "{0}:{1}".format(local_branch, to_branch)])
    check_call(["git", "checkout", "master"])
    check_call(["git", "branch", "-d", local_branch])