Files
binutils-gdb/gdb/testsuite/gdb.src/pre-commit.exp
Tom de Vries 831917c6e0 [pre-commit] Add pre-commit setup check
I wrote a patch and accidentally introduced a typo in the commit message.

This didn't get detected because codespell-log didn't run.

I installed pre-commit on that setup a while back, before codespell-log was
around and consequently only the .git/hooks/pre-commit script was installed.

This is a bit hard to notice given that all other hooks do run.

Add a pre-commit check that checks for this situation:
...
$ rm .git/hooks/commit-msg
$ git commit --amend
  ...
pre-commit-setup........................................................Failed
- hook id: pre-commit-setup
- exit code: 1

missing hook: .git/hooks/commit-msg (please run pre-commit install)
  ...
$
...

This is a bit niche, but worthwhile if you're using a dozen build and test
installations.
2025-12-11 22:38:30 +01:00

43 lines
1.3 KiB
Plaintext

# Copyright 2025 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Run the pre-commit hooks.
set repodir $srcdir/../..
if {![file exists $repodir/.git]} {
unsupported "Not in a git repository"
return
}
with_cwd $repodir {
set result [remote_exec build "pre-commit --version"]
set status [lindex $result 0]
if {$status != 0} {
unsupported "pre-commit missing or broken"
return
}
# Skip the pre-commit-setup check. It checks the repository setup, not
# the sources.
setenv SKIP pre-commit-setup
set result [remote_exec build "pre-commit run --all-files -v"]
set status [lindex $result 0]
gdb_assert {$status == 0} "pre-commit checks"
}