I'm trying to write a post commit hook script for svn to export repository to team foundation server. (So when you commit a code, that latest version of the code gets copied to team foundation repo )
Only language I use is C++ and C and I have never written a script. Can anybody give me step by step instruction for this? which language to use, what to read etc... along with some example code possibly ??
Is it possible to write a hook script with c++? or should I learn how to use python or ruby etc..
You can find instructions on how to define a pre-commit hook here: http://wordaligned.org/articles/a-subversion-pre-commit-hook
The creation of a post-commit is similar to that instruction.
Once you have copied the post-commit template to a new file, you could simply add a line to call a program you have written in c++ and simply pass the arguments to your program.
It depends on what you are up to, but most of the time it is more time saving to use a scripting language as shell-script or python to do your job.
Here is a stackoverflow answer here with a sample for post-commit hook on windows, using native windows shell commands - https://stackoverflow.com/a/3630534/7984
You can write your hook using C or C++ if you like. Most people use Perl or Python.
The main thing is that
svnlook
should be used in your hook script and notsvn
. svnlook is faster and safer thansvn
. In fact, in pre-commit scripts, you have to usesvnlook
since you don't have a repository revision.Here are some things to keep in mind about your
post-commit
hook:pre-commit
hook that fails if the developers don't do it right.post-commit
hook, thePATH
environment variable has been deleted. If you need to access another command or a file, you'll have to provide the full path yourself.ARGV
. Two parameters will be passed to you:svnlook
command).Everything else you must deduce though
svnlook
(which you can run via thesystem
command. However, since you're actually writing things in C and C++, you might be able to use the built in Subversion API).Another possibility: Use a continuous build system like Jenkins to do the dirty work for you. You might find it easier to work through Jenkins instead of worrying how a post-commit hook might accomplish this task. One of the advantages of Jenkins is that when things go wrong, you're not sending back failed post-commit messages to the user (who is probably not at fault). Instead, you cat get a complete log of what happened, and alert the person who can actually fix the issue.
Here's a sample of one I wrote which is in Perl. Don't know if it'll do you any good.