1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-02-20 20:09:07 +00:00

#N/A: Match git_add only if pathspec exists

This commit is contained in:
Vladimir Iakovlev 2016-08-23 13:03:49 +03:00
parent cae76eb55f
commit 4fe64e3dfa
2 changed files with 27 additions and 9 deletions

View File

@ -3,6 +3,12 @@ from thefuck.rules.git_add import match, get_new_command
from tests.utils import Command
@pytest.fixture(autouse=True)
def path_exists(mocker):
return mocker.patch('thefuck.rules.git_add.Path.exists',
return_value=True)
@pytest.fixture
def stderr(target):
return ("error: pathspec '{}' did not match any "
@ -16,10 +22,13 @@ def test_match(stderr, script, target):
assert match(Command(script=script, stderr=stderr))
@pytest.mark.parametrize('script', [
'git submodule update known', 'git commit known'])
def test_not_match(script):
assert not match(Command(script=script, stderr=''))
@pytest.mark.parametrize('script, target, exists', [
('git submodule update known', '', True),
('git commit known', '', True),
('git submodule update known', stderr, False)])
def test_not_match(path_exists, stderr, script, target, exists):
path_exists.return_value = exists
assert not match(Command(script=script, stderr=stderr))
@pytest.mark.parametrize('script, target, new_command', [

View File

@ -1,18 +1,27 @@
import re
from thefuck.shells import shell
from thefuck.specific.git import git_support
from thefuck.system import Path
from thefuck.utils import memoize
@memoize
def _get_missing_file(command):
pathspec = re.findall(
r"error: pathspec '([^']*)' "
r'did not match any file\(s\) known to git.', command.stderr)[0]
if Path(pathspec).exists():
return pathspec
@git_support
def match(command):
return 'did not match any file(s) known to git.' in command.stderr
return ('did not match any file(s) known to git.' in command.stderr
and _get_missing_file(command))
@git_support
def get_new_command(command):
missing_file = re.findall(
r"error: pathspec '([^']*)' "
r'did not match any file\(s\) known to git.', command.stderr)[0]
missing_file = _get_missing_file(command)
formatme = shell.and_('git add -- {}', '{}')
return formatme.format(missing_file, command.script)