fix: correct git log format and resolve symlinks in year update cache#195
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🛠️ Description
Two bugs were introduced in #191 (
42a6ce3) that caused copyright year updates to never be applied when runningcopywrite headers.Bug 1 — Wrong git log format string (
buildRepositoryCache)buildRepositoryCacheused--format=format:%adwhich 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,currentYearstayed0, the cache was always empty, andlastCommitYearwas always0for every file. This meant the conditionlastCommitYear > info.EndYearwas never true, so end years were never bumped.Fix: change format string to
--format=format:__CW_YEAR__=%adto match what the parser expects.Bug 2 — Symlink path mismatch on macOS (
getFileLastCommitYear)getFileLastCommitYearcomputed the relative path viafilepath.Rel(repoRoot, absPath). On macOS, tmp is a symlink to tmp.git rev-parse --show-toplevel(used to getrepoRoot) resolves the real path (e.g./private/tmp/repo), whilefilepath.Abspreserves the symlink path (e.g./tmp/repo). This mismatch causedfilepath.Relto produce a wrong relative path, resulting in a cache miss on every file.Fix: call
filepath.EvalSymlinksonabsPathbefore computing the relative path. This is a no-op on Linux and Windows where symlinks are not involved.🔗 External Links
42a6ce3👍 Definition of Done
🤔 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.
If applicable, I've documented the impact of any changes to security controls.