As a preface, I strongly recommend reading Advanced SCM Branching Strategies by Stephen Vance. Much of this answer is based upon the model set up in that paper.
A key feature to branching and merging correctly in a version control system is keeping the roles of the branches consistent and separate. Do not let your maintenance merge into your mainline, nor your feature flow into the maintenance.
The basic roles of branches are mainline, development, maintenance, accumulation, and packaging. While sometimes these can be combined (for example, the simple 'everything in trunk one developer setup'), when working in groups and more complex environments, a clear separation of roles is often needed.
You've got two feature branches... A and B. Each feature branch should be branched from the mainline. Likewise, each bug fix should be branched from the mainline.
The main programming (reason for the branch) isn't done, but a bug fix needs to be copied across multiple branches and trunk
In this case, feature branch A also contains a bug fix, and part of branch A needs to get merged through the system.
The best practice would have been to branch from mainline, do the maintenance (bug fix) and merge that into the mainline, and then pick up the changes from mainline into the various branches that need it as necessary.
I'm going to assume that the mainline as a policy of "only working code." One shouldn't break the build from the mainline. Likewise, non-working code in mainline means that any branches from that point start out broken.
To resolve what is the case here, the best approach would be to create another branch - an accumulation branch. This keeps any branches done from mainline while the verification of the bug fix in the accumulation branch from being broken. To do this:
- branch mainline to an accumulation branch
- merge the bug fix from branch A into the accumulation branch
- merge the accumulation branch back into main
- propagate the fixes in mainline back to the other branches
The key for a separate branch is to in effect make a maintenance branch that only contains the bug fix, and go from there. This lets you make sure that the branch is done correctly without breaking the mainline and make any additional tweaks for making sure that the bug fix doesn't break anything else.