From 4d5069e4742d790df0b2caa365fb84961825bd7e Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Sun, 11 Oct 2026 16:02:20 -0400 Subject: [PATCH 1/2] ci/workflows: Check PRs for trailing whitespace Reject trailing whitespace, including in new files and lines. Trailing spaces and tabs provide no value, can cause inconsistent rendering, complicate diffs and merges, and create needless whitespace-only changes in future edits. Keeping them out makes source files cleaner and reviews easier. Use .gitattributes to limit checks to text files. Fetch full history to make the PR base and head commits available. Signed-off-by: Robin Getz --- .github/workflows/git-attributes.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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." From 98bd57006c2aa4a3220881b56f8aa6d64e48a53c Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Sun, 11 Oct 2026 16:05:46 -0400 Subject: [PATCH 2/2] Add pre-commit whitespace check hook Add a shared Git hook to reject trailing whitespace in staged changes. Document how developers enable the hook locally. Keep the GitHub Actions check as a server-side safeguard for pull requests. Signed-off-by: Robin Getz --- .githooks/pre-commit | 8 ++++++++ FIXME-notes.md | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100755 .githooks/pre-commit 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/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.