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

Conversation

johnduffell
Copy link
Member

@johnduffell johnduffell commented Dec 18, 2024

Following on from #2546

I noticed it wasn't actually working, the pushes were still taking ages.

It turned out from looking at the output, the AI generated script was assuming there was always an upstream origin/MY_BRANCH_NAME branch, but this isn't the case until you push it.

This meant a chicken and egg situation where when you pushed your new branch, it would run the command, get a nonzero exit code (128), and therefore run the tests!

 % git diff --exit-code --quiet origin/jd-pre-push-condition -- cdk/; echo $?
fatal: bad revision 'origin/jd-pre-push-condition'
128

This PR changes it to try the main branch, if the similarly named origin branch doesn't exist.

Even trying main is not bulletproof, as you might have pulled CDK related updates to main and not merged them into your branch. Or you might have fetched them and merged them in to your branch, without updating the main branch. But I think this should cover most of our typical use cases in the way that we would expect.

Testing

I have tested both of a new branch and an extra push, on both of with and without changes in the CDK folder, and all combinations work as expected.

@johnduffell johnduffell changed the title fix pre-push to not access a non-existent branch fix pre-push to compare with main on first push Dec 18, 2024
@@ -1,13 +1,27 @@
# Fetch the latest changes from the remote without merging
Copy link
Member Author

Choose a reason for hiding this comment

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

not sure if the AI comments were providing any value

@johnduffell johnduffell merged commit e204555 into main Dec 19, 2024
48 checks passed
@johnduffell johnduffell deleted the jd-fix-pre-push-condition branch December 19, 2024 08:41
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
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

shtukas added a commit that referenced this pull request Dec 19, 2024
…ion"

This reverts commit e204555, reversing
changes made to a27f54c.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants