From 41707b80c61acadb7c87b0efcbf10f4186dc5937 Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Thu, 17 Mar 2016 23:25:03 -0300 Subject: [PATCH] #N/A: Fix `git_add` rule --- README.md | 2 +- tests/rules/test_git_add.py | 42 +++++++++++++++---------------------- thefuck/rules/git_add.py | 7 +++---- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 7e9e19d1..e8756e1c 100644 --- a/README.md +++ b/README.md @@ -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`; * `fix_alt_space` – replaces Alt+Space with Space character; * `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_list` – catches `git branch list` in place of `git branch` and removes created branch; * `git_checkout` – fixes branch name or creates new branch; diff --git a/tests/rules/test_git_add.py b/tests/rules/test_git_add.py index c5b7c251..18972b16 100644 --- a/tests/rules/test_git_add.py +++ b/tests/rules/test_git_add.py @@ -4,36 +4,28 @@ from tests.utils import Command @pytest.fixture -def did_not_match(target, did_you_forget=True): - error = ("error: pathspec '{}' did not match any " - "file(s) known to git.".format(target)) - if did_you_forget: - error = ("{}\nDid you forget to 'git add'?'".format(error)) - return error +def stderr(target): + return ("error: pathspec '{}' did not match any " + 'file(s) known to git.'.format(target)) -@pytest.mark.parametrize('command', [ - Command(script='git submodule update unknown', - stderr=did_not_match('unknown')), - Command(script='git commit unknown', - stderr=did_not_match('unknown'))]) # Older versions of Git -def test_match(command): - assert match(command) +@pytest.mark.parametrize('script, target', [ + ('git submodule update unknown', 'unknown'), + ('git commit unknown', 'unknown')]) +def test_match(stderr, script, target): + assert match(Command(script=script, stderr=stderr)) -@pytest.mark.parametrize('command', [ - Command(script='git submodule update known', stderr=('')), - Command(script='git commit known', stderr=('')), - Command(script='git commit unknown', # Newer versions of Git - stderr=did_not_match('unknown', False))]) -def test_not_match(command): - assert not match(command) +@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('command, new_command', [ - (Command('git submodule update unknown', stderr=did_not_match('unknown')), +@pytest.mark.parametrize('script, target, new_command', [ + ('git submodule update unknown', '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')]) -def test_get_new_command(command, new_command): - assert get_new_command(command) == new_command +def test_get_new_command(stderr, script, target, new_command): + assert get_new_command(Command(script=script, stderr=stderr)) == new_command diff --git a/thefuck/rules/git_add.py b/thefuck/rules/git_add.py index 0cf1b05a..a779a204 100644 --- a/thefuck/rules/git_add.py +++ b/thefuck/rules/git_add.py @@ -5,15 +5,14 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('did not match any file(s) known to git.' in command.stderr - and "Did you forget to 'git add'?" in command.stderr) + return 'did not match any file(s) known to git.' in command.stderr @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] + r"error: pathspec '([^']*)' " + r'did not match any file\(s\) known to git.', command.stderr)[0] formatme = shell.and_('git add -- {}', '{}') return formatme.format(missing_file, command.script)