Recently I had to face a limitation of subversion – you can set files and patterns for ignoring files (using svn:ignore) but you can not specify certain files or patterns for files to be included. In my situation, I wanted to build an Ivy repository and put only the ivy files under the version control cause all other artifacts could be rebuild using SCM.

So I came up with a simple bash script, which is run just before commit and is actually called from an ant script in a build environment:

#!/bin/bash
#
# adds only certain files to repository, adds
# all intermediate directories on their paths,
# it also works with empty space in path (except newline)
#
# @todo Add some bells and whistles!
 
REPO_NAME=<some_repo>
echo "Running $0 on" `date` "with $REPO_NAME"
 
# this file will help to limit the search, if it's modified on commit
# for example the log file of last commit, the idea here is to run 
# this script always before commit
REF_TIME_FILE=<some_file>
REP_PATH=/some/path/to/your/copies/root
 
FILE_PATTERN='ivy.xml*'
DIR=`pwd`
 
cd $REP_PATH
IFS_ORIG=$IFS
# this allows paths with whitespace, but not with newline
IFS=$'\n'
#IFS="$(echo)" another way to get newline
for ivy in `find ./ -newer $REF_TIME_FILE  -type f  -name "$FILE_PATTERN"  -print`
do
	echo "found fresh file $ivy"
	p=$ivy
	while [ $p != "." ]
	do 
			all_paths=${all_paths}${del}${p}
			p=${p%/*}	
			del=:
	done
done
 
IFS=$IFS_ORIG
#echo $all_paths | tr ':' '\n' | sort | uniq |  tr '\n' '\0' | xargs -0 -i echo {}
echo $all_paths | tr ':' '\n' | sort | uniq |  tr '\n' '\0' | xargs -0  svn add --non-recursive  2>&1 | grep "^A"
 
 
cd $DIR
echo "Finish $0 on" `date` "with $REPO_NAME"

It’s not a big deal but might help you to spare some time. There might be better ways to do it and I wonder if same can be done using “plain ant”.