Since I started using git, every time I need to use Subversion again I suffer. The output of `git diff` is so nice compared to the one produced `svn diff` that it hurts. I've alredy been struggling with that previously.
Now I think I've achieved the perfect solution to make `svn diff` behave just like `git diff`. I've documented it in this post hoping to help other poor souls like me who still have to use Subversion now and then.
Step 1: install colordiff. It's installed on Debian, so the installation required me no effort at all.
Step2 (optional): configure colordiff to use your preferred set of colors. My ~/.colordiffrc contains the following, to match the same colors used by default by `git diff`:
banner=no
color_patches=no
plain=off
newtext=darkgreen
oldtext=darkred
diffstuff=white
cvsstuff=darkyellow
Step 3: create a script to be called by Subversion when running `svn diff`. In my case, I called it svn-diff and stored it in ~/bin (which is in my $PATH), but you can put it in /usr/local/bin or any other directory that is in your $PATH. The contents of ~/bin/svn-diff is the following:
#!/bin/sh if test -t 1; then colordiff -u -L "${3}" -L "${5}" "${6}" "${7}" | less -FRSX else colordiff -u -L "${3}" -L "${5}" "${6}" "${7}" fi
The conditional tests whether the standard output is connected to a terminal; in the case it is not (e.g. you are redirecting to a file to generate a patch), you do not want to pipe the output to less. The -FRSX options will make less behave exactly as it does when invoked by `git diff`. I've got this tip here.
After creating the script, you need to make it executable:
$ chmod +x ~/bin/svn-diff
Step 4: tell Subversion to use your script instead of plain diff on `svn diff`. To do that, locate the "helpers" section in your Subversion configuration file (~/.subversion/config), and set the diff-cmd setting to the name you gave to your custom script (svn-diff in my case):
[helpers]
diff-cmd = svn-diff
That's it! Now you can almost forget you are using Subversion (until you need to do some merging).
update: added conditional to the svn-diff script to avoid piping to less when redirecting standard output to a file when creating patches.
0sem comentários ainda