Exemplo n.º 1
0
def up():
    """
    \b
    Create remote branch,
    same as 'git push --set-upstream origin'
    """
    Gitx().up()
Exemplo n.º 2
0
def p():
    """
    \b
    Pull the latest code from remote  with '--rebase' option.
    It is same as 'git pull --rebase'
    """
    Gitx().p()
Exemplo n.º 3
0
def test_pr_with_git_remote_origin(mock_open_url, mock_current_branch,
                                   mock_remote_url):
    branch = 'master'
    Gitx().pr(branch)
    mock_remote_url.assert_called()
    mock_current_branch.assert_called()
    mock_open_url.assert_called_once_with(
        'https://github.com/qszhuan/git-x/compare/master...abc?expand=1')
Exemplo n.º 4
0
def ci(comment):
    """
    \b
    Commit all the indexed files into repository, same as 'git commit -m <comment>'.
    \b
    Example:
        git ci "This is the comment."
    """
    Gitx().ci(comment, None, None)
Exemplo n.º 5
0
def test_a(include, exclude, expected_calls):
    with mock.patch('gitx.call', return_value=0) as mock_call:
        Gitx().a(include, exclude)
        if expected_calls:
            calls = [mock.call(each) for each in expected_calls]
            print(calls)
            mock_call.assert_has_calls(calls)
        else:
            mock_call.assert_not_called()
Exemplo n.º 6
0
def test_pr_for_bit_bucket_with_git_remote_origin(mock_open_url,
                                                  mock_current_branch,
                                                  mock_remote_url):
    branch = 'master'
    Gitx().pr(branch)
    mock_remote_url.assert_called()
    mock_current_branch.assert_called()
    mock_open_url.assert_called_once_with(
        'https://bitbucket.org/qszhuan/shopping-cart/compare/abc%0Dmaster')
Exemplo n.º 7
0
def b():
    """
    \b
    Show current branch name.
    \b
    Example:
        git b
    """
    Gitx().b()
Exemplo n.º 8
0
def clb():
    """
    \b
    Clean merged local branch.
    It will always let user to confirm before remove.
    By default, it will ignore current branch and branches with name master, dev, develop, trunk.
    Because those branches are mostly used as trunk/release branches.
    \b
    """
    Gitx().clb()
Exemplo n.º 9
0
def test_pr_for_azure_with_https_remote_origin(mock_open_url,
                                               mock_current_branch,
                                               mock_remote_url):
    branch = 'master'
    Gitx().pr(branch)
    mock_remote_url.assert_called()
    mock_current_branch.assert_called()
    mock_open_url.assert_called_once_with(
        'https://dev.azure.com/qszhuan/repo/pullrequestcreate?sourceRef=abc^&targetRef=master'
    )
Exemplo n.º 10
0
def pr(to_branch):
    """
    \b
    Create pull request from current branch to <to_branch>.
    Currently it only support to raise pull request to github and bitbucket.
    The repository url is retrieved from the .git/config file.
    \b
    Examples:
        1. Create PR against master branch
            git pr master
    """
    Gitx().pr(to_branch)
Exemplo n.º 11
0
def m(from_):
    """
    \b
    Merge codes from branch <from> to current branch.
    It will switch to branch <from>, pull the latest code, and then switch back to previous branch,
    and merge the code from <from> into current branch. You need to make sure that there is no unstaged changes.
    \b
    Examples:
        1. Merge latest code from master branch to current branch(develop)
            git m master
    """
    Gitx().m(from_)
Exemplo n.º 12
0
def amend(edit):
    """
    \b
    Amend files into repository, this only amend the files that already in the index.
    \b
    Examples:
        1. Amend without editing
            git amend
        2. Amend, and edit the commit message, this will open the editing window,
            depends on what editor is configured in git.
            git amend -e

    """
    Gitx().amend(None, None, edit)
Exemplo n.º 13
0
def llg(n, graph, author, date):
    """
    \b
    Show recent <number> logs, the default number is 5.
    This is same as 'git log --oneline -n <number>'
    \b
    Example:
        1. Show recent 5 commit messages.
            git llg
        2. Show recent 6 commit messages.
            git llg 6
        3. Show with graph
            git llg -g
        4. Show with graph, author, and date
            git llg -gad
    """
    Gitx().llg(n, graph, author, date)
Exemplo n.º 14
0
def a(pathspec, exclude):
    """
    \b
    Add file that specified in <pathspec> contents into the index.
    Ignore/Remove the file contents from the index if the files are specified in the -x option.
    The <pathspec> syntax is same as the one in 'git status' parameter.
    \b
    Examples:
        1. Add all sql files:
            git a *.sql
        2. Add all files, but ignore all config files(ending with .config extensions)
            git a . -x *.config
        3. Ignore multiple files(*.config, *.md) by using more than one '-x' to specify multiple patterns.
            git a . -x *.config -x *.md
        4. Remove all config files from the index
            git -x *.config
    """
    Gitx().a(list(pathspec), list(exclude))
