Browse Source

Merge pull request #3005 from rgetz/rgetz-disallow-trailing-spaces

Add trailing-whitespace checks to GitHub Actions and provide an optional local pre-commit hook.
chirpmodem-v8.0.0
Edouard Griffiths 1 month ago committed by GitHub
parent
commit
152c4da8cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      .githooks/pre-commit
  2. 14
      .github/workflows/git-attributes.yml
  3. 20
      FIXME-notes.md

8
.githooks/pre-commit

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
#!/bin/sh
#fail if trailing spaces
if ! git diff --cached --check -- \
':(attr:text)' ':(attr:text=auto)'; then
echo "Error: Remove trailing whitespace from staged changes."
exit 1
fi

14
.github/workflows/git-attributes.yml

@ -9,6 +9,8 @@ jobs: @@ -9,6 +9,8 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for line ending violations
run: |
@ -27,3 +29,15 @@ jobs: @@ -27,3 +29,15 @@ jobs:
fi
echo "All files have correct line endings."
- name: Check for trailing whitespace
run: |
if ! git diff --check \
"${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}" \
-- ':(attr:text)' ':(attr:text=auto)'; then
echo "::error::Trailing whitespace found in the pull request."
echo "Remove trailing spaces and tabs from added lines."
exit 1
fi
echo "No trailing whitespace found in the pull request."

20
FIXME-notes.md

@ -1,3 +1,23 @@ @@ -1,3 +1,23 @@
## Enable Git pre-commit hooks
SDRangel provides a Git pre-commit hook to check staged changes for trailing
whitespace before a commit is created. The hook is maintained in
`.githooks/pre-commit` and uses `.gitattributes` to determine which files to
check.
To enable the hook, run the following command from your repository root:
```bash
git config core.hooksPath .githooks
```
This configuration is local to your clone and only needs to be set once.
After enabling it, Git automatically runs the hook before each commit. If
trailing whitespace is detected, the commit is rejected. Correct the affected
lines, stage the changes, and try again.
The hook is shared through the repository, but enabling it is a per-clone setup
step. GitHub Actions also checks pull requests for trailing whitespace, providing
a server-side check independent of the local hook.
## meshtasticdemodgui.cpp - checkbox signal pattern
All checkboxes currently use stateChanged(int) pattern.
Consider refactoring all to clicked(bool) for simplicity in a future cleanup commit.

Loading…
Cancel
Save