Skip to content

Commit

Permalink
Fixed #1294: bundled git hook broken in V5.
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Jul 11, 2020
1 parent c7ea8ec commit c548602
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@ NOTE: isort follows the [semver](https://semver.org/) versioning standard.

### 5.0.8 July 11, 2020
- Fixed #1277 & #1278: New line detection issues on Windows.
- Fixed #1294: Fix bundled git hook.

### 5.0.7 July 9, 2020
- Fixed #1306: unexpected --diff behavior.
Expand Down
12 changes: 5 additions & 7 deletions isort/hooks.py
Expand Up @@ -47,21 +47,19 @@ def git_hook(strict: bool = False, modify: bool = False) -> int:
"""

# Get list of files modified and staged
diff_cmd = ["git", "diff-index", "--cached", "--name-only", "--diff-filter=ACMRTUXB HEAD"]
diff_cmd = ["git", "diff-index", "--cached", "--name-only", "--diff-filter=ACMRTUXB", "HEAD"]
files_modified = get_lines(diff_cmd)

errors = 0
for filename in files_modified:
if filename.endswith(".py"):
# Get the staged contents of the file
staged_cmd = ["git", "show", ":%s" % filename]
staged_cmd = ["git", "show", f":{filename}"]
staged_contents = get_output(staged_cmd)

if not (
api.sort_file(filename)
if modify
else api.check_code_string(staged_contents, file_path=Path(filename))
):
if not api.check_code_string(staged_contents, file_path=Path(filename)):
errors += 1
if modify:
api.sort_file(filename)

return errors if strict else 0

0 comments on commit c548602

Please sign in to comment.