diff --git a/tests/rules/test_git_push_pull.py b/tests/rules/test_git_push_pull.py index 0e950df..afa7474 100644 --- a/tests/rules/test_git_push_pull.py +++ b/tests/rules/test_git_push_pull.py @@ -13,6 +13,17 @@ To /tmp/foo hint: See the 'Note about fast-forwards' in 'git push --help' for details. ''' +git_err2 = ''' +To /tmp/foo + ! [rejected] master -> master (non-fast-forward) + error: failed to push some refs to '/tmp/bar' +hint: Updates were rejected because the remote contains work that you do +hint: not have locally. This is usually caused by another repository pushing +hint: to the same ref. You may want to first integrate the remote changes +hint: (e.g., 'git pull ...') before pushing again. +hint: See the 'Note about fast-forwards' in 'git push --help' for details. +''' + git_uptodate = 'Everything up-to-date' git_ok = ''' Counting objects: 3, done. @@ -33,6 +44,14 @@ def test_match(command): assert match(command) +@pytest.mark.parametrize('command', [ + Command(script='git push', stderr=git_err2), + Command(script='git push nvbn', stderr=git_err2), + Command(script='git push nvbn master', stderr=git_err2)]) +def test_match(command): + assert match(command) + + @pytest.mark.parametrize('command', [ Command(script='git push', stderr=git_ok), Command(script='git push', stderr=git_uptodate), @@ -52,3 +71,13 @@ def test_not_match(command): 'git pull nvbn master && git push nvbn master')]) def test_get_new_command(command, output): assert get_new_command(command) == output + + +@pytest.mark.parametrize('command, output', [ + (Command(script='git push', stderr=git_err2), 'git pull && git push'), + (Command(script='git push nvbn', stderr=git_err2), + 'git pull nvbn && git push nvbn'), + (Command(script='git push nvbn master', stderr=git_err2), + 'git pull nvbn master && git push nvbn master')]) +def test_get_new_command(command, output): + assert get_new_command(command) == output diff --git a/thefuck/rules/git_push_pull.py b/thefuck/rules/git_push_pull.py index c4e4e41..785e74f 100644 --- a/thefuck/rules/git_push_pull.py +++ b/thefuck/rules/git_push_pull.py @@ -5,10 +5,13 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('push' in command.script - and '! [rejected]' in command.stderr - and 'failed to push some refs to' in command.stderr - and 'Updates were rejected because the tip of your current branch is behind' in command.stderr) + return ('push' in command.script and + '! [rejected]' in command.stderr and + 'failed to push some refs to' in command.stderr and + ('Updates were rejected because the tip of your' + ' current branch is behind' in command.stderr or + 'Updates were rejected because the remote ' + 'contains work that you do' in command.stderr)) @git_support