mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-14 14:48:49 +00:00
Add git merge rule
This commit is contained in:
parent
f966ecd4f5
commit
6a07cc396a
26
tests/rules/test_git_merge.py
Normal file
26
tests/rules/test_git_merge.py
Normal file
@ -0,0 +1,26 @@
|
||||
import pytest
|
||||
from thefuck.rules.git_merge import match, get_new_command
|
||||
from thefuck.types import Command
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def output():
|
||||
return 'merge: local - not something we can merge\n\n' \
|
||||
'Did you mean this?\n\tremote/local'
|
||||
|
||||
|
||||
def test_match(output):
|
||||
assert match(Command('git merge test', output))
|
||||
assert not match(Command('git merge master', ''))
|
||||
assert not match(Command('ls', output))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('git merge local', output()),
|
||||
'git merge remote/local'),
|
||||
(Command('git merge -m "test" local', output()),
|
||||
'git merge -m "test" remote/local'),
|
||||
(Command('git merge -m "test local" local', output()),
|
||||
'git merge -m "test local" remote/local')])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert get_new_command(command) == new_command
|
18
thefuck/rules/git_merge.py
Normal file
18
thefuck/rules/git_merge.py
Normal file
@ -0,0 +1,18 @@
|
||||
import re
|
||||
from thefuck.utils import replace_argument
|
||||
from thefuck.specific.git import git_support
|
||||
|
||||
|
||||
@git_support
|
||||
def match(command):
|
||||
return ('merge' in command.script
|
||||
and ' - not something we can merge' in command.output
|
||||
and 'Did you mean this?' in command.output)
|
||||
|
||||
|
||||
@git_support
|
||||
def get_new_command(command):
|
||||
unknown_branch = re.findall(r'merge: (.+) - not something we can merge', command.output)[0]
|
||||
remote_branch = re.findall(r'Did you mean this\?\n\t([^\n]+)', command.output)[0]
|
||||
|
||||
return replace_argument(command.script, unknown_branch, remote_branch)
|
Loading…
x
Reference in New Issue
Block a user