Skip to content

Commit

Permalink
Merge pull request #2605 from guardian/jd-fix-pre-push-condition
Browse files Browse the repository at this point in the history
fix pre-push to compare with main on first push
  • Loading branch information
johnduffell authored Dec 19, 2024
2 parents a27f54c + 5322971 commit e204555
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -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 origin/$CURRENT_BRANCH -- 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

0 comments on commit e204555

Please sign in to comment.