#!/bin/bash
# Set the svn:ignore property in each subdirectory of a Subversion
# working directory, such that ucmpas-generated HTML files are ignored
# by "svn status". If there are any files (one per line ) listed in
# a file called .usvnignore in the respective directory, then add these
# as well.
#
# Usage:
# $ ucampas-svnignore        # process directories that existed at last commit
# $ ucampas-svnignore .      # process this directory only
# $ find . -type d | xargs ucampas-svnignore  # this directory and recurse
# $ ucampas-svnignore -r     # this directory and recurse
if [ $# -eq 1 -a "$1" = '-r' ] ; then
  DIRS=`find . -type d`
elif [ $# -gt 0 ] ; then
  DIRS=$*
else
  DIRS=". `svn ls -R | grep '/$'`"
fi
for d in $DIRS ; do (
  cd $d || exit
  shopt -s nullglob
  file=.usvnignore~$$
  rm -f $file
  for src in *-b.html ; do
    echo "${src%-b.html}.html" >>$file
  done
  for src in *-b.php ; do
    echo "${src%-b.php}.php" >>$file
  done
  [ -r .usvnignore ] && cat .usvnignore >>$file
  pwd
  if [ -e $file ] ; then
    svn propset svn:ignore -F $file .
    rm $file
  else
    svn propdel svn:ignore .
  fi
) ; done
