fix(pre-commit): improve monorepo handling and failure messaging (#9123)

Co-authored-by: matt korwel <matt.korwel@gmail.com>
This commit is contained in:
Keith Lyons
2025-09-23 11:57:24 -04:00
committed by GitHub
parent c93eed6384
commit 82625fc07a
3 changed files with 32 additions and 2 deletions

View File

@@ -1 +1,9 @@
npm run pre-commit npm run pre-commit || {
echo ''
echo '===================================================='
echo 'pre-commit checks failed. in case of emergency, run:'
echo ''
echo 'git commit --no-verify'
echo '===================================================='
exit 1
}

View File

@@ -52,7 +52,7 @@
"telemetry": "node scripts/telemetry.js", "telemetry": "node scripts/telemetry.js",
"check:lockfile": "node scripts/check-lockfile.js", "check:lockfile": "node scripts/check-lockfile.js",
"clean": "node scripts/clean.js", "clean": "node scripts/clean.js",
"pre-commit": "lint-staged" "pre-commit": "node scripts/pre-commit.js"
}, },
"bin": { "bin": {
"gemini": "bundle/gemini.js" "gemini": "bundle/gemini.js"

22
scripts/pre-commit.js Normal file
View File

@@ -0,0 +1,22 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { execSync } from 'node:child_process';
import lintStaged from 'lint-staged';
try {
// Get repository root
const root = execSync('git rev-parse --show-toplevel').toString().trim();
// Run lint-staged with API directly
const passed = await lintStaged({ cwd: root });
// Exit with appropriate code
process.exit(passed ? 0 : 1);
} catch {
// Exit with error code
process.exit(1);
}