On Aug 31, 2010, at 12:59, Tech Geek wrote:

> Let's say if somehow we do manage to implement this hook before the 
> development/project begins then after the first revision/commit the 
> project.xml file will also be committed (because we reject any commit if that 
> file is not there). Now let's say the development further goes on and now it 
> is time to commit second time. At this time our hook script again will check 
> for the presence of project.xml file and will also check if the project.xml 
> got changed or not. If it got changed that means the developer did produce a 
> new version of this file and we accept the commit. If the version of the file 
> did not change then we reject it.

Here's a pre-commit hook script that requires that project.xml be in every 
commit. As we've discussed, I don't think this is what you really want, but 
it's what you say you want, so here it is and you can try it out and see what 
happens. I realize you are running Subversion on a Windows server, and this 
script is designed for UNIX or Mac OS X, but I am not a Windows programmer so I 
cannot write you a batch script. But perhaps seeing this script will give you 
ideas for how to write a batch script that does the same thing.



#!/bin/sh

# Parameters the Subversion server passes to this script.
REPOS="$1"
TXN="$2"

# Binaries we use.
AWK="/usr/bin/awk"
SVNLOOK="/usr/bin/svnlook"

# Abort if this file is not Added or Updated by this commit.
REQUIRED_FILE="project.xml"

MATCHED=$($SVNLOOK changed -t "$TXN" "$REPOS" \
    | $AWK '/^[AU_][U ]  (.*\/)?'$REQUIRED_FILE'$/ { print }')

if [ -z "$MATCHED" ]; then
    echo "$REQUIRED_FILE was not part of the commit." 1>&2
    exit 1
fi

# All checks passed, so allow the commit.
exit 0





Reply via email to