Repository navigation
Commit 51a541d
Read .overcommit.yml as UTF-8 in the hook template (sds#910)
Fixes sds#868.
Every hook in `template-dir/hooks` starts by reading `.overcommit.yml`
to look for a `gemfile:` setting:
```ruby
File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
```
`File.read` without an encoding uses `Encoding.default_external`. Under
a non-UTF-8 locale such as `LANG=C` that is US-ASCII, so if
`.overcommit.yml` contains any non-ASCII character (even in a comment)
the match raises `ArgumentError: invalid byte sequence in US-ASCII`
before 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.rb`
initializes a temporary repository using the hook templates and writes a
`.overcommit.yml` containing a non-ASCII comment. It runs the installed
`pre-commit` hook with `LC_ALL=C LANG=C` and `-E US-ASCII`, then checks
for a successful exit and output from the configured `AuthorName` check.
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:
- Spec only, without the fix:
[Tests](https://github.com/ChandraChaan/overcommit/actions/runs/41726596528)
fails on every Ruby from 2.6 to 4.0 with a single failure out of 1667
examples, `template_dir_spec.rb:31`, `expected
"…/template-dir/hooks/pre-commit:30:in '<main>': invalid byte s…" not to
include "invalid byte sequence"`.
- Spec with the fix:
[Tests](https://github.com/ChandraChaan/overcommit/actions/runs/41726604340)
passes on all eight Ruby versions (`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.md` alone since it looks like it is written when a version is
cut.
Follow-up validation:
[Tests](https://github.com/sds/overcommit/actions/runs/41934884255)
passes on all eight Ruby versions (2.6–4.0), and
[Lint](https://github.com/sds/overcommit/actions/runs/41934884375)
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.
---------
Co-authored-by: Shane da Silva <[email protected]>1 parent 50f3e86 commit 51a541d
11 files changed
Lines changed: 37 additions & 10 deletions
File tree
- spec/integration
- template-dir/hooks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
29 | 56 | | |
30 | 57 | | |
31 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
0 commit comments