MikeFHay
MikeFHay

Reputation: 9013

How do I exclude certain files from a svn diff?

I'm using svn diff -c 789 to show the changes made in revision 789 of our software, but it's showing a lot of files I don't care about, in particular test files. How can I exclude certain files from the diff, for example all files which match the pattern *Test.java?

I'm using Cygwin on Windows, if that's important.

Upvotes: 11

Views: 19911

Answers (3)

Gerrit Griebel
Gerrit Griebel

Reputation: 453

This is what I did:

FILES=$(svn status some_dir|grep ^M|cut -b2-|grep -v dir_to_remove)
test -n "$FILES" && svn diff "$FILES"

Upvotes: 1

Victor
Victor

Reputation: 3978

By the way, remember that the svn diff commands works as others commands following the in Unix modular philosophy where each command has a standard input and ouput. You can genare your own customize script for listing files you want to include redirect the output of that script to the svn diff commands via the use of pipes and then redirect your output of diff to the desired file you want to create. Just to be more clear : follow this example

svn diff `cat change_list.txt` > patch.diff

in change_list.txt the are the files you want to include in the diff separated by space. For example, the content of the file could be this :

"domain/model/entity.java"

"web_app/controllers/controller.java"

So following this approach, the only dificult of your problem is reduced to implement a script that like Adam generously wrote above.

Hope it helps!

Vic.

Upvotes: 4

Adam Siemion
Adam Siemion

Reputation: 16039

As svn diff does not allow to exclude specific files from the output, below is a BASH script that can be used to achieve that.

It takes two arguments:

  • file with an svn diff output
  • pattern of the files to be excluded (e.g. test/*)

and prints the content of the file without the changes from the files matching pattern.

#!/bin/bash

test $# -ne 2 && echo "Usage: $0 svn_diff_file exclude_pattern" && exit 1

ignore=0
while IFS= read -r line; do
    echo $line | grep -q -e "^Index: " && ignore=0
    echo $line | grep -e "^Index: " | grep -q -e "^Index: $2" && ignore=1
    test $ignore -eq 0 && echo "$line"
done < $1

Update

I just came across a tool that does this job: filterdiff. It's usage is very similar to the above script:

filterdiff svn_diff_file -x exclude_pattern

Upvotes: 8

Related Questions