Tag Archives: semanticmerge

Using SemanticMerge with Visual Studio tools for Git

Microsoft recently released an updated version of its Visual Studio Tools for Git. These tools allow to create, branch and merge inside Visual Studio. In this article we will see how to configure Semantic Merge Tool as custom merge tool in Visual Studio.

When we create a new project inside Visual Studio and add it to version control, a new repository is created in our local folder. Visual Studio adds its custom diff & merge tool to the repository configuration, so for using Semantic Merge, we need to modify that.

What we need to do is simply edit the file called configuration placed inside our .git folder with our favourite text editor, add the following text (replace USERNAME with your own user):

[mergetool "MergeTool"]
path = C:/Users/{USERNAME}/AppData/Local/PlasticSCM4/semanticmerge/semanticmergetool.exe
cmd = \"C:/Users/{USERNAME}/AppData/Local/PlasticSCM4/semanticmerge/semanticmergetool.exe\" -b=\"$BASE\" -bn=\"$BASE\" -s=\"$REMOTE\" -sn=\"$REMOTE\" -d=\"$LOCAL\" -a -r=\"$MERGED\" -l=csharp -emt=\"\"\"C:/Users/{USERNAME}/AppData/Local/PlasticSCM4/semanticmerge/mergetool.exe\"\" -b=\"\"@basefile\"\" -bn=\"\"@basesymbolic\"\" -s=\"\"@sourcefile\"\" -sn=\"\"@sourcesymbolic\"\" -d=\"\"@destinationfile\"\" -dn=\"\"@destinationsymbolic\"\" -r=\"\"@output\"\" -t=\"\"@filetype\"\" -i=\"\"@comparationmethod\"\" -e=\"\"@fileencoding\"\"\" -edt=\"\"\"C:/Users/{USERNAME}/AppData/Local/PlasticSCM4/semanticmerge/mergetool.exe\"\" -s=\"\"@sourcefile\"\" -sn=\"\"@sourcesymbolic\"\" -d=\"\"@destinationfile\"\" -dn=\"\"@destinationsymbolic\"\" -t=\"\"@filetype\"\" -i=\"\"@comparationmethod\"\" -e=\"\"@fileencoding\"\"\"

And finally replace the default mergetool:

[merge]
tool = vsdiffmerge (before)

[merge]
tool = MergeTool (after)

After these simple steps, when we try to merge a branch and conflicts arise, we will get this window:

Capture

If we click on “Merge” our Semantic Merge tool will launch.

Happy hacking!.

More info at SemanticMerge.com

Semantic merge as the default merge tool with git on Windows

When working on a version control system like git, mercurial or plasticscm, branching and merging are part of our daily work. The merge operation may cause conflicts, and usually we must manually solve them using 3-way merge tools.

By default git won’t provide a tool for this operation, so in this article we will see how to configure an external tool (in our case our Semantic Merge toolsemanticmerge.exe) on git in the Windows platform.

Setting git configuration

One of the most common ways of setting the configuration is by using the git config command, for example:

git config --global core.editor emacs

Will set the default text editor. We have the –global modifier, that saves the configuration at user level, we will talk about the levels in the next section. This operation saves the following data in our configuration file:

[core]
    editor = emacs

Git stores the configuration in a .config file at three different levels:

  • repository level, located inside our local repository at .git\config (git config without extra modifiers)
  • user level, usually located at C:\Users\Me\.gitconfig on windows) (–global modifier)
  • system level, located in our git instalation folder, for example C:\Program Files\Git (–system modifier)

Setting the custom merge tool

Now it’s easy to set the merge tool inside the configuration file. The first thing we need is to define a name for our tool:

[merge]
    tool = SemanticMerge

Afterwards, for the selected tool, we must define the path for the executable that will be launched, inside it’s own section:

[mergetool "SemanticMerge"]
    path = C:/Program Files/PlasticSCM4/semanticmerge/semanticmergetool.exe

Aditionally, we must set a couple more parameters:

[mergetool "SemanticMerge"]
    keepBackup = false
    trustExitCode = false

Finally, we must set the parameters that will be passed to the tool, in this case, the source files,  destination and base.

[mergetool "SemanticMerge"]
    ...
    cmd = \"C:/Program Files/PlasticSCM4/semanticmerge/semanticmergetool.exe\" -b=\"$BASE\" -d=\"$LOCAL\" -s=\"$REMOTE\" -r=\"$MERGED\" -l=csharp -emt=\"mergetool.exe -b=\"\"@basefile\"\" -bn=\"\"@basesymbolic\"\" -s=\"\"@sourcefile\"\" -sn=\"\"@sourcesymbolic\"\" -d=\"\"@destinationfile\"\" -dn=\"\"@destinationsymbolic\"\" -r=\"\"@output\"\" -t=\"\"@filetype\"\" -i=\"\"@comparationmethod\"\" -e=\"\"@fileencoding\"\"\" -edt=\"mergetool.exe  -s=\"\"@sourcefile\"\" -sn=\"\"@sourcesymbolic\"\" -d=\"\"@destinationfile\"\" -dn=\"\"@destinationsymbolic\"\" -t=\"\"@filetype\"\" -i=\"\"@comparationmethod\"\" -e=\"\"@fileencoding\"\"\"

This is the final result:

[merge]
    tool = SemanticMerge

[mergetool "SemanticMerge"]
    path = C:/Program Files/PlasticSCM4/semanticmerge/semanticmergetool.exe
    keepBackup = false
    trustExitCode = false
    cmd = \"C:/Program Files/PlasticSCM4/semanticmerge/semanticmergetool.exe\" -b=\"$BASE\" -d=\"$LOCAL\" -s=\"$REMOTE\" -r=\"$MERGED\" -l=csharp -emt=\"mergetool.exe -b=\"\"@basefile\"\" -bn=\"\"@basesymbolic\"\" -s=\"\"@sourcefile\"\" -sn=\"\"@sourcesymbolic\"\" -d=\"\"@destinationfile\"\" -dn=\"\"@destinationsymbolic\"\" -r=\"\"@output\"\" -t=\"\"@filetype\"\" -i=\"\"@comparationmethod\"\" -e=\"\"@fileencoding\"\"\" -edt=\"mergetool.exe  -s=\"\"@sourcefile\"\" -sn=\"\"@sourcesymbolic\"\" -d=\"\"@destinationfile\"\" -dn=\"\"@destinationsymbolic\"\" -t=\"\"@filetype\"\" -i=\"\"@comparationmethod\"\" -e=\"\"@fileencoding\"\"\"

Now, if we generate a conflict, our semantic merge tool will launch for resolving it, displaying a message like this:

git mergetool
Merging:
base.cs

Normal merge conflict for 'base.cs':
  {local}: modified file
  {remote}: modified file

Hit return to start merge resolution tool (SemanticMerge):

Happy hacking!

Further reading