-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2605 from guardian/jd-fix-pre-push-condition
fix pre-push to compare with main on first push
- Loading branch information
Showing
1 changed file
with
19 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |