Skip to content

✨ [nox] Support patching pre-commit hooks written in bash#718

Merged
cjolowicz merged 21 commits intomainfrom
ci/support-pre-commit-bash-hooks
Dec 1, 2021
Merged

✨ [nox] Support patching pre-commit hooks written in bash#718
cjolowicz merged 21 commits intomainfrom
ci/support-pre-commit-bash-hooks

Conversation

@cjolowicz
Copy link
Copy Markdown
Owner

@cjolowicz cjolowicz commented Dec 1, 2021

pre-commit 2.16.0 switched from Python to bash in the hooks installed to .git/hooks. We're patching hook scripts to activate the virtualenv for the pre-commit Nox session. This PR teaches the Nox session to detect bash hooks. The inserted fragment for virtualenv activation was ported to bash.

This PR also fixes a potential crash when files in the hook directory cannot be opened using the default text encoding. We're now checking that the binary file contents start with the shebang sequence #! before attempting to decode the contents. That should at least deal with binaries. Scripts with random garbage will still cause the hook installation to crash.

  • 🔨 Split conditional
  • 🔨 Replace if not continue with if
  • ✨ Add bash version
  • 🔨 Add comments with pre-commit version ranges
  • 🔨 Extract variable patches
  • 🔨 Move bash fragment into patches
  • 🔨 Slide comments
  • 🔨 Replace if...elif with for...if...break loop over patches
  • 🔨 Do not duplicate patches keys
  • 🔨 Inline variable header
  • 🔨 Rename variable patches to headers
  • 🔨 Rename variable patch to header
  • 🔨 Support multiple languages when checking for bindir
  • ✨ Support bash when checking for bindir
  • 🔨 Slide bindirs before loop
  • 🐛 Fix over-aggressive quote removal for bindir in bash hooks
  • 🔨 Inline variable bindirs into bindirs
  • 💡 Expand comment
  • 🔨 Slide headers before loop
  • 🔨 Replace lines[0].startswith with hook.read_bytes().startswith
  • 🐛 Do not attempt to decode hooks unless they have a shebang

@cjolowicz cjolowicz added the enhancement New feature or request label Dec 1, 2021
@cjolowicz cjolowicz merged commit b2a958a into main Dec 1, 2021
@cjolowicz cjolowicz deleted the ci/support-pre-commit-bash-hooks branch December 1, 2021 07:13
@cjolowicz
Copy link
Copy Markdown
Owner Author

The patched hooks have an issue on Git Bash for Windows, where the path separator ; is not properly quoted.

This issue is fixed by #721.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant