Pre-commit spellchecker rejects commits on the basis of filenames not involved in the commit itself.
Port, board and/or hardware
N/A
MicroPython version
N/A
Reproduction
- 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 statusshouldn't report anything needing to be acted upon) - Create a file with a name that would trigger the pre-commit spellchecking (ie. "eror.c")
- Change anything on an existing file, and add that change to the git staging area
- 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.)
- 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
Pre-commit for codespell
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