Using your own tool to help handle Bazaar (bzr) Conflicts

Written . In Technology. Tagged Bazaar, Tool, and Version Control.

When you encounter a conflict using bazaar, you are given three extra files to help you resolve the conflict. For example, lets say you have a file called someText.txt in your repository that you are working on, and someone has worked on it and checked in his changes while you are working on it. Before you do a bzr commit to commit your changes, you have to do a bzr update to get your partner’s changes. If there are conflicts within the file bzr will create someText.txt.BASE, someText.txt.THIS, and someText.txt.OTHER.

Here is an explanation of what each is:

<file name>
This initially lists the conflicts. When you are done the final resolution goes in this document.
<file name>.BASE
This contains the state the file was in when you started working on it.
<file name>.THIS
This should contain your changes to the file.
<file name>.OTHER
This contains the changes done to the file while you were working on it.

Bazaar does not give you tools to visualize the conflict, but bazaar lets you use your own.

To do this, you should first install the Bazaar extmerge plugin.

ExtMerge Plugin

Installation

Here is how you install the plugin: (original instructions)

  • Open up a command line window
  • Go to your bazaar plugins directory (if you use the windows stand-alone install it’s at C:\Program Files\Bazaar\plugins)
  • Do a bzr branch lp:bzr-extmerge extmerge

Configuration

The extmerge plugin is already setup to use kdiff3, xxdiff and opendiff when you install it (assuming they are in your PATH environment variable). However, what if you want to use a different tool? I didn’t find much documentation describing how to setup extmerge with another tool, so here is how you accomplish this.

  • Go to your %APPDATA%\Bazaar\2.0 directory
    • On Win Vista it is C:\users\<user name>\AppData\Bazaar\2.0
    • On Win XP it’s C:\Documents and Settings\<user name>\Application Data\bazaar\2.0
  • Open bazaar.conf. If it’s not there, create it.
  • Add the following line to the file: external_merge="<path to your tool> <options>"

The external_merge="<path to your tool> <options>" will tell the extmerge plugin how to run your tool. In the <options> portion you must specify the files for your tool to open. Here’s a list of what extmerge will replace in the <options> portion with the appropriate files.

  • %b = base (foo.BASE)
  • %t = this (foo.THIS)
  • %o = other (foo.OTHER)
  • %r = resolved file (aka output file) (foo)
  • %T = this (foo.THIS), a temporary copy of foo.THIS; will be used to overwrite ‘foo’ if the merge succeeds

DiffMerge with ExtMerge Plugin

I use DiffMerge so in my bazaar.conf I have:

external_merge="C:/Program Files/DiffMerge/DiffMerge.exe -nosplash -r %r -t1 Base -t2 This -t3 Other %b %t %o"

Putting it all Together

So when you do run into a conflict:

  • Bazaar will notify you and create the three files with BASE, THIS, and OTHER at the tail of their file names.
  • To use your own tool, run bzr emerge <file name> or bzr emerge --all if you want to run your tool on all conflicts.
  • Then, use your tool to merge your changes by hand. Your work should be saved to <file name> not the other three files.
  • When you are that the conflict has been resolved, run bzr resolve <file name> or bzr resolve --all. This will remove the extra three files that with BASE, THIS, and OTHER at the tail of their file names for that file.
  • Finally, bzr commit your change.

External Resources