nhansen
nhansen

Reputation: 11

Duplicated code during Mercurial merge

We have a fair number of ASP.Net (C#) web sites using Mercurial. Occasionally, "something" goes wrong with a merge, and a small number of lines are duplicated into the resulting file; however, there was no merge conflict noted during the merge.

The lines that are duplicated are generally very "generic" lines like block closures (braces, closing tags, etc.). In some cases, they cause compiler errors; in others, they cause JS failures; in others, just invalid markup that causes browser compatibility issues.

We have a number of people who collaborate on projects, and they often branch off one another's branches, merge between branches, and so on long before merging back into one of the "main" branches (one for the test site, and another for the production site).

The problem seems to happen most commonly when two branches are started independently, merged at some point, and then both independently merged back into the test site main branch. We hypothesize that since the second branch to merge into test has no history of being merged into test, it is including all the change sets that were already merged by the first branch merge, and in some cases, not detecting the duplicate because the context is too generic to place it properly, and just including it.

Does this problem have a name? Is it a known issue? Is there a procedure to follow to avoid it? It seems that it would have to be a common issue, but I cannot seem to find any information on it.

We've considered adding hooks to forbid merges if an ancestor has a descendant that has already been merged into the target branch, but that will likely be very slow considering the size of the project and the number of branches involved.

We've also considered adding hooks to enforce some sort of "depth and lineage" control so that merges can only happen back to parent branches, not to sibling, cousin, or grandparent branches, but this will dramatically disrupt several people's collaboration and workflow.

Thoughts?

Upvotes: 1

Views: 75

Answers (1)

Marcos Zolnowski
Marcos Zolnowski

Reputation: 2807

however, there was no merge conflict noted during the merge.

Well, I would say someone is solving the conflicts very badly.

How is this possible? They are not lazy, right?

I was playing with graft, and my diff tool did something stupid. For example, file index.html, in the default branch:

</div>
</div>
</body></html>

Branch A:

</div>
<br></div>
</body></html>

Branch B:

<p></div>
</div>
</body></html>

Just one more commit for branch B:

<p>a</div>
</div>    
</body></html>

Merging branch A with default, fine.

When grafting B on default, I get:

<p>a</div>
</div>
<br></div>
</body></html>

But merging B with default:

<p>a</div>
<br></div>
</body></html>

Several hours later, I understand that hg graft does not work like merge. I need to pass both commits of branch B to hg graft.

Probably, your problem is not related to this, I guess your team only uses hg merge. But I still believe that someone must be, someway, merging things wrongly.

Upvotes: 1

Related Questions