The problem of foxtrot merges explained in details in this question. In a nutshell: When working on the same branch (remote and local), the simple git merge
command hides the remote merged commits under 2nd parent, and replaces the first-parents history of the remote (in the regular case - "origin"). And we consider it to be bad.
The linked-above question asks for a way to detect this situation, and reject the push. My question is how to automatically fix it.
I don't really care about the neat-tidiness of the full tree history, but I want that the first-parents tree will be perfect. And it is important to not disturb the other users, so the problem should solve itself automatically.
The goal: When the git origin hook detects foxtrot commit push, it will add another merge-commit, above the old-HEAD, and the new-HEAD, putting the old-HEAD as first-parent.
What is the safest way to achieve it?