Часто временные файлы создаются в результате компиляции или открытия файла проекта. Я хочу, чтобы SVN игнорировал (а не версию) эти файлы там, где они были созданы, без необходимости игнорировать их глобально, так как разные программы / процессы могут создавать их в других местах, и им может потребоваться управление версиями (то же расширение с другим типом файла). Какой лучший способ сделать это, используя Bash и SVN? Достаточно ли следующего скрипта bash, который я создал?
# Recursively find, remove, and set svn:ignore on files or folders.
# For safety, you must perform an svn status and an svn commit yourself.
#
# $1 is the pattern to ignore
# $2 is the starting directory (optional)
# $3 is a flag to remove the ignored files locally (optional)
#
# Example: recursive_svn_ignore "*.bak" . --remove
#
recursive_svn_ignore ()
{
cd "$2";
svn info > /dev/null 2>&1;
if [ "$?" -ne "0" ]; then
echo "Skipping `pwd` because it is not under version control.";
return 1;
fi;
# Check if pattern matches
ls -l $1 > /dev/null 2>&1;
if [ "$?" = "0" ]; then
for f in "$1"; do
if [ "$3" = "--remove" ]; then
# Remove file from working directory and repository
svn rm --force -q $f;
else
# Remove file from repository only
svn rm --force --keep-local $f;
fi;
done
echo "Adding "$1" in `pwd` to svn:ignore list";
svn propget svn:ignore . > svnignore.tempfile;
echo "$1" >> svnignore.tempfile;
svn propset -q svn:ignore -F svnignore.tempfile .;
rm svnignore.tempfile;
fi;
# Recurse
for d in *
do
if [ -d "$d" ]; then
( recursive_svn_ignore "$1" "$d" )
fi;
done
}
Как подсказывает @ david-van-brink, использование find
значительно упрощает работу за счет исключения рекурсии. Это то, что я придумал.
#!/bin/bash
# Recursively find and set svn:ignore on files or folders.
# If the file was already version it will be removed from the repository
# and keep the local copy (can be overridden).
# This does not perform the final commit so you can review the changes
# using svn status.
#
# $1 pattern to ignore
# $2 remove the ignored files locally as well (optional)
#
# Example: find_svn_ignore "*.bak" . --remove
#
for a in `find . -name $1`
do
svn info ${a%/*} > /dev/null 2>&1;
if [ "$?" -ne "0" ]; then
echo "Skipping ${a%/*} because it is not under version control.";
continue;
fi;
echo "Ignoring ${a##*/} in ${a%/*}";
svn propget svn:ignore ${a%/*} > svnignore.tempfile;
echo "$1" >> svnignore.tempfile;
svn propset -q svn:ignore -F svnignore.tempfile ${a%/*};
rm svnignore.tempfile;
if [ "$2" = "--remove" ]; then
# Remove file from working directory and repository
svn rm --force -q ${a##*/};
else
# Remove file from repository only
svn rm --force --keep-local ${a##*/};
fi;
done