Beispiel #1
0
def main(args):
    name = args.upstream

    code_username = ''
    if not args.origin:
        code_username = get_code_username()
        if not code_username:
            log_error('origin not specified')
            return 1
        repo_name = name.split('/')[-1]
        args.origin = '%s/%s' % (code_username, repo_name)

    if not args.dir:
        args.dir = name.rsplit('/')[-1]
        print_log("Destination dir is not specified, will use {}".format(
            args.dir))

    check_call([
        'git',
        'clone',
        repo_git_url(args.origin,
                     login_user=code_username,
                     provider=args.provider),
        args.dir,
    ])
    with cd(args.dir):
        merge_config()
        check_call(['git', 'remote', 'add', 'upstream', repo_git_url(name)])
Beispiel #2
0
def main(args):
    branch_name = 'hotfix-%s-%s' % (args.start_point, args.issue)
    check_call(['git', 'fetch', 'upstream'])
    check_call([
        'git', 'checkout', '-b', branch_name, '--no-track',
        'upstream/' + args.start_point
    ])
Beispiel #3
0
def add_remote(username):
    user_git_url = origin_git_url = None

    output = getoutput(['git', 'remote', '-v'])
    for line in output.splitlines():
        words = line.split()
        if words[0] == 'origin':
            origin_git_url = words[1]
        if words[0] == username:
            user_git_url = words[1]

    if not origin_git_url:
        raise Exception("No origin remote found, abort")

    repo = origin_git_url.rsplit('/', 1)[-1].rsplit('.', 1)[0]
    remote_name = username
    remote_url = repo_git_url('%s/%s' % (username, repo))

    if user_git_url:
        if user_git_url != remote_url:
            raise Exception("remote %s already exists, delete it first?")
        # already added
        return

    check_call(['git', 'remote', 'add', remote_name, remote_url])
Beispiel #4
0
def branch_is_published_already(branch):
    check_call(['git', 'fetch', 'origin'])
    commits = getoutput(['git', 'log', '--pretty=oneline', 'master..%s' % branch])
    if commits:
        log_line = commits.split('\n')[-1]
        first_ci = log_line.split()[0]
    else:
        first_ci = branch
    return bool(getoutput(['git', 'branch', '-r', '--contains', first_ci]))
Beispiel #5
0
def branch_is_published_already(branch):
    check_call(['git', 'fetch', 'origin'])
    commits = getoutput(
        ['git', 'log', '--pretty=oneline',
         'master..%s' % branch])
    if commits:
        log_line = commits.split('\n')[-1]
        first_ci = log_line.split()[0]
    else:
        first_ci = branch
    return bool(getoutput(['git', 'branch', '-r', '--contains', first_ci]))
Beispiel #6
0
def main(args):
    url = repo_git_url(args.repo)
    cmd = ['git', 'clone', url]

    if args.dir:
        cmd.append(args.dir)
        dir = args.dir
    else:
        dir = url.rsplit('/', 1)[-1].rpartition('.git')[0]

    check_call(cmd)

    with cd(dir):
        merge_config()

        # set upstream to origin to make other code commands work
        check_call(['git', 'remote', 'add', 'upstream', url])
Beispiel #7
0
def main(args):
    url = repo_git_url(args.repo, provider=args.provider)
    cmd = ['git', 'clone', url]

    if args.dir:
        cmd.append(args.dir)
        dir = args.dir
    else:
        dir = url.rsplit('/', 1)[-1].rpartition('.git')[0]

    check_call(cmd)

    with cd(dir):
        merge_config()

        # set upstream to origin to make other code commands work
        check_call(['git', 'remote', 'add', 'upstream', url])
Beispiel #8
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.ask(
                "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 = utils.ask("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])
Beispiel #9
0
def main(args):
    name = args.upstream

    code_username = ''
    if not args.origin:
        code_username = get_code_username()
        if not code_username:
            log_error('origin not specified')
            return 1
        args.origin = '%s/%s' % (code_username, name)

    if not args.dir:
        args.dir = name.rsplit('/')[-1]
        print_log("Destination dir is not specified, will use {}".format(args.dir))

    check_call(['git', 'clone', repo_git_url(args.origin, login_user=code_username), args.dir])
    with cd(args.dir):
        merge_config()
        check_call(['git', 'remote', 'add', 'upstream', repo_git_url(name)])
Beispiel #10
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 = ask("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])
Beispiel #11
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 = ask("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])
Beispiel #12
0
def start(branch, remote='upstream', fetch_args=[], base_ref='upstream/master'):
    existing_branches = get_branches()
    if branch in existing_branches:
        answer = ask("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])
Beispiel #13
0
def start(branch, remote='upstream', checkout_branch='master', fetch_args=[]):
    existing_branches = get_branches()
    if branch in existing_branches:
        answer = ask("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)

    base_ref = '%s/%s' % (remote, checkout_branch)
    check_call(['git', 'fetch', remote] + fetch_args)
    check_call(['git', 'checkout', '-b', branch, '--no-track', base_ref])
Beispiel #14
0
def push_to_my_fork(branch):
    check_call(['git', 'push', '--set-upstream', 'origin', branch])
Beispiel #15
0
def main(args):
    branch_name = 'hotfix-%s-%s' % (args.start_point, args.issue)
    check_call(['git', 'fetch', 'upstream'])
    check_call(['git', 'checkout', '-b', branch_name,
                '--no-track', 'upstream/' + args.start_point])
Beispiel #16
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])
Beispiel #17
0
def fetch(remote_name):
    check_call(['git', 'fetch', remote_name])
Beispiel #18
0
def push_to_my_fork(branch):
    check_call(['git', 'push', '--set-upstream', 'origin', branch])
Beispiel #19
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])
Beispiel #20
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 = ask("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])