I got this error when doing github PR check (in
npm run build process):
> nx affected:build --parallel
Error: Command failed: git merge-base master HEAD
And asked in group, Herb said he met with this error every time when the PR branch not just being merged with master
That’s weird, merging does not require the branch syncing with the latest version of master
After looking at github workflow script, there is no
git merge-base master HEAD code inside, and it’s happening inside
npm run build procedure, so I search and found that
nx build would execute this merge-base command
This command actually has not problem, I tired it on my computer, it works well
Is it because CI env had no master branch checked to local? I tried to add a
git checkout master but it still failed, and I found master already checked out in
What if I do the merging before build?
git merge-base master HEAD before build, But it exited with code 254 without error messages
That’s not very helpful
Day 2 trying
What about normal merge?
git merge master before build, it exited with error message:
Run git merge master
fatal: refusing to merge unrelated histories ##[error] Process completed with exit code 128.
Weird, it’s in the same repo, but git said
This information is crucial, I search with it and got:
When use Checkout@v2 12, only a single commit is fetched by default, for the ref/SHA that triggered the workflow. Set fetch-depth to fetch more history.
Oh, that’s helpful, maybe there is no commits history other than the latest one and git cannot find the common parent node of PR branch and master branch
And with the document of
# Number of commits to fetch. 0 indicates all history for all branches and tags.
# Default: 1
I thought to try with 0 (all history) is a good idea, and it worked.
Resolve and conclusion
- name: 'Checkout'
last line solved this problem
actions/checkout@v2 only fetched latest one commit info by default, so when merging, git can only check latest commit of master is the parent of PR branch or not, so if their common parent is a little earlier, it just fails with no more commits info of master. And now I fetched all commits on master, so
git merge can check one by one from latest to very first commit, cause PR branch is from master, so it will find the common parent node eventually, and perform the merging successfully.