Skip to content

Commit 5ff2218

Browse files
YunYouJunclaude
andcommitted
fix: ensureBasePath fallback, per-file maxCount, include %b in format
- ensureBasePath now catches git rev-parse failures and falls back to process.cwd() instead of rejecting (handles non-repo / shallow CI) - handleGitLogInfo and flushGitLogBatch both guard ensureBasePath with try/catch for defense-in-depth - batchGetChangelog removes --max-count (which limited globally across all pathspecs, not per-file) and truncates per-file in JS instead - Add %b (body) to git log pretty format to match getChangelog() output Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f6ee676 commit 5ff2218

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

node/gitLog.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export function initBasePath() {
2424
basePathPromise = git.revparse(['--show-toplevel']).then((result) => {
2525
basePath = result.trim()
2626
return basePath
27+
}).catch((error) => {
28+
consola.warn('valaxy-addon-git-log: Could not resolve git root, falling back to cwd.', error)
29+
basePath = process.cwd()
30+
return basePath
2731
})
2832
return basePathPromise
2933
}
@@ -73,7 +77,14 @@ export async function handleGitLogInfo(options: GitLogOptions, route: EditableTr
7377
route.meta.frontmatter.git_log = {}
7478

7579
// Ensure basePath is available before computing relative path
76-
const resolvedBase = await ensureBasePath()
80+
let resolvedBase: string
81+
try {
82+
resolvedBase = await ensureBasePath()
83+
}
84+
catch {
85+
// Fallback: use cwd-relative path
86+
resolvedBase = process.cwd()
87+
}
7788

7889
const gitRelativePath = path.relative(resolvedBase, filePath).split(path.sep).join('/')
7990
route.meta.frontmatter.git_log.path = gitRelativePath
@@ -172,11 +183,13 @@ async function batchGetChangelog(resolvedBase: string, filePaths: string[], maxC
172183
return result
173184

174185
try {
186+
// Note: --max-count is omitted because with multiple pathspecs it limits
187+
// the *global* commit count, not per-file. We fetch all matching commits
188+
// and truncate each file's array to `maxCount` in JS below.
175189
const raw = await git.raw([
176190
'log',
177-
`--max-count=${maxCount}`,
178191
'--name-only',
179-
'--pretty=format:---CL_SEP---%H|%an|%ae|%aI|%s',
192+
'--pretty=format:---CL_SEP---%H|%an|%ae|%aI|%s|%b',
180193
'--',
181194
...filePaths,
182195
])
@@ -227,8 +240,13 @@ async function batchGetChangelog(resolvedBase: string, filePaths: string[], maxC
227240
consola.error('valaxy-addon-git-log: Error batch-fetching changelogs:', e)
228241
}
229242

243+
// Truncate each file's changelog to maxCount to match per-file semantics
244+
for (const [fp, logs] of result) {
245+
if (logs.length > maxCount)
246+
result.set(fp, logs.slice(0, maxCount))
247+
}
248+
230249
return result
231-
}
232250

233251
/**
234252
* Process all pending routes in batch: 2 git commands for ALL files
@@ -245,7 +263,14 @@ export async function flushGitLogBatch(options: GitLogOptions) {
245263
const isPrebuilt = strategy === 'prebuilt'
246264
const isBuildTime = strategy === 'build-time'
247265

248-
const resolvedBase = await ensureBasePath()
266+
let resolvedBase: string
267+
try {
268+
resolvedBase = await ensureBasePath()
269+
}
270+
catch (error) {
271+
consola.error('valaxy-addon-git-log: Failed to resolve git root in flushGitLogBatch, skipping.', error)
272+
return
273+
}
249274

250275
const filePaths = routes.map(r => r.filePath)
251276
const maxCount = process.env.CI ? 1000 : 100

0 commit comments

Comments
 (0)