views:

326

answers:

2

Is it possible to set up TortoiseMerge (comes with TortoiseSVN) to be the external merge tool that pops up when you encounter a merge conflict using the "svn merge" commandline? I have tried setting my environment variable "SVN_MERGE" to point to TortoiseMerge.exe, but this doesn't seem to be enough. TortoiseMerge just pops up when I choose "l" (to launch an external tool) asking me what files I want to merge. I want this information to be pushed into the tool automatically.

Any ideas?

A: 

I don't know which version of Subversion you're using, so I'm going to try to refer to information in the most recent version of the Subversion documentation, for 1.6. (They add on that page that "if you bookmark or link to specific sections, those links may be invalidated by continuing development." But there is no stable version for 1.6.)

First, the bad news:

To use a merge tool, you need to either set the SVN_MERGE environment variable or define the merge-tool-cmd option in your Subversion configuration file (see the section called “Configuration Options” for more details). Subversion will pass four arguments to the merge tool: the BASE revision of the file, the revision of the file received from the server as part of the update, the copy of the file containing your local edits, and the merged copy of the file (which contains conflict markers). If your merge tool is expecting arguments in a different order or format, you'll need to write a wrapper script for Subversion to invoke.

The slightly better news is that Subversion has anticipated your question, somewhat. See the section Using External Differencing and Merge Tools; there are templates of external merge tool wrappers.

In your specific case, the TortoiseMerge documentation has an appendix explaining how to use it from the command line. The essential switches are /base, /mine, and /theirs, but you may want to use more (you're writing your own wrapper script, after all). TortoiseMerge also allows a "simplified form" of the command:

TortoiseMerge BaseFilePath MyFilePath TheirFilePath

The way to communicate the results of your merge back to Subversion is by writing the merged file to standard output and returning an appropriate value. This information is placed prominently in the wrapper templates in the Subversion manual.

JXG
Thanks. I eventually found that "Using External Differencing and Merge Tools" in the help.
Mike Gates
+1  A: 

Create a bat script that looks like this:

"c:\Program Files\TortoiseSVN\bin\TortoiseMerge.exe" /base:"%1" /theirs:"%2" /mine:"%3" /merged:"%4"

Then set the SVN_MERGE environment variable to that bat script:

set SVN_MERGE=c:\bin\svnmerge.bat
Jeremy