Skip to content

fix: LICENSE file no longer updated on every run when no headers changed#224

Merged
CreatorHead merged 1 commit into
mainfrom
fix/license-always-updated
Apr 29, 2026
Merged

fix: LICENSE file no longer updated on every run when no headers changed#224
CreatorHead merged 1 commit into
mainfrom
fix/license-always-updated

Conversation

@CreatorHead
Copy link
Copy Markdown
Contributor

@CreatorHead CreatorHead commented Apr 29, 2026

anyFileUpdated was unconditionally set to true in non-plan mode due to a Repetitive condition, causing the LICENSE year to be bumped on every run even when all source file headers were already correct. This triggered buggy pre-commit hook failures.

Fix: teach addlicense.Run to return whether it actually wrote any files, and use that signal instead of the always-true condition.

🛠️ Description

What was broken:

The anyFileUpdated flag in cmd/headers.go was supposed to be true only when at least one source file was actually modified. The condition guarding it was a tautology — the second branch (!plan && runErr == nil) is always true in normal mode, so anyFileUpdated was set on every successful run regardless of whether any file was touched. This caused the LICENSE file's copyright year to be bumped unconditionally, producing a spurious git diff and causing pre-commit hooks to fail with "files were modified by this hook" even when no header work was needed.

What changed:

  • addlicense.processFile now returns (bool, error) — the bool is true when the file was actually written to
  • addlicense.Run now returns (bool, error) — uses an atomic.Bool to aggregate results across parallel goroutines
  • The always-true condition in cmd/headers.go is replaced with the actual signal from Run

Before:

if runErr != nil || (!plan && runErr == nil) {
    anyFileUpdated = true
}

After:

filesAdded, runErr := addlicense.Run(...)
if runErr != nil || filesAdded {
    anyFileUpdated = true
}

🔗 External Links

👍 Definition of Done
New functionality works? — verified: repo with all correct headers produces zero changes and clean git status
Tests added? — existing test suite updated to match new return signature; all packages pass
🤔 Can be merged upon approval?

PCI review checklist
I have documented a clear reason for, and description of, the change I am making.
If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request. — simple git revert; no schema or data changes involved.
If applicable, I've documented the impact of any changes to security controls. — no security controls affected; bug fix in copyright year tracking logic only.

Test Results

# Scenario Expected Result
A All headers correct, LICENSE up to date No changes ✅ Clean
B Source file missing header, LICENSE already at current year Header added, LICENSE untouched ✅ Pass
C Source file missing header, LICENSE behind (2025) Header added + LICENSE bumped ✅ Pass
D Source file year outdated (2025), LICENSE behind Both year-bumped to current year ✅ Pass
E --plan mode with missing header Shows what would change, writes nothing ✅ Pass
F --plan mode with everything correct No output, writes nothing ✅ Clean
G No LICENSE file in repo Runs cleanly, no crash ✅ Pass
H Mixed — correct, missing, outdated in same repo Only affected files changed, correct file untouched ✅ Pass
I ignore_year1=true, single-year headers already correct No changes ✅ Clean
J Idempotency — run once then run again immediately Second run always produces zero changes ✅ Pass
K Existing header year outdated, no missing headers (step 1 only) Year bumped in source + LICENSE ✅ Pass
L Copyright holder mismatch (e.g. HashiCorp → Acme) Holder updated, LICENSE untouched if already current year ✅ Pass

anyFileUpdated was unconditionally set to true in non-plan mode due to
a tautological condition, causing the LICENSE year to be bumped on every
run even when all source file headers were already correct. This triggered
spurious pre-commit hook failures.

Fix: teach addlicense.Run to return whether it actually wrote any files,
and use that signal instead of the always-true condition.
@CreatorHead CreatorHead requested a review from a team as a code owner April 29, 2026 08:37
@CreatorHead CreatorHead merged commit f558415 into main Apr 29, 2026
5 checks passed
@CreatorHead CreatorHead deleted the fix/license-always-updated branch April 29, 2026 09:16
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.

2 participants