diff --git a/.husky/post-checkout b/.husky/post-checkout index cddb5753bc3..1485ab1707b 100755 --- a/.husky/post-checkout +++ b/.husky/post-checkout @@ -1,35 +1,30 @@ #!/usr/bin/env bash . "$(dirname "$0")/_/husky.sh" -# '1' is branch +# The hook documentation: https://git-scm.com/docs/githooks.html#_post_checkout CHECKOUT_TYPE=$3 -redColoured='\033[0;31m' +HEAD_NEW=$2 +HEAD_PREVIOUS=$1 + whiteColoured='\033[0m' +orangeColoured='\033[1;33m' +# '1' is a branch checkout if [ "$CHECKOUT_TYPE" = '1' ]; then - canUpdateDependencies='no' - # Prompt about pnpm versions mismatch when switching between branches. - currentPnpmVersion=$( ( command -v pnpm > /dev/null && pnpm -v ) || echo 'n/a' ) + currentPnpmVersion=$( ( command -v pnpm > /dev/null && pnpm -v 2>/dev/null ) || echo 'n/a' ) targetPnpmVersion=$( grep packageManager package.json | sed -nr 's/.+packageManager.+pnpm@([[:digit:].]+).+/\1/p' ) if [ "$currentPnpmVersion" != "$targetPnpmVersion" ]; then - printf "${redColoured}pnpm versions mismatch: in use '$currentPnpmVersion', needed '$targetPnpmVersion'. Here some hints how to solve this:\n" - printf "${redColoured}* actualize environment: 'nvm use && pnpm -v' (the most common case)\n" - printf "${redColoured}* install: 'npm install -g pnpm@$targetPnpmVersion'\n" - else - canUpdateDependencies='yes' + printf "${orangeColoured}pnpm versions mismatch: in use '$currentPnpmVersion', needed '$targetPnpmVersion'. If you are working on something in this branch, here are some hints on how to solve this:\n" + printf "${orangeColoured}* actualize environment: 'nvm use && pnpm -v' (the most common case)\n" + printf "${orangeColoured}* install: 'npm install -g pnpm@$targetPnpmVersion'\n" fi # Auto-refresh dependencies when switching between branches. - changedManifests=$( ( git diff --name-only HEAD ORIG_HEAD | grep -E '(package.json|pnpm-lock.yaml|pnpm-workspace.yaml|composer.json|composer.lock)$' ) || echo '' ) + changedManifests=$( ( git diff --name-only $HEAD_NEW $HEAD_PREVIOUS | grep -E '(package.json|pnpm-lock.yaml|pnpm-workspace.yaml|composer.json|composer.lock)$' ) || echo '' ) if [ -n "$changedManifests" ]; then - printf "${whiteColoured}It was a change in the following file(s) - refreshing dependencies:\n" + printf "${whiteColoured}The following file(s) in the new branch differs from the original one, dependencies might need to be refreshed:\n" printf "${whiteColoured} %s\n" $changedManifests - - if [ "$canUpdateDependencies" = 'yes' ]; then - pnpm install --frozen-lockfile - else - printf "${redColoured}Skipping dependencies refresh. Please actualize pnpm version and execute 'pnpm install --frozen-lockfile' manually.\n" - fi + printf "${orangeColoured}If you are working on something in this branch, ensure to refresh dependencies with 'pnpm install --frozen-lockfile'\n" fi fi diff --git a/.husky/post-merge b/.husky/post-merge index 7ff64bebced..bc022e8fede 100755 --- a/.husky/post-merge +++ b/.husky/post-merge @@ -1,6 +1,8 @@ #!/usr/bin/env bash . "$(dirname "$0")/_/husky.sh" +# The hook documentation: https://git-scm.com/docs/githooks.html#_post_merge + changedManifests=$( ( git diff --name-only HEAD ORIG_HEAD | grep -E '(package.json|pnpm-lock.yaml|pnpm-workspace.yaml|composer.json|composer.lock)$' ) || echo '' ) if [ -n "$changedManifests" ]; then printf "It was a change in the following file(s) - refreshing dependencies:\n"