diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 000000000..01590b752 --- /dev/null +++ b/.githooks/pre-commit @@ -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 diff --git a/.github/workflows/git-attributes.yml b/.github/workflows/git-attributes.yml index 7637713bd..60eb352b2 100644 --- a/.github/workflows/git-attributes.yml +++ b/.github/workflows/git-attributes.yml @@ -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: 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." diff --git a/FIXME-notes.md b/FIXME-notes.md index e3f1bcc68..9dafdf9a7 100644 --- a/FIXME-notes.md +++ b/FIXME-notes.md @@ -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.