hakre
hakre

Reputation: 198216

How to make svn diff ignoring some files?

I have a live and a test system. The software is using SVN for version control. The live version is a specific TRUNK revision.

Now I'd like to create a diff from the files in the test-system to the live system. I can do this with

# svn diff -r 12345

On the test box where 12345 is the revision of the live system. That works as intended, however the project has put it's config file under SVN as well and naturally the live system does not share the config with the test system so I need to exclude it.

I'm not that well with svn and it looks like that there is no switch to specifically exclude files/dirs.

I'm wondering if I need to write a script for the job checking for changed files first, filtering that list and then provide the PATHs to svn diff.

Upvotes: 4

Views: 4153

Answers (1)

hakre
hakre

Reputation: 198216

I created a little shell script that's able to list at least all modifications since a specific revision plus the local modifications:

$ ./svn-modified-since 10563

Code:

#!/bin/bash

LOCALBASE=$(svnversion -n|grep -oP "^\d+(?=M$)")

# echo "Local base revision: $LOCALBASE"

if [ ! $LOCALBASE ]
    then
        echo "Quit: No modifications in local copy found."
        exit
fi

TARGETBASE=$1

# echo "Target base revision: $TARGETBASE"

if [ ! $TARGETBASE ]
    then
        echo "Quit: No target base revision given."
        exit
fi

WORKPATH=$2

# files changed in working directory copy
FILES=`svn status $WORKPATH`

# files changed between working copy and foreign base revision
FILES="$FILES
`svn diff --summarize -r $TARGETBASE:$LOCALBASE $WORKPATH`"

echo "$FILES" | sort -u

Example output:

M       common_functions.php
M       config.php
M       locale/fr/LC_MESSAGES/fr.mo
M       locale/fr/LC_MESSAGES/fr.po
M       common_functions.php
?       tmp/surrogates.php
...

I can now filter that output with grep and use the filenames as parameters with xargs:

# ./svn-modified-since 10563 | grep -v "^\?" | grep -o "([^ ]+)$" | grep -v "config.php" | xargs svn diff --force -r 10563 > my.diff

To handle binary files like the LC_MESSAGES, I could get it to work with replacing the svn diff command:

svn diff --force --diff-cmd /usr/bin/diff -x "-au --binary" -r 10563

With

patch -p0 -i my.diff 

Upvotes: 1

Related Questions