[ACCEPTED]-Automatically add svn:needs-lock-svn-propset

Accepted answer
Score: 22

Apache Subversion 1.8 introduced the Repository Dictated Configuration feature 12 which requires SVN 1.8 client, but 1.8 server is not necessary 11 because this is a client-side feature.

With 10 Subversion 1.8, you can configure auto-props 9 patterns within a repository using the new 8 Subversion svn:auto-props inherited property.

For example, set svn:auto-props value to *.exe = svn:needs-lock=* property 7 on the root of your repository (or repository 6 path that represents a root of a project). This 5 will result into each newly added *.exe file having svn:needs-lock=* property 4 applied.

You can store multi-line values 3 in Subversion properties, so you can add 2 the following standard svn:needs-lock and 1 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=*
Score: 14

Edit the svn config file and add an entry 5 for auto props or use svn:auto-props versioned property 4 with SVN 1.8 and newer clients. Read SVNBook!

EDIT:

From SVN 3 1.8 the you can apply the svn:auto-props property to the 2 root path of your repository. See this release note and 1 updated SVNBook 1.8 chapter.

Score: 5

It should be noted that the auto props method 18 has to be configured on each SVN client 17 being used. So when you're setting up a 16 new developer, or an existing developer 15 on a new machine, you have to remember to 14 perform this configuration.

If you are all 13 using TortoiseSVN, you can set the tsvn:autoprops property on the 12 base folder of each checkout and it will 11 be honoured by all TortoiseSVN clients.

If 10 you really want to nail it, you'll need 9 to put a pre-commit hook in each repository. The 8 enforcer script might be easily tooled for this.

If 7 you have any python-fu, RepoGuard (the successor 6 to SVNChecker) looks like it could be useful too.

No 5 matter which you pick, there's no way to 4 retroactively apply the property to existing 3 files in the repository, I think. You can 2 probably enforce it on the next commit of 1 the file, however.

Score: 2

There's a page on this Subversion wiki that 5 describes all the different options on how 4 to automatically add needs-lock and how 3 to guarantee it has been set. The page also 2 gives example scripts and configuration 1 details:

http://www.orcaware.com/svn/wiki/Automatic_lock-modify-unlock

Score: 2

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

0

More Related questions