April 22, 2010

Surround SCM with OS X FileMerge

Surround SCM
For my first blog post I thought it would be a good idea to post about how I use Surround SCM. I always find it interesting to see how developers actually use the tools they develop. When I'm using Surround SCM on my Mac I prefer to use FileMerge. What is FileMerge, you ask? FileMerge is a free utility that comes bundled with the Apple Developer Tools, it allows you to view the differences between files, as well as merge the contents of different file versions. If you've done any development on a team, you know that a tool like this can be your Swiss Army knife. Surround SCM comes packed with Guiffy, a tool similar to FileMerge. Guiffy will do everything that FileMerge can do, it just does not look as nice. If you're still not convinced, take a look at the two screenshots below. It's not just eye candy, it's actually easier and more intuitive to use.

Surround SCM Diff with FileMerge(FileMerge performing difference operation)

FileMerge 3-way merge(FileMerge performing 3-way merge operation)

Ready to give FileMerge a try? Create a bash script on your local machine and insert the contents from the script at the bottom of this post. Don't forget to set your script's permissions (chmod 755)! Fire up your Surround SCM Client, open the "User Options" dialog (Tools -> User Options), select the "Diff/Merge" section from the pane on the left side, and double click "All other text files" (Diff) from the table on the right. Choose "Selected Application" from the dropdown and enter the following into the "Selected application" field: "/path/to/script.sh" -diff "%1" "%2" (beware, copy/paste will insert the wrong quotes). Click "OK" to close the dialog. Now repeat the process for "All other text files" (Merge), using the -2way and -3way arguments accordingly (see screenshot below). For the "Three-way merge" also add "%3" to the end of the field.

That's it, you're done! Give FileMerge a try and let me know what you think. Happy merging! Here is the bash script mentioned above. Again, don't forget to set execute permissions on the script.
#!/bin/bash
OPENDIFF="/Developer/usr/bin/opendiff"
COMMAND_ARG=$1
if [ $COMMAND_ARG == "-diff" ]; then
# Open in BG so SCM Client does not sit and wait
$OPENDIFF "$2" "$3" &
elif [ $COMMAND_ARG == "-2way" ]; then
# Open in a pipe to prevent it from returning before it terminates
`$OPENDIFF "$2" "$3" -merge "$3"`
elif [ $COMMAND_ARG == "-3way" ]; then
# Open in a pipe to prevent it from returning before it terminates
`$OPENDIFF "$2" "$3" -ancestor "$4" -merge "$3"`
else
echo "Please specify a command: -diff, -2way or -3way"
fi;