Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pre-push to compare with main on first push #2605

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you maybe want to compare with the point you branched? This SO post has some info on how to do that: https://stackoverflow.com/questions/29810331/is-there-a-quick-way-to-git-diff-from-the-point-or-branch-origin

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
Loading