Beispiel #1
0
def fork():
    '''
    fork from github
    :return:
    '''
    subprocess.check_call(['hub', 'clone'])
    return 'SUCCESS: cloned repo from remote'
Beispiel #2
0
def rebase():
    # git rebase -i origin/master
    # todo: cherry-pick 什么意思
    commit()
    subprocess.check_call(
        ['git', 'rebase', '-i', '--autosquash', 'origin/master'])
    return
Beispiel #3
0
def clone(repo):
    '''
    clone from github
    :param repo:
    :return:
    '''
    subprocess.check_call(['hub', 'clone', repo])
    return 'SUCCESS: cloned repo from remote'
Beispiel #4
0
def init():
    '''
    init a new local repo.
    :return:
    '''
    # subprocess.call['git','init']
    subprocess.check_call(['git', 'init'])
    subprocess.check_call(['touch', 'readme.md'])
    commit(m='init commit')
    return "SUCCESS: inited a new project."
Beispiel #5
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'
Beispiel #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."
Beispiel #7
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 "
Beispiel #8
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
Beispiel #9
0
def browse():
    '''
    hub browse
    :return:
    '''
    subprocess.check_call(['hub', 'browse'])