From b02e02dcd26c0bbe87db81be61b964a8167d692a Mon Sep 17 00:00:00 2001 From: L4XB Date: Thu, 22 Oct 2026 23:01:26 +0200 Subject: [PATCH] fix(hooks): list modified files from the repository root even with diff.relative With diff.relative=true, `git diff --name-only` reports paths relative to the working directory, so joining them to the repository root pointed at files that do not exist, and a session in a subdirectory again got no console.log warning. getGitModifiedFiles now runs `git -c diff.relative=false diff --name-only HEAD`. The -c form also works on Git versions older than --no-relative. --- scripts/lib/utils.js | 3 ++- tests/hooks/hooks.test.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/lib/utils.js b/scripts/lib/utils.js index 2e8550e5e..cc2b6c21e 100644 --- a/scripts/lib/utils.js +++ b/scripts/lib/utils.js @@ -552,7 +552,8 @@ function isGitRepo() { function getGitModifiedFiles(patterns = []) { if (!isGitRepo()) return []; - const result = runCommand('git diff --name-only HEAD'); + // Paths from the repository root even when diff.relative is set. + const result = runCommand('git -c diff.relative=false diff --name-only HEAD'); if (!result.success) return []; let files = result.output.split('\n').filter(Boolean); diff --git a/tests/hooks/hooks.test.js b/tests/hooks/hooks.test.js index 71eb2e8ca..af257f8e0 100644 --- a/tests/hooks/hooks.test.js +++ b/tests/hooks/hooks.test.js @@ -1217,6 +1217,11 @@ async function runTests() { const result = await runScript(path.join(scriptsDir, 'check-console-log.js'), '{}', {}, appDir); assert.strictEqual(result.code, 0); assert.ok(result.stderr.includes('console.log found in packages/app/src/a.ts'), `Should warn about the file, got: ${result.stderr}`); + + // diff.relative would make git report paths from the session's directory. + execFileSync('git', ['config', 'diff.relative', 'true'], { cwd: repo }); + const relative = await runScript(path.join(scriptsDir, 'check-console-log.js'), '{}', {}, appDir); + assert.ok(relative.stderr.includes('console.log found in packages/app/src/a.ts'), `Should warn with diff.relative, got: ${relative.stderr}`); } finally { fs.rmSync(repo, { recursive: true, force: true }); }