diff --git a/CHANGELOG.md b/CHANGELOG.md index 27cb7533a..984159e18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/isort/hooks.py b/isort/hooks.py index 07b92f898..8eabda560 100644 --- a/isort/hooks.py +++ b/isort/hooks.py @@ -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