← index #15830PR #12157
Related · high · value 1.542
QUERY · ISSUE

Pre-commit spellchecker rejects commits on the basis of filenames not involved in the commit itself.

openby agattiopened 2024-09-11updated 2024-09-11
bug

Port, board and/or hardware

N/A

MicroPython version

N/A

Reproduction

  1. Install the pre-commit hooks on the MicroPython repo, and make sure it doesn't have any existing change or uncommitted files in it (git status shouldn't report anything needing to be acted upon)
  2. Create a file with a name that would trigger the pre-commit spellchecking (ie. "eror.c")
  3. Change anything on an existing file, and add that change to the git staging area
  4. Commit the change in interactive mode (this is important), writing a commit message that would otherwise pass all checks (sign-off line present, no typos, valid, subject line format, etc.)
  5. The pre-commit hooks reject the commit on the basis of the misspelt file created in step 2.

Expected behaviour

The spellchecking pre-commit hook should reject misspellings only on typos in the commit message content and (optionally) on the names of files that are part of the commit itself.

Observed behaviour

$ git clone https://github.com/micropython/micropython.git
Cloning into 'micropython'...
remote: Enumerating objects: 123388, done.
remote: Counting objects: 100% (577/577), done.
remote: Compressing objects: 100% (358/358), done.
remote: Total 123388 (delta 298), reused 358 (delta 218), pack-reused 122811 (from 1)
Receiving objects: 100% (123388/123388), 62.78 MiB | 7.98 MiB/s, done.
Resolving deltas: 100% (92509/92509), done.
Updating files: 100% (5594/5594), done.
$ cd micropython
$ pre-commit install --hook-type pre-commit --hook-type commit-msg
pre-commit installed at .git/hooks/pre-commit
pre-commit installed at .git/hooks/commit-msg
$ touch eror.c
$ echo "Changed file." >> README.md
$ git add README.md
$ git commit -s
# ($EDITOR is invoked, with the default git template)
MicroPython codeformat.py for changed C files............................Passed
ruff.................................................(no files to check)Skipped
ruff-format..........................................(no files to check)Skipped
Spellcheck for changed files (codespell).................................Passed
MicroPython codeformat.py for changed C files............................Passed
MicroPython git commit message format checker............................Passed
- hook id: verifygitlog
- duration: 0.15s

ok

ruff.................................................(no files to check)Skipped
ruff-format..........................................(no files to check)Skipped
Spellcheck for changed files (codespell).................................Failed
- hook id: codespell
- exit code: 65

.git/COMMIT_EDITMSG:16: eror ==> error
1
$

Additional Information

The issue occurs because the spellchecking step also looks at the comment lines in the git template that would be stripped away when committing. Following the reproduction steps, the spellchecker would trigger on this:

<subject line goes here>

<optional commit message>

Signed-off-by: Committer name <committer@email>

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#   (use "git push" to publish your local commits)
#
# Changes to be committed:
#	modified:   README.md
#
# Untracked files:
#	eror.c
#

"eror" would trigger the check even if it isn't part of the commit files set, and even if the line it appears in will get stripped by git when adding the commit to the repo.

Code of Conduct

Yes, I agree

CANDIDATE · PULL REQUEST

Pre-commit for codespell

mergedby Josverlopened 2023-08-03updated 2024-01-25

Add a pre-commit hook for codespell and updates the documentation accordingly.

To minimize complexity when using the pre-commit hook, codespell and tomli are installed automatically from the codespell-repo, and configuration is read from the pyproject.toml file.

to test:

$> pip install pre-commit

$> pre-commit install --hook-type pre-commit --hook-type commit-msg

$> pre-commit run codespell               
Spellcheck for changed files (codespell).................................Passed

Signed-off-by: Jos Verlinde jos_verlinde@hotmail.com

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied