This has been discussed in numerous posts before, and there's a feature request at https://youtrack.jetbrains.com/issue/TW-16070
But in addition to this, I want to discuss if it's possible to achieve this without resorting to command line merge or waiting for the feature request to get some traction.
So, is it possible to write a plugin that would handle the pre-build merge instead of using the command line? If so, where should I start looking? My first guess is that this might have to be a VCS plugin, meaning that I'd have to fork the existing git plugin, unless there's some sort of a "extend a plugin" mechanism.
We have setup where we have 3 related projects (application A, configurator B, test framework C) with a "git flow" type of branching setup, which are gathered together in a nightly attempt to merge their respective development branches to their master branches. Basically the test framework uses the configurator to configure the application, then flashes it on to hardware and executes a bunch of tests that take anywhere between 4 to 30 hours.
The development branches of these are built on commit, but for the test run I'll have to make a special "integration build" which does the pre-build merge, so I get the proper binaries to use in the actual test run.
Ideally I'd also like the build history to show that a build is indeed an "integration build": instead of showing "refs/heads/develop" as the built branch, it'd show something like "refs/heads/develop applied on top of refs/heads/master", since that is the actual case.
This last point can be worked around by using two different build jobs, but it'd still leave the build history in a misleading state as it would always say that the test builds are run on refs/heads/develop, even though they are actually refs/heads/master with develop on top.