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

v5 breaks the Git hook #1294

Closed
honzajavorek opened this issue Jul 7, 2020 · 5 comments
Closed

v5 breaks the Git hook #1294

honzajavorek opened this issue Jul 7, 2020 · 5 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@honzajavorek
Copy link

I upgraded to v5, my Git hook looks like this (the same as in README, I double checked now):

#!/usr/bin/env python
import sys
from isort.hooks import git_hook

sys.exit(git_hook(strict=True, modify=True))

I'm getting the following error:

$ git commit
error: unknown change class ' ' in --diff-filter=ACMRTUXB HEAD
Traceback (most recent call last):
  File ".git/hooks/pre-commit", line 5, in <module>
    sys.exit(git_hook(strict=True, modify=True))
  File "/Users/honza/.local/share/virtualenvs/project-kjnSj-Yq/lib/python3.7/site-packages/isort/hooks.py", line 51, in git_hook
    files_modified = get_lines(diff_cmd)
  File "/Users/honza/.local/share/virtualenvs/project-kjnSj-Yq/lib/python3.7/site-packages/isort/hooks.py", line 31, in get_lines
    stdout = get_output(command)
  File "/Users/honza/.local/share/virtualenvs/project-kjnSj-Yq/lib/python3.7/site-packages/isort/hooks.py", line 20, in get_output
    result = subprocess.run(command, stdout=subprocess.PIPE, check=True)  # nosec - trusted input
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 512, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['git', 'diff-index', '--cached', '--name-only', '--diff-filter=ACMRTUXB HEAD']' returned non-zero exit status 129.

Using: macOS Mojave (10.14.6), Homebrew, git 2.27.0, python 3.7.7 (I hope the hook won't get executed using the system python 2.7.16)

@honzajavorek
Copy link
Author

honzajavorek commented Jul 7, 2020

I confirmed #/usr/bin/env python leads to the 2.7 python installation, but even when I changed it to #!/usr/bin/env python3, which leads to the 3.7, the problem persists. When I run the command manually, it seems to work correctly:

$ git diff-index --cached --name-only --diff-filter=ACMRTUXB HEAD
.isort.cfg
tests/test_models_base.py

$ echo $?
0

I'm unsure what the git hook does exactly, I guess I need some guidance here to continue debugging or to provide a fix.

@honzajavorek
Copy link
Author

I figured out line 50 in hooks.py should get changed like this:

- diff_cmd = ["git", "diff-index", "--cached", "--name-only", "--diff-filter=ACMRTUXB HEAD"]
+ diff_cmd = ["git", "diff-index", "--cached", "--name-only", "--diff-filter=ACMRTUXB", "HEAD"]

However, the hook still doesn't work. It correctly passes on commiting .isort.cfg, but evaluates tests/test_models_base.py as unsorted (although it has been previously sorted by isort and that is the very reason why it's modified), sets errors to 1, and silently exits the hook with 1 as an exit status code. No print output, no modification made to the file.

@timothycrosley timothycrosley added bug Something isn't working help wanted Extra attention is needed labels Jul 8, 2020
@danaspiegel
Copy link

I'm seeing this too. (OS X 10.15.5, python 3.8.2, git 2.27.0). In addition, we use pyenv to ensure python versions are set properly on a per project basis and I just confirmed that its using the project specific python version.

This completely breaks isort for us. I've held isort back to <5 until fixed.

@timothycrosley
Copy link
Member

Thanks @honzajavorek and @danaspiegel for raising this!
I've started using the git hook, to hopefully identify any further issues before they become user impacting, and believe I have fixed this in the 5.0.8 release.

Thanks!

~Timothy

@honzajavorek
Copy link
Author

Awesome, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants