how to install svn post-commit hook
Asked Answered
G

2

15

I am running SVN on Linux. I was hoping to run auto deployment once committed. Based on my searching, it looks like svn post-commit might do the trick. But I couldn't find SVN post-commit from my SVN installation. So I wonder if it's a separate install? Is there any SVN post-commit hook that I can download and install?

Gaynor answered 28/9, 2011 at 0:56 Comment(0)
R
17

It's not a separate install. In your respository directory, there is a 'hooks' dir. You can find post-commit.tmpl, just modify the file and rename it to executable file according your os type.

Roadblock answered 28/9, 2011 at 1:0 Comment(2)
I copied pre-commit.pl and didn't work. After rename to pre-commit it works.Andromada
That's weird, but though the directory is mentioned everywhere, I never had «hooks» dir in my repository. More over, locate post-commit outputs nothing at all. Shall it work if I create hooks directory by myself? And should it be created in the .svn directory, or in the root directory of the repository?Lonilonier
O
22

First, you probably don't want to do this as a post-commit. The reason is that you don't want to do anything that takes too long to do in a hook because the user has to wait for the hook to complete before they can continue.

To answer your question, take a look at the repository directory on your server, you should see the following directories and files:

  • README.txt
  • conf
  • db
  • format
  • hooks
  • locks

One of the directories is called hooks. Take a look in this directory:

  • post-commit.tmpl
  • post-lock.tmpl
  • post-revprop-change.tmpl
  • post-unlock.tmpl
  • pre-commit.tmpl
  • pre-lock.tmpl
  • pre-revprop-change.tmpl
  • pre-unlock.tmpl
  • start-commit.tmpl

These are templates for the various hooks. You'll see these are all simple BASH/Korn/Bourne shell scripts. You'll be using the svnlook command to get information about the revision or transaction (if pre-commit hook) that your user just committed.

What you would do is run the command svnlook changed to see what was changed, then based upon this information, you'll have to fetch the file, and deploy it. This means you'll have to create a working directory and do a checkout. Imagine a developer doing a checkin, and then waiting for your post-commit hook to do a checkout and deployment.

What you would be better off doing is getting something like Jenkins to do your post commit tasks. Jenkins is normally a continuous build server. Whenever someone does a commit, Jenkins does a checkout on that project and does the build. It can run all sorts of tests, and then email the developers if there are any problems.

However, it can also simply do a checkout and deployment if you really have nothing to build. Jenkins uses Java 1.6 to run, but otherwise, it's pretty easy to install and use. It's all menu driven, and you don't need to know how to create XML files or write any programs to use it.

So, take a look at Jenkins and see about doing your deployments from there. This way, your developers can continue their work while Jenkins handles the deployments. And, you can have Jenkins send out an email, an IM, Tweet, or even change a traffic light from green to red if there is an issue with the deployment.

Oscular answered 28/9, 2011 at 2:48 Comment(4)
Jenkins looks interesting. But does Jenkins work with svn? It looks like it works with git?Gaynor
Jenkins comes with the Subversion plugin already installed, so it works with Subversion out of the box. There're plugins for Git, ClearCase, StarTeam, BItKeeper, Baazar, and many others source control systems too.Oscular
Ah, so the hooks directory is in the server repository! It weren't obvious, e.g. I don't have an access to the root of the repository, but rather to a subdirectory. Should hooks work, if I just create on my PC that directory with a script?Lonilonier
this answer is pretty old, does this answer still hold up in 2020?Showy
R
17

It's not a separate install. In your respository directory, there is a 'hooks' dir. You can find post-commit.tmpl, just modify the file and rename it to executable file according your os type.

Roadblock answered 28/9, 2011 at 1:0 Comment(2)
I copied pre-commit.pl and didn't work. After rename to pre-commit it works.Andromada
That's weird, but though the directory is mentioned everywhere, I never had «hooks» dir in my repository. More over, locate post-commit outputs nothing at all. Shall it work if I create hooks directory by myself? And should it be created in the .svn directory, or in the root directory of the repository?Lonilonier

© 2022 - 2024 — McMap. All rights reserved.