Hi I was wondering if there is a way for the SVN server to automatically assign the svn:needs-lock property on any file that is binary and not textual.
We have a rather small developers team but resting on everyone to remember to set this property on newly created binary files doesn't make sense since it's very easy to forget such a thing.
Edit the svn config file and add an entry for auto props or use svn:auto-props
versioned property with SVN 1.8 and newer clients. Read SVNBook!
EDIT:
From SVN 1.8 the you can apply the svn:auto-props
property to the root path of your repository. See this release note and updated SVNBook 1.8 chapter.
Apache Subversion 1.8 introduced the Repository Dictated Configuration feature which requires SVN 1.8 client, but 1.8 server is not necessary because this is a client-side feature.
With Subversion 1.8, you can configure auto-props patterns within a repository using the new Subversion svn:auto-props
inherited property.
For example, set svn:auto-props
value to *.exe = svn:needs-lock=*
property on the root of your repository (or repository path that represents a root of a project). This will result into each newly added *.exe file having svn:needs-lock=*
property applied.
You can store multi-line values in Subversion properties, so you can add the following standard svn:needs-lock and MIME pattern to svn:auto-props
:
*.bmp = svn:mime-type=image/bmp;svn:needs-lock=*
*.gif = svn:mime-type=image/gif;svn:needs-lock=*
*.ico = svn:mime-type=image/x-icon;svn:needs-lock=*
*.jpeg = svn:mime-type=image/jpeg;svn:needs-lock=*
*.jpg = svn:mime-type=image/jpeg;svn:needs-lock=*
*.png = svn:mime-type=image/png;svn:needs-lock=*
*.tif = svn:mime-type=image/tiff;svn:needs-lock=*
*.tiff = svn:mime-type=image/tiff;svn:needs-lock=*
*.doc = svn:mime-type=application/x-msword;svn:needs-lock=*
*.docx = svn:mime-type=application/x-msword;svn:needs-lock=*
*.jar = svn:mime-type=application/octet-stream;svn:needs-lock=*
*.odc = svn:mime-type=application/vnd.oasis.opendocument.chart;svn:needs-lock=*
*.odf = svn:mime-type=application/vnd.oasis.opendocument.formula;svn:needs-lock=*
*.odg = svn:mime-type=application/vnd.oasis.opendocument.graphics;svn:needs-lock=*
*.odi = svn:mime-type=application/vnd.oasis.opendocument.image;svn:needs-lock=*
*.odp = svn:mime-type=application/vnd.oasis.opendocument.presentation;svn:needs-lock=*
*.ods = svn:mime-type=application/vnd.oasis.opendocument.spreadsheet;svn:needs-lock=*
*.odt = svn:mime-type=application/vnd.oasis.opendocument.text;svn:needs-lock=*
*.pdf = svn:mime-type=application/pdf;svn:needs-lock=*
*.ppt = svn:mime-type=application/vnd.ms-powerpoint;svn:needs-lock=*
*.ser = svn:mime-type=application/octet-stream;svn:needs-lock=*
*.swf = svn:mime-type=application/x-shockwave-flash;svn:needs-lock=*
*.vsd = svn:mime-type=application/x-visio;svn:needs-lock=*
*.xls = svn:mime-type=application/vnd.ms-excel;svn:needs-lock=*
*.zip = svn:mime-type=application/zip;svn:needs-lock=*
It should be noted that the auto props method has to be configured on each SVN client being used. So when you're setting up a new developer, or an existing developer on a new machine, you have to remember to perform this configuration.
If you are all using TortoiseSVN, you can set the tsvn:autoprops property on the base folder of each checkout and it will be honoured by all TortoiseSVN clients.
If you really want to nail it, you'll need to put a pre-commit hook in each repository. The enforcer script might be easily tooled for this.
If you have any python-fu, RepoGuard (the successor to SVNChecker) looks like it could be useful too.
No matter which you pick, there's no way to retroactively apply the property to existing files in the repository, I think. You can probably enforce it on the next commit of the file, however.
There's a page on this Subversion wiki that describes all the different options on how to automatically add needs-lock and how to guarantee it has been set. The page also gives example scripts and configuration details:
http://www.orcaware.com/svn/wiki/Automatic_lock-modify-unlock
Use a pre-commit hook
#!/bin/bash
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
ICONV=/usr/bin/iconv
SVNLOOKOK=1
# Check files for svn:needs-lock property
# Exit on all errors.
set -e
echo "`$SVNLOOK changed -t "$TXN" "$REPOS"`" | while read REPOS_PATH
do
if [[ $REPOS_PATH =~ (A|M|U)[[:blank:]]{3}(.*)\.(.*) ]]
then
if [ ${#BASH_REMATCH[*]} -ge 2 ]
then
FILENAME=${BASH_REMATCH[2]}.${BASH_REMATCH[3]};
# Make sure every file has the svn:needs-lock property set
if [ "" == "`$SVNLOOK propget -t \"$TXN\" \"$REPOS\" svn:needs-lock \"$FILENAME\" 2> /dev/null`" ]
then
ERROR=1;
echo "" >&2
echo "svn:needs-lock property has to be set on \"$FILENAME\"" >&2
echo "" >&2
fi
fi
fi
test -z $ERROR || (exit 1)
done
# All checks passed, so allow the commit.
exit 0
and a pre-lock hook
#!/bin/bash
REPOS="$1"
PATH="$2"
USER="$3"
# If a lock exists and is owned by a different person, don't allow it
# to be stolen (e.g., with 'svn lock --force ...').
# (Maybe this script could send email to the lock owner?)
SVNLOOK=/usr/bin/svnlook
GREP=/bin/grep
SED=/bin/sed
LOCK_OWNER=`$SVNLOOK lock "$REPOS" "$PATH" | \
$GREP '^Owner: ' | $SED 's/Owner: //'`
# If we get no result from svnlook, there's no lock, allow the lock to
# happen:
if [ "$LOCK_OWNER" = "" ]; then
exit 0
fi
# If the person locking matches the lock's owner, allow the lock to
# happen:
if [ "$LOCK_OWNER" = "$USER" ]; then
exit 0
fi
来源:https://stackoverflow.com/questions/711053/automatically-add-svnneeds-lock