Reputation: 11
Is it possible to get file properties from post-commit hook?
I want to check all changed files, if one or more of them have my specific property, I want to perform some action.
svn propget my:property file.txt
^ this reads properties only from local working copy, but i don't have it in the env where hook is executed.
Thanks!
Upvotes: 1
Views: 2515
Reputation: 107040
When you use a hook, you should use the svnlook
command and not the svn
command.
TXN=$1
REPOS=$2
SVNLOOK="/usr/bin/svnlook"
"$SVNLOOK" pget -t $TXN $REPOS my:property /path/in/repository
You can get a list of files that have been changed via the svnlook changed
command:
/usr/bin/svnlook changed -t $TXN
This will provide you with the change type (U = Updated, D = Deleted, M = Modified, R = Replaced) and the name of the file. You can use that file name with the svnlook pget
command to look at the property.
Maybe something like this:
$SVNLOOK changed -t $TXN | while read changeType fileName
do
$SVNLOOK plist -t $TXN -v $REPOS $fileName
done
One of the problems with shell is that you can't do loops in loops very easily. For example, it would be nice if I could do something with $SVNLOOK plist
, but I am already piping STDOUT to STDIN, so any output from svnlook plist
will affect my outer loop. You can do all sorts of weird stuff to use other file descriptors, but it's simply easier to use Python or Perl.
You also really can't change anything about the commit. You can't change a file or a file property. The only thing you can change is a revision property like svn:log
, and even that's not recommended.
Not sure what you had in mind, but be careful. Also understand that anything that can take too long will delay the user's commit as they wait for your post-commit script to run. I've seen people attempt to compile and run unit tests in Subversion hooks. In that case, you're better off using a continuous build system like Jenkins to do post commit processing.
You can take a look at my svn-watcher-hook to see how it's done. This is a Perl script, but it's not all that complicated, and I try to explain everything I do. It shouldn't be too hard to understand.
Upvotes: 1