mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-19 04:21:14 +00:00
Merge pull request #476 from scorphus/git-help-aliased
#N/A: Add new `git_help_aliased` rule
This commit is contained in:
commit
a47e84fa6b
@ -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 <alias>` commands replacing <alias> 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;
|
||||
|
24
tests/rules/test_git_help_aliased.py
Normal file
24
tests/rules/test_git_help_aliased.py
Normal file
@ -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
|
12
thefuck/rules/git_help_aliased.py
Normal file
12
thefuck/rules/git_help_aliased.py
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user