mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-19 04:21:14 +00:00
Add a git_push_force
rule
This commit is contained in:
parent
ee87d1c547
commit
569709388d
52
tests/rules/test_git_push_force.py
Normal file
52
tests/rules/test_git_push_force.py
Normal file
@ -0,0 +1,52 @@
|
||||
import pytest
|
||||
from thefuck.rules.git_push_force import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
git_err = '''
|
||||
To /tmp/foo
|
||||
! [rejected] master -> master (non-fast-forward)
|
||||
error: failed to push some refs to '/tmp/bar'
|
||||
hint: Updates were rejected because the tip of your current branch is behind
|
||||
hint: its remote counterpart. Integrate the remote changes (e.g.
|
||||
hint: '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.
|
||||
Delta compression using up to 4 threads.
|
||||
Compressing objects: 100% (2/2), done.
|
||||
Writing objects: 100% (3/3), 282 bytes | 0 bytes/s, done.
|
||||
Total 3 (delta 0), reused 0 (delta 0)
|
||||
To /tmp/bar
|
||||
514eed3..f269c79 master -> master
|
||||
'''
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='git push', stderr=git_err),
|
||||
Command(script='git push nvbn', stderr=git_err),
|
||||
Command(script='git push nvbn master', stderr=git_err)])
|
||||
def test_match(command):
|
||||
assert match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='git push', stderr=git_ok),
|
||||
Command(script='git push', stderr=git_uptodate),
|
||||
Command(script='git push nvbn', stderr=git_ok),
|
||||
Command(script='git push nvbn master', stderr=git_uptodate),
|
||||
Command(script='git push nvbn', stderr=git_ok),
|
||||
Command(script='git push nvbn master', stderr=git_uptodate)])
|
||||
def test_not_match(command):
|
||||
assert not match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, output', [
|
||||
(Command(script='git push', stderr=git_err), 'git push --force'),
|
||||
(Command(script='git push nvbn', stderr=git_err), 'git push --force nvbn'),
|
||||
(Command(script='git push nvbn master', stderr=git_err), 'git push --force nvbn master')])
|
||||
def test_get_new_command(command, output):
|
||||
assert get_new_command(command, None) == output
|
15
thefuck/rules/git_push_force.py
Normal file
15
thefuck/rules/git_push_force.py
Normal file
@ -0,0 +1,15 @@
|
||||
from thefuck import utils
|
||||
|
||||
|
||||
@utils.git_support
|
||||
def match(command, settings):
|
||||
return ('git' in command.script
|
||||
and '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)
|
||||
|
||||
|
||||
@utils.git_support
|
||||
def get_new_command(command, settings):
|
||||
return command.script.replace('push', 'push --force')
|
Loading…
x
Reference in New Issue
Block a user