diff --git a/README.md b/README.md index 742ae9c..06d8f18 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `java` – removes `.java` extension when running Java programs; * `git_add` – fix *"Did you forget to 'git add'?"*; * `git_checkout` – creates the branch before checking-out; +* `git_diff_staged` – adds `--staged` to previous `git diff` with unexpected output; * `git_no_command` – fixes wrong git commands like `git brnch`; * `git_pull` – sets upstream before executing previous `git pull`; * `git_push` – adds `--set-upstream origin $branch` to previous failed `git push`; diff --git a/tests/rules/test_git_diff_staged.py b/tests/rules/test_git_diff_staged.py new file mode 100644 index 0000000..93fe253 --- /dev/null +++ b/tests/rules/test_git_diff_staged.py @@ -0,0 +1,27 @@ +import pytest +from thefuck.rules.git_diff_staged import match, get_new_command +from tests.utils import Command + + +@pytest.mark.parametrize('command', [ + Command(script='git diff'), + Command(script='git df'), + Command(script='git ds')]) +def test_match(command): + assert match(command, None) + + +@pytest.mark.parametrize('command', [ + Command(script='git tag'), + Command(script='git branch'), + Command(script='git log')]) +def test_not_match(command): + assert not match(command, None) + + +@pytest.mark.parametrize('command, new_command', [ + (Command('git diff'), 'git diff --staged'), + (Command('git df'), 'git df --staged'), + (Command('git ds'), 'git ds --staged')]) +def test_get_new_command(command, new_command): + assert get_new_command(command, None) == new_command diff --git a/thefuck/rules/git_diff_staged.py b/thefuck/rules/git_diff_staged.py new file mode 100644 index 0000000..32e5dcb --- /dev/null +++ b/thefuck/rules/git_diff_staged.py @@ -0,0 +1,6 @@ +def match(command, settings): + return command.script.startswith('git d') + + +def get_new_command(command, settings): + return '{} --staged'.format(command.script)