From 8cb57a2053b0cd21c48850b82bc3f91e42300f8a Mon Sep 17 00:00:00 2001 From: creatorHead Date: Tue, 24 Feb 2026 17:35:58 +0530 Subject: [PATCH] fix: correct git log format and resolve symlinks in year update cache 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. --- licensecheck/update.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/licensecheck/update.go b/licensecheck/update.go index 3d990bd..b3fa37b 100644 --- a/licensecheck/update.go +++ b/licensecheck/update.go @@ -414,7 +414,7 @@ func GetRepoRoot(workingDir string) (string, error) { // - The year of the first commit in the repository (or 0 if not found) // - An error if the git command fails func buildRepositoryCache(repoRoot string) (map[string]int, int, error) { - cmd := exec.Command("git", "log", "--format=format:%ad", "--date=format:%Y", "--name-only") + cmd := exec.Command("git", "log", "--format=format:__CW_YEAR__=%ad", "--date=format:%Y", "--name-only") cmd.Dir = repoRoot output, err := cmd.Output() if err != nil { @@ -484,6 +484,14 @@ func getFileLastCommitYear(filePath string, repoRoot string) (int, error) { return 0, err } + // Resolve symlinks to get the canonical path. This is important on systems + // like macOS where /tmp is a symlink to /private/tmp. The git repo root + // (from 'git rev-parse --show-toplevel') uses the real path, so absPath + // must also be resolved before computing the relative path. + if resolved, err := filepath.EvalSymlinks(absPath); err == nil { + absPath = resolved + } + // Calculate relative path from repo root to file relPath, err := filepath.Rel(repoRoot, absPath) if err != nil {