Resolving merge conflicts in Azure DevOps via extension

Part of the role of source control is to ensure that any simultaneous updates to code and logic done in a collaborative development environment, do not override each other.

And in any case when this happens, a “Conflict” arises when Merging the Branch or raising a Pull Request. This would mean that someone will have to review the code in the source and target branches – potentially side-by-side – and decide which one to keep or how to merge the logic as one.

When using GIT repositories in Azure DevOps, solving Conflicts that arise within the Pull Request screen – might mean that one must go back to Visual Studio (or any IDE they are using). There they then merge the target branch into the local source branch to solve the conflicts there before pushing back the changes within the Pull Request (or raise a separate Pull Request afterwards).

However, one tool which I found helpful to reduce the steps required during such process is an extension named “Pull Request Merge Conflict Extension” by Microsoft DevLabs that can be installed on Azure DevOps.

Extension in Action

Let’s see an example below.

A SQL Post-Deployment exists in the VS Solution, that adds the following list of users to [Table].[UserDetails]. This Post-Deployment script is already part of the develop branch.

SET IDENTITY_INSERT [Table].[UserDetails] ON;

INSERT INTO [Table].[UserDetails] ([UserKey],[Name],[Surname])
VALUES
       ( 1, N'Alex', N'Smith'),
       ( 2, N'Dan', N'Brown'),
       ( 3, N'Mark', N'Black'),
       ( 4, N'Mike', N'Lee')

SET IDENTITY_INSERT [Table].[UserDetails] OFF;

GO

Two different members of the development team, each create a feature branch off the develop branch (“Branch#1” and “Branch#2”) and amend the same script within the different branches – by each adding a new line in the same line number on the separate branches.

In “Branch#1”, the first developer added the new row for “Pete Law”:

A PR for “Branch#1” has been raised, got approved and been merged to the develop branch.

In the meantime, the second developer, added a new user/line of code within the same line number.

As a PR is raised on “Branch#2”, to merge the work to develop branch (after the first developer has already done so), a conflict will arise as per below:

With the extension in DevOps, instead of solving the issue on the local “Branch#2” and push back again, one could go in through “Conflicts” tab and amend the changes straight in DevOps.

Once in “Conflicts” a merge script window at the bottom would be generated. In this case, this couldn’t be left as is, since we will end up with duplicate rows for UserKey 4, and also with two users having the same UserKey 5 – which will violate the IDENTITY_INSERT setting:

The bottom window tab can then be modified directly, the unneeded rows removed and one of the new Lines having the UserKey changed to 6:

This can then be merged as follows, which will put the script in a state that can be approved and PR-ed:

For each resolution done via the Conflicts tab, a comment is then generated within the main “Overview” tab of that branch – which will indicate that a conflict had occurred and has been resolved:

Implementing Extension

To implement this extension in DevOps, one can go to the Marketplace icon, do “Browse marketplace” and look for it by the search:

Alternatively click directly on this URL: https://marketplace.visualstudio.com/items?itemName=ms-devlabs.conflicts-tab

After choosing the Azure DevOps Organisation name from the dropdown, one can download and install.

When all is complete, the following screen will show:

To be able to install the extension yourself, one needs to be a member of the “Project Collection Administrators” or set as an organization Owner on DevOps. However, if one is not, one can always request the extension.

For more information about the services and industries Adatis can help with, please visit our main website here.