mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 20:38:54 +00:00
#N/A: Match git_add
only if pathspec exists
This commit is contained in:
parent
cae76eb55f
commit
4fe64e3dfa
@ -3,6 +3,12 @@ from thefuck.rules.git_add import match, get_new_command
|
|||||||
from tests.utils import 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
|
@pytest.fixture
|
||||||
def stderr(target):
|
def stderr(target):
|
||||||
return ("error: pathspec '{}' did not match any "
|
return ("error: pathspec '{}' did not match any "
|
||||||
@ -16,10 +22,13 @@ def test_match(stderr, script, target):
|
|||||||
assert match(Command(script=script, stderr=stderr))
|
assert match(Command(script=script, stderr=stderr))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('script', [
|
@pytest.mark.parametrize('script, target, exists', [
|
||||||
'git submodule update known', 'git commit known'])
|
('git submodule update known', '', True),
|
||||||
def test_not_match(script):
|
('git commit known', '', True),
|
||||||
assert not match(Command(script=script, stderr=''))
|
('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', [
|
@pytest.mark.parametrize('script, target, new_command', [
|
||||||
|
@ -1,18 +1,27 @@
|
|||||||
import re
|
import re
|
||||||
from thefuck.shells import shell
|
from thefuck.shells import shell
|
||||||
from thefuck.specific.git import git_support
|
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
|
@git_support
|
||||||
def match(command):
|
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
|
@git_support
|
||||||
def get_new_command(command):
|
def get_new_command(command):
|
||||||
missing_file = re.findall(
|
missing_file = _get_missing_file(command)
|
||||||
r"error: pathspec '([^']*)' "
|
|
||||||
r'did not match any file\(s\) known to git.', command.stderr)[0]
|
|
||||||
|
|
||||||
formatme = shell.and_('git add -- {}', '{}')
|
formatme = shell.and_('git add -- {}', '{}')
|
||||||
return formatme.format(missing_file, command.script)
|
return formatme.format(missing_file, command.script)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user