title: Mercurial and merge tools?
body: <p>Is Mercurial always using the external merge tools when two branches that are merging have changes to the same file?</p>
  
  <p>Or does it first see if it can merge the file itself, and only punting to the external tool if it can't?</p>
  
  <p>The reason I'm asking is that I am (once again) re-reading the <a href="http://hginit.com/00.html" rel="noreferrer">tutorial written by Joel Spolsky on Mercurial</a> and one thing he says, when comparing how Subversion and Mercurial is merging is that:</p>
  
  <blockquote>
    <p>By contrast, while we were working separately in Mercurial, Mercurial was busy keeping a series of changesets. And so, when we want to merge our code together, Mercurial actually has a whole lot more information: it knows what each of us changed and can reapply those changes, rather than just looking at the final product and trying to guess how to put it together.</p>
  </blockquote>
  
  <p>Only, my experience tells me that it seems to involve the external merge tool when two branches have changes to the same files. And thus, doesn't that render the above argument incorrect?</p>
  
  <p>Or should I interpret this as follows:</p>
  
  <ul>
  <li>Subversion only merges the final state of the two branches, and has more work to do in a single unit</li>
  <li>Mercurial merges each changeset individually, which allows it to work with smaller units of changes, with higher chance of merge success</li>
  </ul>
  
  <p>Can someone shed some light on this?</p>
  
  <hr>
  
  <p><strong>Edit</strong>: Let me give an example:</p>
  
  <pre><code>@echo off
  
  setlocal
  
  if exist repo rd /s /q repo
  
  md repo
  cd repo
  hg init .
  
  rem --- version 0 ---
  echo 1 &gt;test.txt
  echo 2 &gt;&gt;test.txt
  echo 3 &gt;&gt;test.txt
  echo 4 &gt;&gt;test.txt
  echo 5 &gt;&gt;test.txt
  hg add test.txt
  hg commit -m "v0"
  
  rem --- version 1 ---
  echo 1 &gt;test.txt
  echo 2 v1 &gt;&gt;test.txt
  echo 3 &gt;&gt;test.txt
  echo 4 &gt;&gt;test.txt
  echo 5 &gt;&gt;test.txt
  hg commit -m "v1"
  
  rem --- version 2 ---
  hg update 0
  echo 1 &gt;test.txt
  echo 2 &gt;&gt;test.txt
  echo 3 &gt;&gt;test.txt
  echo 4 v2 &gt;&gt;test.txt
  echo 5 &gt;&gt;test.txt
  hg commit -m "v2"
  
  rem --- merge ---
  hg update 1
  hg merge 2
  </code></pre>
  
  <p>This first creates a file with the following content:</p>
  
  <pre><code>1
  2
  3
  4
  5
  </code></pre>
  
  <p>Then it changes it to:</p>
  
  <pre><code>1
  2 v1
  3
  4
  5
  </code></pre>
  
  <p>Then it goes back to the initial version (changeset), and changes it to:</p>
  
  <pre><code>1
  2
  3
  4 v2
  5
  </code></pre>
  
  <p>Then it attempts to merge the two.</p>
  
  <p>Now, according to the (currently) single answer, this should not pose a problem, since the changes are not in conflict.</p>
  
  <p>However, at this point, Beyond Compare (my external merge tool) is invoked.</p>