mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 20:38:54 +00:00
#N/A: Fix git_add
rule
This commit is contained in:
parent
3a39deb485
commit
41707b80c6
@ -155,7 +155,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
|
|||||||
* `dry` – fixes repetitions like `git git push`;
|
* `dry` – fixes repetitions like `git git push`;
|
||||||
* `fix_alt_space` – replaces Alt+Space with Space character;
|
* `fix_alt_space` – replaces Alt+Space with Space character;
|
||||||
* `fix_file` – opens a file with an error in your `$EDITOR`;
|
* `fix_file` – opens a file with an error in your `$EDITOR`;
|
||||||
* `git_add` – fixes *"Did you forget to 'git add'?"*;
|
* `git_add` – fixes *"pathspec 'foo' did not match any file(s) known to git."*;
|
||||||
* `git_branch_delete` – changes `git branch -d` to `git branch -D`;
|
* `git_branch_delete` – changes `git branch -d` to `git branch -D`;
|
||||||
* `git_branch_list` – catches `git branch list` in place of `git branch` and removes created branch;
|
* `git_branch_list` – catches `git branch list` in place of `git branch` and removes created branch;
|
||||||
* `git_checkout` – fixes branch name or creates new branch;
|
* `git_checkout` – fixes branch name or creates new branch;
|
||||||
|
@ -4,36 +4,28 @@ from tests.utils import Command
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def did_not_match(target, did_you_forget=True):
|
def stderr(target):
|
||||||
error = ("error: pathspec '{}' did not match any "
|
return ("error: pathspec '{}' did not match any "
|
||||||
"file(s) known to git.".format(target))
|
'file(s) known to git.'.format(target))
|
||||||
if did_you_forget:
|
|
||||||
error = ("{}\nDid you forget to 'git add'?'".format(error))
|
|
||||||
return error
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('command', [
|
@pytest.mark.parametrize('script, target', [
|
||||||
Command(script='git submodule update unknown',
|
('git submodule update unknown', 'unknown'),
|
||||||
stderr=did_not_match('unknown')),
|
('git commit unknown', 'unknown')])
|
||||||
Command(script='git commit unknown',
|
def test_match(stderr, script, target):
|
||||||
stderr=did_not_match('unknown'))]) # Older versions of Git
|
assert match(Command(script=script, stderr=stderr))
|
||||||
def test_match(command):
|
|
||||||
assert match(command)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('command', [
|
@pytest.mark.parametrize('script', [
|
||||||
Command(script='git submodule update known', stderr=('')),
|
'git submodule update known', 'git commit known'])
|
||||||
Command(script='git commit known', stderr=('')),
|
def test_not_match(script):
|
||||||
Command(script='git commit unknown', # Newer versions of Git
|
assert not match(Command(script=script, stderr=''))
|
||||||
stderr=did_not_match('unknown', False))])
|
|
||||||
def test_not_match(command):
|
|
||||||
assert not match(command)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('command, new_command', [
|
@pytest.mark.parametrize('script, target, new_command', [
|
||||||
(Command('git submodule update unknown', stderr=did_not_match('unknown')),
|
('git submodule update unknown', 'unknown',
|
||||||
'git add -- unknown && git submodule update unknown'),
|
'git add -- unknown && git submodule update unknown'),
|
||||||
(Command('git commit unknown', stderr=did_not_match('unknown')), # Old Git
|
('git commit unknown', 'unknown',
|
||||||
'git add -- unknown && git commit unknown')])
|
'git add -- unknown && git commit unknown')])
|
||||||
def test_get_new_command(command, new_command):
|
def test_get_new_command(stderr, script, target, new_command):
|
||||||
assert get_new_command(command) == new_command
|
assert get_new_command(Command(script=script, stderr=stderr)) == new_command
|
||||||
|
@ -5,15 +5,14 @@ from thefuck.specific.git import git_support
|
|||||||
|
|
||||||
@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 "Did you forget to 'git add'?" in command.stderr)
|
|
||||||
|
|
||||||
|
|
||||||
@git_support
|
@git_support
|
||||||
def get_new_command(command):
|
def get_new_command(command):
|
||||||
missing_file = re.findall(
|
missing_file = re.findall(
|
||||||
r"error: pathspec '([^']*)' "
|
r"error: pathspec '([^']*)' "
|
||||||
r"did not match any file\(s\) known to git.", command.stderr)[0]
|
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