Skip to content

chore: track the @date/@copyright hook and stop it stamping unchanged files - #153

Merged
FredM67 merged 1 commit into
devfrom
chore/metadata-hook
Sep 21, 2026
Merged

FredM67 merged 1 commit into
devfrom
chore/metadata-hook

Conversation

@FredM67

@FredM67 FredM67 commented Sep 21, 2026

Copy link
Copy Markdown
Owner

Problem

A hand-written .git/hooks/pre-commit occupied the hook slot on my machine and never chained to the pre-commit framework. Two consequences:

  • Everything declared in .pre-commit-config.yaml — no-commit-to-branch, clang-format, trailing-whitespace, end-of-file-fixer, mixed-line-ending — was silently inert locally.
  • The hook stamped @date / @copyright on every staged .cpp/.h, whether or not the file had actually been edited. Any git add -A turned into a spray of one-line date bumps. On feat: left-aligned ADC and circular channel list (#121) #127 that was 7 files of pure churn, all of them conflict bait against feature/remote-loads.

Change

  • scripts/hooks/update-metadata.sh — the same logic, tracked and fixed. It stamps only when the staged diff contains a change other than the metadata lines themselves; a metadata-only change is restored from HEAD instead. Newly added files always stamp. Like clang-format, it rewrites the file and fails rather than calling git add itself (staging from inside a hook interferes with pre-commit's stash handling).
  • .pre-commit-config.yaml — registers it as a local hook and adds ci: skip: [update-metadata], so pre-commit.ci never stamps headers with the build date.
  • CONTRIBUTING.md — documents the hook and the CI skip.

Testing

Exercised all three paths against a tracked header:

staged change result
@date bump only reverted to the HEAD value, file left untouched
real edit + stale date stamped to today, copyright year extended
real edit + current date no-op, exit 0

Note for anyone with a local checkout

The hand-written hook has to go for the framework shim to take the slot. One-time setup, already documented in CONTRIBUTING.md:

pip install pre-commit && pre-commit install

🤖 Generated with Claude Code

… files

The hand-written .git/hooks/pre-commit occupied the hook slot without ever
chaining to pre-commit, so no-commit-to-branch, clang-format and the
whitespace fixers declared in .pre-commit-config.yaml never ran locally. It
also stamped @Date on every staged .cpp/.h unconditionally, which turned any
`git add -A` into a spray of one-line date bumps that pad diffs and conflict
between long-lived branches.

Move the logic into a tracked script registered as a local pre-commit hook.
It now stamps only when the staged diff contains a change other than the
metadata lines themselves; a metadata-only change is restored from HEAD.
Skipped on pre-commit.ci, where the date would be the build date.

Contributors need the one-time `pip install pre-commit && pre-commit install`
documented in CONTRIBUTING.md.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@FredM67
FredM67 merged commit 3c9ca74 into dev Sep 21, 2026
13 checks passed
@FredM67
FredM67 deleted the chore/metadata-hook branch September 21, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant