diff --git a/tests/rules/test_git_not_command.py b/tests/rules/test_git_not_command.py index 8a9740c54..bb3ed32c0 100644 --- a/tests/rules/test_git_not_command.py +++ b/tests/rules/test_git_not_command.py @@ -35,23 +35,40 @@ def git_not_command_closest(): ''' +@pytest.fixture +def git_not_command_uncommon(): + return "git: 'lock' is not a git command. See 'git --help'.\n\nThe most similar command is" + + @pytest.fixture def git_command(): return "* master" -def test_match(git_not_command, git_command, git_not_command_one_of_this): +def test_match(git_not_command, git_command, git_not_command_one_of_this, git_not_command_closest, git_not_command_uncommon): assert match(Command('git brnch', git_not_command)) assert match(Command('git st', git_not_command_one_of_this)) assert not match(Command('ls brnch', git_not_command)) assert not match(Command('git branch', git_command)) + assert match(Command('git lock', git_not_command_uncommon)) + assert match(Command('git lock --help', git_not_command_uncommon)) + + assert not match(Command('git branch foo', '')) + assert not match(Command('git checkout feature/test_commit', '')) + assert not match(Command('git push', '')) + def test_get_new_command(git_not_command, git_not_command_one_of_this, - git_not_command_closest): + git_not_command_closest, git_not_command_uncommon): assert (get_new_command(Command('git brnch', git_not_command)) == ['git branch']) assert (get_new_command(Command('git st', git_not_command_one_of_this)) == ['git stats', 'git stash', 'git stage']) assert (get_new_command(Command('git tags', git_not_command_closest)) == ['git tag', 'git stage']) + + assert (get_new_command(Command('git lock', git_not_command_uncommon)) + == ['git log']) + assert (get_new_command(Command('git lock --help', git_not_command_uncommon)) + == ['git log --help']) diff --git a/thefuck/rules/git_not_command.py b/thefuck/rules/git_not_command.py index fd2a1bd12..7146e7338 100644 --- a/thefuck/rules/git_not_command.py +++ b/thefuck/rules/git_not_command.py @@ -3,6 +3,14 @@ from thefuck.specific.git import git_support +COMMON_TYPOS = { + 'copy': ['branch'], + 'list': ['branch'], + 'lock': ['log'], + 'update': ['fetch', 'fetch --all', 'fetch --all --tags', 'remote update'], +} + + @git_support def match(command): return (" is not a git command. See 'git --help'." in command.output @@ -14,5 +22,6 @@ def match(command): def get_new_command(command): broken_cmd = re.findall(r"git: '([^']*)' is not a git command", command.output)[0] - matched = get_all_matched_commands(command.output, ['The most similar command', 'Did you mean']) + matched = COMMON_TYPOS.get(broken_cmd, []) + matched.extend(get_all_matched_commands(command.output, ['The most similar command', 'Did you mean'])) return replace_command(command, broken_cmd, matched)