Fixes T10665. See that task for discussion.
Because $head_map is not properly re-initialized for each ref we check, pushes which affect multiple branches (say, "A" and "B") can have information bleed from the first branch check to the second branch.
To trigger a problem behavior, you can push one commit which updates an existing branch, plus one commit which creates a new branch. If they process in the right order, the $head_map from the updated branch will bleed into the $head_map for the new branch and trigger an incorrect head split detection.