diff --git a/README.md b/README.md index 534955d..b2f169c 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `fix_alt_space` – replaces Alt+Space with Space character; * `fix_file` – opens a file with an error in your `$EDITOR`; * `git_add` – fixes *"pathspec 'foo' did not match any file(s) known to git."*; +* `git_bisect_usage` – fixes `git bisect strt`, `git bisect goood`, `git bisect rset`, etc. when bisecting; * `git_branch_delete` – changes `git branch -d` to `git branch -D`; * `git_branch_exists` – offers `git branch -d foo`, `git branch -D foo` or `git checkout foo` when creating a branch that already exists; * `git_branch_list` – catches `git branch list` in place of `git branch` and removes created branch; diff --git a/tests/rules/test_git_bisect_usage.py b/tests/rules/test_git_bisect_usage.py new file mode 100644 index 0000000..c4f8828 --- /dev/null +++ b/tests/rules/test_git_bisect_usage.py @@ -0,0 +1,30 @@ +import pytest +from tests.utils import Command +from thefuck.rules.git_bisect_usage import match, get_new_command + + +@pytest.fixture +def stderr(): + return ("usage: git bisect [help|start|bad|good|new|old" + "|terms|skip|next|reset|visualize|replay|log|run]") + + +@pytest.mark.parametrize('script', [ + 'git bisect strt', 'git bisect rset', 'git bisect goood']) +def test_match(stderr, script): + assert match(Command(script=script, stderr=stderr)) + + +@pytest.mark.parametrize('script', [ + 'git bisect', 'git bisect start', 'git bisect good']) +def test_not_match(script): + assert not match(Command(script=script, stderr='')) + + +@pytest.mark.parametrize('script, new_cmd, ', [ + ('git bisect goood', ['good', 'old', 'log']), + ('git bisect strt', ['start', 'terms', 'reset']), + ('git bisect rset', ['reset', 'next', 'start'])]) +def test_get_new_command(stderr, script, new_cmd): + new_cmd = ['git bisect %s' % cmd for cmd in new_cmd] + assert get_new_command(Command(script=script, stderr=stderr)) == new_cmd diff --git a/thefuck/rules/git_bisect_usage.py b/thefuck/rules/git_bisect_usage.py new file mode 100644 index 0000000..2503e3c --- /dev/null +++ b/thefuck/rules/git_bisect_usage.py @@ -0,0 +1,16 @@ +import re +from thefuck.utils import replace_command +from thefuck.specific.git import git_support + + +@git_support +def match(command): + return ('bisect' in command.script_parts and + 'usage: git bisect' in command.stderr) + + +@git_support +def get_new_command(command): + broken = re.findall(r'git bisect ([^ $]*).*', command.script)[0] + usage = re.findall(r'usage: git bisect \[([^\]]+)\]', command.stderr)[0] + return replace_command(command, broken, usage.split('|'))