I'm creating a GitHub Action which runs a check to see how a pull request affects the codebase. The check needs two inputs:
- The repository state before the PR changes
- The repository state after the PR changes
The 2nd input is easy: its the newest commit on the PR branch
The 1st one is a bit tricky and I'm having trouble figuring it out. It can't simply be the master of the main (upstream) repository, because of the potential rebase issues (new changes are already on upstream/master which are not in the forks' master). So I'm using the merge-base between the master branch and the HEAD.
git merge-base master HEAD
This works as expected, but the problem arises if the PR is made from the forks' master branch. The merge-base is the same as HEAD.
How to get the correct SHA in order to checkout the repo just before the changes made on PR. GitHub handles this situation correctly and shows only the changed files.