Repository navigation
Read .overcommit.yml as UTF-8 in the hook template - #910
Merged
Merged
Conversation
The hook template reads .overcommit.yml with File.read and no encoding, so the string takes Encoding.default_external. Under a non-UTF-8 locale (for example LANG=C, as used by some GUI git clients) that is US-ASCII, and matching the gemfile regex against a file containing any non-ASCII character, even in a comment, raises "invalid byte sequence in US-ASCII" and every git hook fails. Pass encoding: 'UTF-8' in all hook copies, which the template directory spec requires to be identical, and add a spec that runs a hook with LC_ALL=C against a non-ASCII .overcommit.yml.
Run the installed pre-commit hook in an initialized temporary repository with an explicit US-ASCII external encoding. Require a successful exit and output from the configured AuthorName check so unrelated startup failures and disabled hooks cannot satisfy the regression test.
Owner
|
Thanks! |
sds
added a commit
that referenced
this pull request
Nov 5, 2026
Windows CI has been disabled since #836. Restore the full test matrix on Windows for every supported Ruby (2.6–4.0), alongside Linux, and remove the Windows and AppVeyor exclusions from the specs. Give the slower Windows jobs 30 minutes to complete the integration suite while retaining the 15-minute Linux limit. Both platforms now run the same 1,679 examples; no examples are removed or newly skipped. The restored matrix exposed two production failures: - Reading merge state with `File.open(...).read` leaves handles open until garbage collection, preventing Windows from deleting `MERGE_MODE`. Use `File.read` so the handles close immediately. Also close readers and temporary files in the Gerrit specs, and retain commit-message fixtures until each example finishes, to prevent Windows finalizer errors. - Parent-command detection depends on WMIC, which is unavailable on current Windows runners. Query `Win32_Process` through PowerShell's `Get-CimInstance`, preserving the `nil` fallback when the command cannot launch or the parent has exited. Use Ruby's native symlink APIs on Windows instead of invoking `mklink` and parsing `dir` output. This supports directory links, raises on creation failures, and lets the restored specs exercise real symlinks with `core.symlinks=true`. Ten additional examples cover files, directories, missing targets, spaces, and creation errors. Repair the parallelism regression spec: its previous built-in hook ignored the configured sleep command. An ad hoc serial hook now actually sleeps and writes a marker; the spec requires a successful commit and verifies the marker. Allow 30 seconds for Git and interpreter startup on slower Windows runners instead of the flaky five-second deadline. Two additional examples cover unavailable Windows process information. Validation: - Local Ruby 3.4.7: full suite with 1,679 examples and zero failures; the strengthened parallelism example and all 52 commit-message context examples also pass independently. - [Tests](https://github.com/sds/overcommit/actions/runs/41940143707): all 16 Linux/Windows jobs pass, each with 1,679 examples, zero failures, and zero pending examples. All Windows logs are free of tempfile finalizer errors. - [Lint](https://github.com/sds/overcommit/actions/runs/41940143568), coverage finalization, and all 16 Coveralls statuses pass. All 34 PR checks are green on `03e86dc5`. Refs #836 and #910.
sds
added a commit
to guillaume-d/overcommit
that referenced
this pull request
Nov 10, 2026
* origin/main: (108 commits) Remember all previously approved configurations and hooks (sds#665) Keep deleted and renamed paths absent while stashing changes (sds#928) Document the case-sensitive KtLint hook name (sds#927) Update CI actions and pin Ubuntu to clear annotations (sds#926) Preserve standard input bytes when forwarding hooks (sds#925) Preserve Git-quoted filenames when running all hooks (sds#924) Fail when Git cannot enumerate tracked files (sds#923) Add note about disabling default hooks (sds#922) Close files inspected by LineEndings (sds#921) Use Script Host before PowerShell for Windows parent query fallback (sds#920) Cache Windows dependency resolution with daily refreshes (sds#919) Avoid PowerShell startup for Windows parent command queries (sds#918) Avoid repeated CLI startup when preparing integration fixtures (sds#917) Allocate more CI runners to Windows with asymmetric sharding (sds#916) Shard CI tests across runners and add one required CI check (sds#915) Remove EOL Ruby versions from the CI matrix (sds#914) Cut CI test time by 68% while preserving the full test matrix (sds#913) Cut version 0.75.0 (sds#912) Re-enable the full Windows test matrix and fix platform failures (sds#911) Read .overcommit.yml as UTF-8 in the hook template (sds#910) Update Overcommit logo (sds#907) Cut version 0.74.0 (sds#906) Keep each worktree's signatures separate (sds#903) Recognize amend aliases on macOS (sds#904) Exclude files deleted from the working tree from all_files (sds#905) Restore the Ruby 2.6-3.1 test checks (sds#902) Delete subprocess output tempfiles once they are read (sds#901) Stop wrapping commands in cmd.exe on Windows (sds#898) Allow URL-only lines to exceed TextWidth body limit (sds#900) Cut version 0.73.0 (sds#896) Add automated release flow (sds#895) Instruct oxfmt not to fail if no files are matched (sds#894) Add filetypes to oxc tools (sds#893) Add pre commit hook for herb-lint (sds#892) Cut version 0.72.0 (sds#891) Remove maintainability badge (sds#890) Require patched REXML version (sds#889) Fix operation state restoration in linked worktrees (sds#887) Fail Flay hook when flay crashes instead of silently passing (sds#885) Fix Solargraph regexp capture warning (sds#886) Cut version 0.71.0 (sds#883) Prepare for the new solargraph typecheck format (sds#873) Make hook context input reads thread-safe (sds#882) Cut version 0.70.0 (sds#880) Add oxc pre-commit hooks (sds#879) Add Ruby 3.4 and 4.0 to CI matrix (sds#878) Cut version 0.69.0 (sds#877) Use Etc.nprocessors and handle sandboxed environments (sds#876) Cut version 0.68.0 (sds#872) Add solargraph pre-commit hook for typechecking (sds#871) Update RuboCop in Gemfile to silence a deprecation warning in build (sds#870) Cut version 0.67.1 adds 'set' requirements to diff hook context. (sds#866) Add note about unsupported YAML features in `gemfile:` line in default.yml (sds#865) Cut version 0.67.0 (sds#864) Restore ability to specify "gemfile: false" in config (sds#863) Cut version 0.66.0 (sds#861) Add `-diff` cli option for running precommit hooks against diffs (sds#860) Cut version 0.65.0 Load bundled gems on expected version (sds#859) Update changelog Bump rexml to >= 3.3.9 to resolve GHSA-2rxp-v6pw-ch6m (sds#857) Expand tildes(~) for hooksPath (sds#853) Fix spec compatibility with recent git versions (sds#854) Update changelog Cut version 0.64.0 (sds#852) Add changelog_uri to gemspec (sds#851) Support stylelint 16+, which emits messages on stderr (sds#848) Add Ruby 3.3 to CI matrix (sds#849) Update README with latest requirements (sds#845) Fix README badges (sds#844) Cut version 0.63.0 (sds#843) Add RSpec Hook to PreCommit, Add Applicable files if set (sds#842) Fix RuboCop warnings (sds#841) [FEATURE] New pre-commit hook: Sorbet (Issue sds#825) (sds#826) Green CI PoC (sds#833) Revert "Get suite running smoothly again (sds#824)" (sds#840) Get suite running smoothly again (sds#824) Cut version 0.62.0 (sds#821) Allow childprocess 5 (sds#820) Update branch for CI from `master` to `main` (sds#819) Update RuboCop (sds#818) Adding Ruby 3.2 to test matrix (sds#816) Cut version 0.61.0 (sds#817) fix: local overcommit file merges with existing .overcommit.yml file (sds#815) Allow ReplaceBranch to use skip_if (sds#809) Cut version 0.60.0 (sds#807) Add non ASCII encoding schema support to RailsSchemaUpToDate hook (sds#786) Rescue Psych::DisallowedClass in YamlSyntax (sds#805) Add optional additional local configuration (sds#799) Add MixTest hook (sds#802) Add MixFormat hook (sds#801) support trailing space in replace_branch's 'replacement_text' config (sds#804) Allow overriding Gemfile.lock (sds#796) Cut version 0.59.1 (sds#785) Revert addition of `--disable-pending-cops` flag to RuboCop (sds#783) Revert `Fix encoding of process output under windows` (sds#784) Cut version 0.59.0 (sds#780) Partial log flushing to make long hooks intuitive (sds#777) Fix pronto hooks swallowing generic errors (sds#779) ... # Conflicts: # CHANGELOG.md # README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #868.
Every hook in
template-dir/hooksstarts by reading.overcommit.ymlto look for agemfile:setting:File.readwithout an encoding usesEncoding.default_external. Under a non-UTF-8 locale such asLANG=Cthat is US-ASCII, so if.overcommit.ymlcontains any non-ASCII character (even in a comment) the match raisesArgumentError: invalid byte sequence in US-ASCIIbefore Overcommit loads, and every git hook fails.This passes
encoding: 'UTF-8'in all 10 hook copies (the template directory spec requires them to be byte-identical).The regression spec in
spec/integration/template_dir_spec.rbinitializes a temporary repository using the hook templates and writes a.overcommit.ymlcontaining a non-ASCII comment. It runs the installedpre-commithook withLC_ALL=C LANG=Cand-E US-ASCII, then checks for a successful exit and output from the configuredAuthorNamecheck. This verifies that the hook actually runs instead of passing on an unrelated startup failure or an early exit. The encoding is set explicitly because the CI runners use a UTF-8 locale by default.Initial validation of the original spec on the fork:
template_dir_spec.rb:31,expected "…/template-dir/hooks/pre-commit:30:in '<main>': invalid byte s…" not to include "invalid byte sequence".1667 examples, 0 failures), and Lint passes.The original fix commit is the squashed form of the fix branch; a separate follow-up commit strengthens the regression test. I left
CHANGELOG.mdalone since it looks like it is written when a version is cut.Follow-up validation: Tests passes on all eight Ruby versions (2.6–4.0), and Lint passes. The strengthened spec also passes locally on Ruby 2.6 and fails both without the encoding fix and with hook execution disabled. The full local suite has four macOS timestamp precision failures, all reproduced on the original PR commit.