#!/bin/zsh

svnstatus="`svn status`";

for line in ${(s:
:)svnstatus}; do
  state=`echo $line | awk '{ print $1 }'`;
  # look for files in the (C)onflicted state:
  if [ "x$state" = "xC" ]; then
    file=`echo $line | awk '{ print $2 }'`;
    dir=`dirname $file`;
    
    # use `svn info` to figure out the names of my file, the 
    # modified file my file is conflicting with, and the
    # common ancestor:
    ancestor=`svn info $file | grep "Conflict Previous Base File:" | awk '{ print $5 }'`;
    newfile=`svn info $file | grep "Conflict Current Base File:" | awk '{ print $5 }'`;
    myfile=`svn info $file | grep "Conflict Previous Working File:" | awk '{ print $5 }'`;
    
    opendiff $dir/$myfile $dir/$newfile -ancestor $dir/$ancestor -merge $file;
    # NOTE: opendiff returns immediately, so don't do anything 
    # that depends on the result of the merge... like `svn resolve`
  fi;
done


