From 837ca73f50b3e622a0454f8d2678acabdb019c14 Mon Sep 17 00:00:00 2001 From: Julian Zimmermann Date: Thu, 7 Jul 2016 11:47:51 +0200 Subject: [PATCH] Added "contains work" error for git push --- tests/rules/test_git_push_pull.py | 29 +++++++++++++++++++++++++++++ thefuck/rules/git_push_pull.py | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/rules/test_git_push_pull.py b/tests/rules/test_git_push_pull.py index 0e950df4..afa74748 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 c4e4e41b..d55b5194 100644 --- a/thefuck/rules/git_push_pull.py +++ b/thefuck/rules/git_push_pull.py @@ -8,7 +8,7 @@ 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) + 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