Skip to content
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
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ jobs:
run: |
pip install -Ur requirements.txt coveralls
python setup.py develop
- name: Diagnose lint checkout
run: |
git rev-parse HEAD
git status --short --untracked-files=all
git ls-files -- thefuck/rules/git_direct_commit.py tests/rules/test_edit_filename.py
find . -name git_direct_commit.py -o -name test_edit_filename.py
nl -ba tests/rules/test_edit_filename.py | sed -n '1,16p'
- name: Lint
if: matrix.os == 'ubuntu-22.04' && matrix.python-version == env.PYTHON_LATEST
run: flake8
Expand Down
5 changes: 3 additions & 2 deletions fastentrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def get_args(cls, dist, header=None):
if re.search(r'[\\/]', name):
raise ValueError("Path separators not allowed in script names")
script_text = TEMPLATE.format(
ep.module_name, ep.attrs[0], '.'.join(ep.attrs),
spec, group, name)
ep.module_name, ep.attrs[0], '.'.join(ep.attrs),
spec, group, name)
args = cls._get_script_args(type_, name, header, script_text)
for res in args:
yield res
Expand Down Expand Up @@ -107,4 +107,5 @@ def main():
setup.truncate()
setup.write('import fastentrypoints\n' + setup_content)


print(__name__)
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from setuptools import setup, find_packages
import sys
import os
import fastentrypoints


try:
Expand Down Expand Up @@ -48,13 +47,13 @@
if sys.platform == "win32":
scripts = ['scripts\\fuck.bat', 'scripts\\fuck.ps1']
entry_points = {'console_scripts': [
'thefuck = thefuck.entrypoints.main:main',
'thefuck_firstuse = thefuck.entrypoints.not_configured:main']}
'thefuck = thefuck.entrypoints.main:main',
'thefuck_firstuse = thefuck.entrypoints.not_configured:main']}
else:
scripts = []
entry_points = {'console_scripts': [
'thefuck = thefuck.entrypoints.main:main',
'fuck = thefuck.entrypoints.not_configured:main']}
'thefuck = thefuck.entrypoints.main:main',
'fuck = thefuck.entrypoints.not_configured:main']}

setup(name='zhifei',
version=VERSION,
Expand Down
3 changes: 1 addition & 2 deletions tests/rules/test_edit_filename.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

import pytest
import os

from thefuck.rules.edit_filename import EDITORS, get_new_command, match
from thefuck.types import Command
Expand Down
14 changes: 13 additions & 1 deletion tests/rules/test_git_not_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ def git_command():
return "* master"


@pytest.fixture
def git_comit_error():
return """git: 'comit' is not a git command. See 'git --help'.

The most similar command is
commit
"""


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))
Expand All @@ -60,7 +69,7 @@ def test_match(git_not_command, git_command, git_not_command_one_of_this, git_no


def test_get_new_command(git_not_command, git_not_command_one_of_this,
git_not_command_closest, git_not_command_uncommon):
git_not_command_closest, git_not_command_uncommon, git_comit_error):
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))
Expand All @@ -72,3 +81,6 @@ def test_get_new_command(git_not_command, git_not_command_one_of_this,
== ['git log'])
assert (get_new_command(Command('git lock --help', git_not_command_uncommon))
== ['git log --help'])

assert (get_new_command(Command('git comit', git_comit_error))
== ['git commit'])
15 changes: 9 additions & 6 deletions tests/rules/test_upper_to_lower_case.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Absorbed from upstream #1297 (author nkakonas); the original test used
# `cd`, which is a shell builtin and not in get_all_executables().
import os

import pytest

Expand All @@ -15,11 +14,15 @@
("LS -A", "command not found"),
],
)
# Windows runners have neither a `ls` executable on PATH nor the POSIX
# "command not found" message, so the positive-match cases can't hold there.
@pytest.mark.skipif(os.name == 'nt',
reason='POSIX-only error message and PATH layout')
def test_match(script, output):
def test_match(script, output, monkeypatch):
monkeypatch.setattr(
"thefuck.rules.upper_to_lower_case.which",
lambda command: None,
)
monkeypatch.setattr(
"thefuck.rules.upper_to_lower_case.get_all_executables",
lambda: ["ls"],
)
assert match(Command(script, output))


Expand Down
2 changes: 1 addition & 1 deletion tests/rules/test_yarn_command_not_found.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

Run `yarn help COMMAND` for more information on specific commands.
Visit https://yarnpkg.com/en/docs/cli/ to learn more about Yarn.
''' # noqa
''' # noqa


@pytest.fixture(autouse=True)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_system_win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import pytest

win_unicode_console = pytest.importorskip('win_unicode_console')
import colorama # noqa: E402
from thefuck.system.win32 import init_output # noqa: E402

import colorama # noqa: E402, E261
from thefuck.system.win32 import init_output # noqa: E402, E261


class TestInitOutputWarningSuppression:
Expand Down
16 changes: 16 additions & 0 deletions thefuck/fix_git_and_command_misspell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from difflib import get_close_matches


def fix_git_command(git_command):
git_possible = ['clone', 'init', 'add', 'mv', 'reset', 'rm', 'bisect',
'grep', 'log', 'show', 'status', 'branch', 'checkout',
'commit', 'diff', 'merge', 'rebase', 'tag', 'fetch',
'pull', 'push']
if git_command not in git_possible[0]:
close_match = get_close_matches(git_command, git_possible)
if len(close_match) > 0:
return close_match[0]
else:
return git_command
else:
return git_command
11 changes: 8 additions & 3 deletions thefuck/rules/git_direct_commit.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Absorbed from upstream #1311 (author nkakonas): the user tried to commit
# without staging anything first; suggest `git add --all` before committing.
def match(command):
return 'git commit ' in command.script and ('Untracked files' in command.output
or '''use "git add"''' in command.output or 'Changes not staged for commit'
in command.output)
return (
'git commit ' in command.script
and (
'Untracked files' in command.output
or 'use "git add"' in command.output
or 'Changes not staged for commit' in command.output
)
)


def get_new_command(command):
Expand Down
8 changes: 1 addition & 7 deletions thefuck/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def _safe(fn, fallback):
return fallback

cache_path = _get_executables_cache_path()
# Respect the test-suite cache switch so tests always scan PATH.
use_cache = not cache.disabled
if use_cache:
try:
Expand All @@ -156,12 +155,7 @@ def _safe(fn, fallback):
pass

tf_alias = get_alias()
try:
from . import const as _const
tf_entry_points = (['thefuck', tf_alias]
+ list(_const.DEFAULT_EXTRA_ALIASES))
except Exception:
tf_entry_points = ['thefuck', tf_alias]
tf_entry_points = ['thefuck', 'fuck']

bins = [exe.name.decode('utf8') if six.PY2 else exe.name
for path in os.environ.get('PATH', '').split(os.pathsep)
Expand Down
Loading