From e7b377a3105d1b3d59e5e8b4882a325b9909fe21 Mon Sep 17 00:00:00 2001 From: nvbn Date: Wed, 8 Apr 2015 21:20:11 +0200 Subject: [PATCH] Add handler for "is not a git command" --- README.md | 9 +++++++++ setup.py | 2 +- tests/rules/test_git_not_command.py | 28 ++++++++++++++++++++++++++++ thefuck/rules/git_not_command.py | 16 ++++++++++++++++ thefuck/rules/no_command.py | 2 +- 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 tests/rules/test_git_not_command.py create mode 100644 thefuck/rules/git_not_command.py diff --git a/README.md b/README.md index 91120906..b597ad33 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,15 @@ zsh: command not found: puthon ➜ fuck Python 3.4.2 (default, Oct 8 2014, 13:08:17) ... + +➜ git brnch +git: 'brnch' is not a git command. See 'git --help'. + +Did you mean this? + branch + +➜ fuck +* master ``` ## Installation diff --git a/setup.py b/setup.py index 1e40a3fc..a95ba457 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup(name='thefuck', - version=1.2, + version=1.3, description="Magnificent app which corrects your previous console command", author='Vladimir Iakovlev', author_email='nvbn.rm@gmail.com', diff --git a/tests/rules/test_git_not_command.py b/tests/rules/test_git_not_command.py new file mode 100644 index 00000000..71b1012d --- /dev/null +++ b/tests/rules/test_git_not_command.py @@ -0,0 +1,28 @@ +import pytest +from thefuck.main import Command +from thefuck.rules.git_not_command import match, get_new_command + + +@pytest.fixture +def git_not_command(): + return """git: 'brnch' is not a git command. See 'git --help'. + +Did you mean this? +branch +""" + + +@pytest.fixture +def git_command(): + return "* master" + + +def test_match(git_not_command, git_command): + assert match(Command('git brnch', '', git_not_command), None) + assert not match(Command('ls brnch', '', git_not_command), None) + assert not match(Command('git branch', '', git_command), None) + + +def test_get_new_command(git_not_command): + assert get_new_command(Command('git brnch', '', git_not_command), None)\ + == 'git branch' diff --git a/thefuck/rules/git_not_command.py b/thefuck/rules/git_not_command.py new file mode 100644 index 00000000..ba7aced7 --- /dev/null +++ b/thefuck/rules/git_not_command.py @@ -0,0 +1,16 @@ +import re + + +def match(command, settings): + return ('git' in command.script + and " is not a git command. See 'git --help'." in command.stderr + and 'Did you mean this?' in command.stderr) + + +def get_new_command(command, settings): + broken_cmd = re.findall(r"git: '([^']*)' is not a git command", + command.stderr)[0] + new_cmd = re.findall(r'Did you mean this\?\n\s*([^\n]*)', + command.stderr)[0] + return command.script.replace(broken_cmd, new_cmd, 1) + diff --git a/thefuck/rules/no_command.py b/thefuck/rules/no_command.py index 6e2bb361..122dbd6f 100644 --- a/thefuck/rules/no_command.py +++ b/thefuck/rules/no_command.py @@ -22,4 +22,4 @@ def get_new_command(command, settings): output)[0] fixed_name = re.findall(r"Command '([^']*)' from package", output)[0] - return command.script.replace(broken_name, fixed_name) + return command.script.replace(broken_name, fixed_name, 1)