Context
I'm working in a complex git flow where some specific branches get specific submodules and some specific config files that require to be committed, but must not be merged.
These are few files but it is too dangerous to let anyone merge branches without being careful not to merge those.
In order to make it automatic, I worked on pre-merge-commit hooks, both at server and local side.
In case of conflict, I make use of .gitattributes and git/config files to resolve the conflict with a custom merge driver. It works like a charm.
Problem
However, I'm struggling to make it work when there is no conflict. In this case, the merge is carried out successfully and my pre-merge-hook is triggered. It does its magic and then exit successfully. Though, for some reason, git re-do some merging stuff after the hook which make it useless. Here is the behavior I'm witnessing :
before the merge
I got two branches, let's say A_current and B_incoming.
Both got a file I don't want to be merged. This file is called do_not_merge_me. At some point, do_not_merge_me content changed in B_incoming. Let's say it went from contentA to contentB
during the merge
What I see when I'm merging B_incoming into A_current is :
- The merge goes on, and adds files in the staged area, including
do_not_merge_me. - The merge succeed, so it triggers my hook
- my hook finds
do_not_merge_mein the staging area and remove it from the staging area (at the end, it's agit reset do_not_merge_mefollowed by agit checkout do_not_merge_me) - my hook ends properly,
do_not_merge_meis not in the staging area anymore - Git does some dark magic : it redo a merge and re-stage
do_not_merge_me - Git validate the commit, I see this added in my console :
Merge made by the 'recursive' strategy.
do_not_merge_me | 2 +-
- Weirdly, after the merge is done, I got the correct versions of the files in my staged area (I'd never seen anything in the staging area after a merge, before this)
Question
The git documentation, available here https://git-scm.com/docs/githooks#_pre_merge_commit, states the pre-merge-commit is triggered after the merged is successfully handled and before the commit is validated.
My questions are:
- why do I get the correct version in the staged area ?
- Is there any way to achieve what I'm trying to do ?
- Why is git doing some merging stuff after the hook ? Is it a bug ?