Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
539 views
in Technique[技术] by (71.8m points)

post - how to write a svn hook script

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..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 not svn. svnlook is faster and safer than svn. In fact, in pre-commit scripts, you have to use svnlook since you don't have a repository revision.

Here are some things to keep in mind about your post-commit hook:

  • You cannot change a revision, and don't try to commit changes. Your post-commit hook will end up calling itself. If you want your developers to follow certain parameters, you need to have a pre-commit hook that fails if the developers don't do it right.
  • When Subversion calls your post-commit hook, the PATH environment variable has been deleted. If you need to access another command or a file, you'll have to provide the full path yourself.
  • Subversion will pass you certain parameters from the command line. Not an actual command line, but it means you can find these parameters in ARGV. Two parameters will be passed to you:
    1. The repository path on the server (for the svnlook command).
    2. The revision of the repository.

Everything else you must deduce though svnlook (which you can run via the system 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...