Skip to content

fix: correct git log format and resolve symlinks in year update cache#195

Merged
CreatorHead merged 1 commit into
mainfrom
fix-year-update-cache
Feb 26, 2026
Merged

fix: correct git log format and resolve symlinks in year update cache#195
CreatorHead merged 1 commit into
mainfrom
fix-year-update-cache

Conversation

@CreatorHead
Copy link
Copy Markdown
Contributor

🛠️ Description

Two bugs were introduced in #191 (42a6ce3) that caused copyright year updates to never be applied when running copywrite headers.

Bug 1 — Wrong git log format string (buildRepositoryCache)

buildRepositoryCache used --format=format:%ad which outputs bare years (e.g. 2026). However, the parser expected lines prefixed with __CW_YEAR__= to distinguish year lines from filename lines. Since the prefix was never emitted, currentYear stayed 0, the cache was always empty, and lastCommitYear was always 0 for every file. This meant the condition lastCommitYear > info.EndYear was never true, so end years were never bumped.

Fix: change format string to --format=format:__CW_YEAR__=%ad to match what the parser expects.

Bug 2 — Symlink path mismatch on macOS (getFileLastCommitYear)

getFileLastCommitYear computed the relative path via filepath.Rel(repoRoot, absPath). On macOS, tmp is a symlink to tmp. git rev-parse --show-toplevel (used to get repoRoot) resolves the real path (e.g. /private/tmp/repo), while filepath.Abs preserves the symlink path (e.g. /tmp/repo). This mismatch caused filepath.Rel to produce a wrong relative path, resulting in a cache miss on every file.

Fix: call filepath.EvalSymlinks on absPath before computing the relative path. This is a no-op on Linux and Windows where symlinks are not involved.

🔗 External Links

👍 Definition of Done

  • New functionality works?
  • Tests added?

🤔 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.

    These changes are limited to update.go. To revert, simply revert this PR or cherry-pick the fix from 42a6ce3 with the corrected format string and symlink resolution.

  • If applicable, I've documented the impact of any changes to security controls.

    No security controls are affected. This is a bug fix for git log parsing and file path resolution in the copyright year update logic.

Two bugs were introduced in #191 (42a6ce3) that caused copyright year
updates to never be applied:

1. buildRepositoryCache used '--format=format:%ad' which outputs bare
   years (e.g. '2026'), but the parser expected lines prefixed with
   '__CW_YEAR__=' to distinguish years from filenames. This meant
   lastCommitYear was always 0, so the condition 'lastCommitYear >
   info.EndYear' was never true and end years were never bumped.
   Fix: change format to '--format=format:__CW_YEAR__=%ad'.

2. getFileLastCommitYear computed the relative path via
   filepath.Rel(repoRoot, absPath), but on macOS /tmp is a symlink to
   /private/tmp. git resolves the real path for repoRoot while
   filepath.Abs preserves the symlink, causing a path mismatch and a
   cache miss on every file.
   Fix: call filepath.EvalSymlinks on absPath before computing the
   relative path. This is a no-op on Linux and Windows where symlinks
   are not involved.
@CreatorHead CreatorHead requested a review from a team as a code owner February 24, 2026 12:11
Copy link
Copy Markdown
Collaborator

@mohanmanikanta2299 mohanmanikanta2299 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@CreatorHead CreatorHead merged commit 69a19ab into main Feb 26, 2026
5 checks passed
@CreatorHead CreatorHead deleted the fix-year-update-cache branch February 26, 2026 10:02
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