Exemplo n.º 15
0
def cia(comment, exclude):
    """
    \b
    Add content files into index, and then create a new commit.
    By default it will add all the files under the current folder.
    You can ignore/remove files by specifying in the '-x' option.
    This is a combination of the following commands:
    `git a . -x <pathspec>`
    `git commit -m <comment>`
    \b
    Examples:
        1. Add all files and create a commit.
            git cia "This is the comment"
        2. Exclude *.config files, and create a commit.
            git -x *.config "This is the comment"
        3. Exclude the *.cs and *.config files, and create a commit.
            git -x *.config -x *.cs "This is the comment"
    """
    Gitx().cia(comment, list(exclude))
Exemplo n.º 16
0
def co(start_point, b, f, branch):
    """
    \b
    Check out the branch matching the string in <branch>.
    If multiple branches include the <branch> text, all those branches will be listed and let user to choose.
    This only works if '-b' is not present.
    If '-b' is present, a new branch with name <branch> will be created.
    \b
    Examples:
        Suppose we have 5 existing branches - master, develop, feature_1, feature_2, develop1
        1. Switch to an existing branch 'develop'
            git co develop
        2. Create a new branch 'feature_3'
            git co -b feature_3
        3. Create a new branch, and set the start point with <start_point>
            git co -b feature_3 32aa51b
        4. Switch to a branch with name like 'feature_*'
            gi co feature_
            \b
            Then it will list all indexed branches with 'feature_' in the name, and let the user to choose:
            \b
            Found 4 branches including "feature_":
            ====================
            0: feature_1
            1: feature_2
            ====================
            Please select branch by index:
            \b
            Then, the user can choose 0, click ENTER to switch to feature_1 branch.
        5. Switch to a branch with -f option:
            gi co develop -f
            \b
            if there is a branch name exactly matching 'develop', it will check out that branch,
            no matter there are other branches with 'develop' in the name.
            If there is not exactly matches, then follow the same logic without -f option
            \b
            Found 1 branch exactly matching "develop":
            git co -b -f develop
    """
    Gitx().co(branch, start_point, b, f)
Exemplo n.º 17
0
def test_co_with_exactly_matched_branch_name_forcely(mock_call, mock_popen):
    mock_popen.side_effect = lambda x: 'abc\n  click\n* master\n master2\n' if x == 'git branch' else 0
    Gitx().co("master", force=True)
    mock_call.assert_called_once_with('git checkout master')
Exemplo n.º 18
0
def test_amend(mock_a, mock_call):
    Gitx().amend('a.txt', 'a.txt', False)
    mock_a.assert_called_once_with('a.txt', 'a.txt')
    mock_call.assert_called_once_with('git commit --amend --no-edit')
Exemplo n.º 19
0
def test_amend_no_edit(mock_a, mock_call):
    Gitx().amend('a.txt', 'a.txt', True)
    mock_a.assert_called_once_with('a.txt', 'a.txt')
    mock_call.assert_called_once_with('git commit --amend')
Exemplo n.º 20
0
def test_ci(mock_call):
    Gitx().ci("comment", None, None)
    mock_call.assert_called_once_with('git commit -m "comment"')
Exemplo n.º 21
0
def test_ci_exception(mock_call):
    with pytest.raises(Exception) as e:
        expected = 'Please add a valid comment.'
        Gitx().ci(None, None, None)
        assert e == expected
Exemplo n.º 22
0
def test_co_create_if_not_exist_with_start_point(mock_call):
    Gitx().co("master", 'c1ff877', create_if_not_existed=True)
    mock_call.assert_called_once_with('git checkout -b master c1ff877')
Exemplo n.º 23
0
def test_co_create_if_not_exist(mock_call):
    Gitx().co("master", create_if_not_existed=True)
    mock_call.assert_called_once_with('git checkout -b master')
Exemplo n.º 24
0
def test_co(mock_call):
    Gitx().co("master")
    mock_call.assert_called_once_with('git checkout master')
Exemplo n.º 25
0
def test_co_ignore_start_point_if_not_create_new(mock_call):
    Gitx().co("master", 'c1ff877', create_if_not_existed=False)
    mock_call.assert_called_once_with('git checkout master')
Exemplo n.º 26
0
def test_llg_with_all(mock_call):
    Gitx().llg(d=True, g=True, a=True, n=10)
    expected = 'git log --graph ' \
               '--pretty=format:"%C(auto)%h%Creset %C(auto)%d%Creset %s %Cgreen(%cr)%Creset %C(cyan)<%an>%Creset"' \
               ' --abbrev-commit -n 10'
    mock_call.assert_called_once_with(expected)
Exemplo n.º 27
0
def test_co_with_partial_branch_name_but_not_unique_2(mock_call, mock_popen,
                                                      _):
    mock_popen.side_effect = lambda x: 'abc\n  click\n* master\n' if x == 'git branch' else 0
    Gitx().co("a")
    mock_call.assert_called_once_with('git checkout master')
Exemplo n.º 28
0
def test_llg_with_negative():
    with pytest.raises(Exception) as e:
        n = -1
        Gitx().llg(n)
        expected = 'The commit count must be greater than zero.'
        assert e == expected
Exemplo n.º 29
0
def test_st(mock_call):
    Gitx().st()
    mock_call.assert_called_once_with('git status')
Exemplo n.º 30
0
def test_llg_with_5_by_default(mock_call):
    Gitx().llg()
    expected = 'git log --oneline --pretty=format:"%C(auto)%h%Creset %C(auto)%d%Creset %s" --abbrev-commit -n {}'.format(
        5)
    mock_call.assert_called_once_with(expected)