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 }); }