Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Uncommon Typos #1429

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions tests/rules/test_git_not_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
11 changes: 10 additions & 1 deletion thefuck/rules/git_not_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)