eclipse-capella / capella

Open Source Solution for Model-Based Systems Engineering
https://mbse-capella.org
Eclipse Public License 2.0
232 stars 96 forks source link

EMF Diff/Merge produces broken links when resolving Git conflicts on fragmented models #2725

Open Wuestengecko opened 11 months ago

Wuestengecko commented 11 months ago

Hi! I'm one of the engineers at DB, where we use Capella in different internal projects. In one of them, we encountered an interesting issue with the EMF Diff/Merge tool when it comes to Git merge conflicts in combination with fragmented models.

After performing the merge, some of the links that came in from "their side" (in git terminology) no longer use the correct relative workspace file paths. Instead, the link seems to point to somewhere in the git index, which - when opening the model afterwards - no longer exists.

We managed to reproduce the issue on our public "coffee machine" demo model. Compare the following working FunctionRealization:

https://github.com/DSD-DBS/coffee-machine/blob/4a2569b73222255ec380d3607f90421675d8487d/fragments/SA.capellafragment#L46-L48

grafik

With this non-working version after using the merge tool:

https://github.com/DSD-DBS/coffee-machine/blob/3ba35b1888a23be66fa632621cd138d79851efdf/fragments/SA.capellafragment#L46-L48

grafik

Steps to reproduce:

  1. Make sure you have at least two fragments. In the demo model, we have fragmented out OA and SA, but in production we saw it in SA→LA realizations as well (with all layers fragmented out). This is the index-links/base branch.
  2. Also make sure you have a diagram in the airdfragment file that you'll later create the link in. In our model, we already have the "[SAB] make coffee" diagram, which is defined in SA.airdfragment.
  3. For "their side" (the "incoming changes"), open the "[SAB] make coffee" diagram and add a note to it (to provoke a conflict later). Create a new OperationalActivity (we called it "make delicious drinks"), and add it to the "realized functions" of "make coffee". (This is the index-links/right branch.)
  4. For "our side", simply change the same diagram as in the previous step. We did so by renaming "make coffee" to "make black water" and moving and resizing its box a little. (This is index-links/left.)
  5. Make sure you're on "our" branch, and then merge "their" branch using the Capella GUI. The Git integration should inform you about the conflicts, and mark the airdfragment as a conflicted file in the project explorer.
  6. Open EMF Diff/Merge by right clicking the conflicted airdfragment, then choosing Team > Merge Tool. Confirm the default settings.
  7. Make sure to at least accept the new link (the FunctionRealization from step 3) that came in and should be therefore marked in blue. (If it's red, you need to switch branches and the merge the other way round.) Then "ignore" the name change, so that it stays "make black water" instead of reverting back to "make coffee". The other changes don't seem to matter at all, so you can simply accept everything from incoming. (This is index-links/merged.)

You should now have a Git history that looks similar to this:

*   FFFFFFF The merged changes (HEAD -> index-links/merged)
|\
* | AAAAAAA Our side (index-links/left)
| * 1111111 Their side (index-links/right)
|/
*   0000000 The common ancestor (index-links/base)
|   (previous history is not relevant)

(Use git log --format=oneline --graph to double check, and make sure that "their changes" come in from the right. The Repository History view in Capella ignores this ordering when drawing the graph.)

Importantly, "our side" and "their side" must be parallel branches that both have the base commit as their immediate and only parent commit.

When opening the model now and inspecting the "make coffee" / "make black water" SystemFunction (depending on whether you accepted "our" or "their" name), you'll notice that the "realized functions" says "undefined" instead of "make delicious drinks" again. When inspecting the XML, you will see a broken link with an index: prefix.

Affected versions: We successfully reproduced this on Capella 6.0 and 6.1, using the steps described above.

vik378 commented 11 months ago

Just a few more words regarding the effect / criticality of this issue - the effect is that almost all of the changes related to traceability (realization links) are broken silently. In Capella you will see that an object is realized by "operational capability" but that is it.

Diff/merge with git is essential functionality in our context and this issue currently endangers a few running projects that were not allowed to use Team4Capella - basically any project with strict change control requirements (under assumption that EMF diff/merge is a trustworthy core technology). We would love to see some root cause analysis and solution options as well as eager to help resolving this issue.