Ejemplo n.º 1
0
def fork():
    '''
    fork from github
    :return:
    '''
    subprocess.check_call(['hub', 'clone'])
    return 'SUCCESS: cloned repo from remote'
Ejemplo n.º 2
0
def rebase():
    # git rebase -i origin/master
    # todo: cherry-pick 什么意思
    commit()
    subprocess.check_call(
        ['git', 'rebase', '-i', '--autosquash', 'origin/master'])
    return
Ejemplo n.º 3
0
def clone(repo):
    '''
    clone from github
    :param repo:
    :return:
    '''
    subprocess.check_call(['hub', 'clone', repo])
    return 'SUCCESS: cloned repo from remote'
Ejemplo n.º 4
0
def create():
    # api: curl -u "$username:$token" https://api.github.com/user/repos -d '{"name":"'$repo_name'"}'
    # https://viget.com/extend/create-a-github-repo-from-the-command-line
    # github 工具, hub: https://hub.github.com/
    '''
    create remote github repo for current directory.
    :return:
    '''
    subprocess.check_call(['hub', 'create'])
    return 'SUCCESS: remote github repo created or existed'
Ejemplo n.º 5
0
def add_remote():
    '''
    add remote repo
    :return: the status whether successful
    '''
    project_name = os.path.basename(os.path.abspath('.'))
    # todo: 异常处理
    subprocess.call(['git', 'remote', 'add', 'origin', '[email protected]:lhrkkk/%s.git' % project_name])
    subprocess.check_call(['git', 'remote', '-v'])
    return "SUCCESS: pushed to remote "
Ejemplo n.º 6
0
def sync():
    '''
    sync remote changes to local branch.
    :return:
    '''
    # git fetch origin
    commit()
    subprocess.check_call(['git', 'fetch', 'origin'])
    # git rebase origin master
    subprocess.check_call(['git', 'rebase', 'origin/master'])
    return "SUCCESS: synced to remote repo."
Ejemplo n.º 7
0
def init():
    '''
    init a new local repo.
    :return:
    '''
    # subprocess.call['git','init']
    if len(os.listdir('.')) == 0:
        subprocess.check_call(['touch', 'readme.md'])
    subprocess.check_call(['git', 'init'])
    commit(m='init commit')
    return "SUCCESS: inited a new project."
Ejemplo n.º 8
0
def switch(branch_name, from_branch='master'):
    '''
    from the newest master checkout a new branch named branch_name, 要先pull
    :param branch_name:
    :return:
    '''
    from_branch='master'

    if not branch_is_exist(branch_name):
        subprocess.check_call(['git', 'checkout', from_branch])
        flag = 'y'
        try:
            subprocess.check_call(['git', 'pull'])
        except:
            print("ERROR: no remote source specified")
            flag = raw_input("Do you want to checkout from local master? [y(default)/n]:")
            # todo: 修改 new 为 switch 并且处理 remote 分支存在的问题.
        if flag == 'y' or flag == 'yes':
            subprocess.check_call(['git', 'checkout', '-b', branch_name])
            return "SUCCESS: new branch %s created and checked out" % branch_name
        else:
            return ("command canceled")
    else:
        # flag = raw_input("Branch does not exist. Do you want to create a new one ? [y(default)/n]:")
        # if flag == 'y' or flag == 'yes':

        subprocess.check_call(['git', 'checkout', branch_name])
Ejemplo n.º 9
0
def newbranch(branch_name, from_branch='master'):
    '''
    from the newest master checkout a new branch named branch_name, 要先pull
    :param branch_name:
    :return:
    '''
    # if not from_branch:
    #     from_branch='master'
    subprocess.check_call(['git', 'checkout', from_branch])
    flag = 'y'
    try:
        subprocess.check_call(['git', 'pull'])
    except:
        print("ERROR: no remote source specified")
        flag = raw_input("do you want to continue?")
    if flag == 'y' or flag == 'yes':
        subprocess.check_call(['git', 'checkout', '-b', branch_name])
        return "SUCCESS: new branch %s created and checked out" % branch_name
    else:
        return
Ejemplo n.º 10
0
def browse():
    '''
    hub browse
    :return:
    '''
    subprocess.check_call(['hub', 'browse'])
Ejemplo n.º 11
0
def rebase():
    # git rebase -i origin/master
    # 就用origin/master, rebase对比仓库的head
    commit()
    subprocess.check_call(['git', 'rebase', '-i', '--autosquash', 'origin/master'])
    return