How do you get a pager in svn diff?

Viewed 2602

I’d like svn diff to display colored diff through a pager (just like git does). I’ve succeeded to get a colored diff by setting the diff-cmd in ~/.subversion/config:

diff-cmd = colordiff

Now I’d like to pipe the diff output through a pager, how do I do that? (Short of writing svn diff | less, of course.)

4 Answers

This would've been a comment, but I don't have enough rep. An improvement on schot's answer is to also fail before piping to less if the svn command fails for any reason, for example if you specify a file that doesn't exist. It also passes through the error code as well.

And this answer also adds progress format:

EDIT: An additional approvement is when piping/redirecting output to not use colordiff. To do this, do not change ~/.subversion/config and instead we need to use the --diff-cmd option.

function svn() {
    if [[ "$1" == "diff" && -t 1 ]]; then
        output=$(/usr/bin/svn --diff-cmd=colordiff "$@") || return $?
        [ "${output}" != "" ] && less -rM +Gg <<< "${output}";
    else
        /usr/bin/svn "$@"
    fi
}
Related