From 15e13d7c1a3b5733c84139e89b09d105bb70de93 Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Fri, 29 May 2015 18:38:01 -0300 Subject: [PATCH] add(rule): add the new git_diff_staged rule --- README.md | 1 + tests/rules/test_git_diff_staged.py | 27 +++++++++++++++++++++++++++ thefuck/rules/git_diff_staged.py | 6 ++++++ 3 files changed, 34 insertions(+) create mode 100644 tests/rules/test_git_diff_staged.py create mode 100644 thefuck/rules/git_diff_staged.py diff --git a/README.md b/README.md index 742ae9cf..06d8f18b 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 00000000..93fe2536 --- /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 00000000..32e5dcbb --- /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)