Add post checkout pnpm install to git hooks (#36731)

* Add post checkout pnpm install to help devs, disable hooks on pre push.
* Disable hooks in all simpleGit instances where checkout is run.
This commit is contained in:
Sam Seay 2023-02-21 08:42:44 +13:00 committed by GitHub
parent b3b6eacdf4
commit 13b09da2cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 8 deletions

4
.husky/post-checkout Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
pnpm install

View File

@ -31,8 +31,9 @@ if [ $? -ne 0 ]; then
exit 1 exit 1
fi fi
# Ensure both branches are tracked or check-changelogger-use will fail. # Ensure both branches are tracked or check-changelogger-use will fail. Note we pass hooksPath
git checkout $PROTECTED_BRANCH --quiet # to avoid running the pre-commit hook.
git checkout $CURRENT_BRANCH --quiet git -c core.hooksPath=/dev/null checkout $PROTECTED_BRANCH --quiet
git -c core.hooksPath=/dev/null checkout $CURRENT_BRANCH --quiet
php tools/monorepo/check-changelogger-use.php $PROTECTED_BRANCH $CURRENT_BRANCH php tools/monorepo/check-changelogger-use.php $PROTECTED_BRANCH $CURRENT_BRANCH

View File

@ -132,7 +132,10 @@ export const sparseCheckoutRepo = async (
* @return {Response<string>} - the simple-git response. * @return {Response<string>} - the simple-git response.
*/ */
export const checkoutRef = ( pathToRepo: string, ref: string ) => { export const checkoutRef = ( pathToRepo: string, ref: string ) => {
const git = simpleGit( { baseDir: pathToRepo } ); const git = simpleGit( {
baseDir: pathToRepo,
config: [ 'core.hooksPath=/dev/null' ],
} );
return git.checkout( ref ); return git.checkout( ref );
}; };
@ -252,7 +255,10 @@ export const getPullRequestNumberFromHash = async (
hash: string hash: string
) => { ) => {
try { try {
const git = await simpleGit( { baseDir } ); const git = await simpleGit( {
baseDir,
config: [ 'core.hooksPath=/dev/null' ],
} );
const formerHead = await git.revparse( 'HEAD' ); const formerHead = await git.revparse( 'HEAD' );
await git.checkout( hash ); await git.checkout( hash );
const cmdOutput = await git.raw( [ const cmdOutput = await git.raw( [
@ -294,7 +300,10 @@ export const generateDiff = async (
excludePaths: string[] = [] excludePaths: string[] = []
) => { ) => {
try { try {
const git = simpleGit( { baseDir: tmpRepoPath } ); const git = simpleGit( {
baseDir: tmpRepoPath,
config: [ 'core.hooksPath=/dev/null' ],
} );
const validBranches = [ hashA, hashB ].filter( const validBranches = [ hashA, hashB ].filter(
( hash ) => ! refIsHash( hash ) ( hash ) => ! refIsHash( hash )

View File

@ -21,7 +21,10 @@ const getPluginData = async (
pathToMainFile: string, pathToMainFile: string,
hashOrBranch: string hashOrBranch: string
): Promise< string | void > => { ): Promise< string | void > => {
const git = simpleGit( { baseDir: tmpRepoPath } ); const git = simpleGit( {
baseDir: tmpRepoPath,
config: [ 'core.hooksPath=/dev/null' ],
} );
await git.checkout( [ hashOrBranch ] ); await git.checkout( [ hashOrBranch ] );
const mainFile = join( tmpRepoPath, pathToMainFile ); const mainFile = join( tmpRepoPath, pathToMainFile );

View File

@ -81,7 +81,10 @@ export const generateSchemaDiff = async (
build: () => Promise< void > | void, build: () => Promise< void > | void,
error: ( s: string ) => void error: ( s: string ) => void
): Promise< SchemaDiff[] | null > => { ): Promise< SchemaDiff[] | null > => {
const git = simpleGit( { baseDir: tmpRepoPath } ); const git = simpleGit( {
baseDir: tmpRepoPath,
config: [ 'core.hooksPath=/dev/null' ],
} );
// Be sure the wp-env engine is started. // Be sure the wp-env engine is started.
await startWPEnv( tmpRepoPath, error ); await startWPEnv( tmpRepoPath, error );