From 6d82bda53abaf5d91f3f95c6a53f565d4569150b Mon Sep 17 00:00:00 2001 From: John Duffell Date: Wed, 18 Dec 2024 15:49:52 +0000 Subject: [PATCH 1/2] fix pre-push to not access a non-existent branch --- .husky/pre-push | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.husky/pre-push b/.husky/pre-push index dc37bc9d8..f8a188023 100644 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -5,7 +5,7 @@ git fetch origin CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) # Check if there are changes in the 'cdk' folder between the local branch and its remote -if git diff --exit-code --quiet origin/$CURRENT_BRANCH -- cdk/; then +if git diff --exit-code --quiet main -- cdk/; then echo "No changes detected in the 'cdk' folder. Skipping lint and test." else echo "Changes detected in the 'cdk' folder. Running lint and test..." From 5322971bf520448722f77ba2be921194c06a3f22 Mon Sep 17 00:00:00 2001 From: John Duffell Date: Wed, 18 Dec 2024 16:03:56 +0000 Subject: [PATCH 2/2] try our origin branch and then main for push hook --- .husky/pre-push | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/.husky/pre-push b/.husky/pre-push index f8a188023..ac928780e 100644 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,13 +1,27 @@ -# Fetch the latest changes from the remote without merging git fetch origin -# Get the name of the current branch CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) -# Check if there are changes in the 'cdk' folder between the local branch and its remote -if git diff --exit-code --quiet main -- cdk/; then +git diff --exit-code --quiet origin/$CURRENT_BRANCH -- cdk/ +RC=$? +if [ $RC -eq 0 ]; then + # no changes echo "No changes detected in the 'cdk' folder. Skipping lint and test." -else +elif [ $RC -eq 1 ]; then echo "Changes detected in the 'cdk' folder. Running lint and test..." pnpm --filter cdk lint && pnpm --filter cdk test +else + # something went wrong, maybe we haven't pushed our branch and are branching off main + # use main not origin/main as we don't care if others changed cdk dir + git diff --exit-code --quiet main -- cdk/ + RC=$? + if [ $RC -eq 0 ]; then + # no changes + echo "(main) No changes detected in the 'cdk' folder. Skipping lint and test." + elif [ $RC -eq 1 ]; then + echo "(main) Changes detected in the 'cdk' folder. Running lint and test..." + pnpm --filter cdk lint && pnpm --filter cdk test + else + echo "Error: could not compare with upstream" + fi fi