diff --git a/README.md b/README.md index 0a1eedd4..e8e4cb14 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `git_checkout` – fixes branch name or creates new branch; * `git_diff_staged` – adds `--staged` to previous `git diff` with unexpected output; * `git_fix_stash` – fixes `git stash` commands (misspelled subcommand and missing `save`); +* `git_help_aliased` – fixes `git help ` commands replacing with the aliased command; * `git_not_command` – fixes wrong git commands like `git brnch`; * `git_pull` – sets upstream before executing previous `git pull`; * `git_pull_clone` – clones instead of pulling when the repo does not exist; diff --git a/tests/rules/test_git_help_aliased.py b/tests/rules/test_git_help_aliased.py new file mode 100644 index 00000000..ef33a112 --- /dev/null +++ b/tests/rules/test_git_help_aliased.py @@ -0,0 +1,24 @@ +import pytest +from thefuck.rules.git_help_aliased import match, get_new_command +from tests.utils import Command + + +@pytest.mark.parametrize('script, stdout', [ + ('git help st', "`git st' is aliased to `status'"), + ('git help ds', "`git ds' is aliased to `diff --staged'")]) +def test_match(script, stdout): + assert match(Command(script=script, stdout=stdout)) + + +@pytest.mark.parametrize('script, stdout', [ + ('git help status', "GIT-STATUS(1)...Git Manual...GIT-STATUS(1)"), + ('git help diff', "GIT-DIFF(1)...Git Manual...GIT-DIFF(1)")]) +def test_not_match(script, stdout): + assert not match(Command(script=script, stdout=stdout)) + + +@pytest.mark.parametrize('script, stdout, new_command', [ + ('git help st', "`git st' is aliased to `status'", 'git help status'), + ('git help ds', "`git ds' is aliased to `diff --staged'", 'git help diff')]) +def test_get_new_command(script, stdout, new_command): + assert get_new_command(Command(script=script, stdout=stdout)) == new_command diff --git a/thefuck/rules/git_help_aliased.py b/thefuck/rules/git_help_aliased.py new file mode 100644 index 00000000..d4103029 --- /dev/null +++ b/thefuck/rules/git_help_aliased.py @@ -0,0 +1,12 @@ +from thefuck.specific.git import git_support + + +@git_support +def match(command): + return 'help' in command.script and ' is aliased to ' in command.stdout + + +@git_support +def get_new_command(command): + aliased = command.stdout.split('`', 2)[2].split("'", 1)[0].split(' ', 1)[0] + return 'git help {}'.format(aliased)