3

I need to have a more intelligent post-commit script.

If a commit message states something like "Adding Revision-v.10.3 production", an ssh command needs to be executed.

Is it possible to do this with post-commit?

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Cmag
  • 14,946
  • 25
  • 89
  • 140
  • REPOS="$1" , REV="$2" are variables... how do i get the 'commit message' string in the post-commit ? – Cmag Aug 30 '11 at 16:05
  • 1
    @Clustermagnet: Try `MESSAGE=$(/usr/bin/svn log "$1" -r HEAD --limit 1 --incremental | sed '1,3d')` (from [here](http://www.designified.com/blog/article/89/an-svn-post-commit-hood-shell-script-to-copy-the-log-message-and-revision-number-to-the-clipboard-on-os-x)). – gen_Eric Aug 30 '11 at 16:07

3 Answers3

4

There is no easy way to get the commit message from the SVN post-commit hook. You can ask svn log for the message, and then parse it out.

 MESSAGE=$(/usr/bin/svn log "$1" -r HEAD --limit 1 --incremental | sed '1,3d')

From: here

To get the commit message from post-commit use this:

MESSAGE=$(svnlook propget --revprop -r $REV $REPOS_PATH svn:log)
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
  • @David: I didn't know that. For some reason Googling "svn post-commit get message" doesn't return a whole lot. The link I posted in the answer was the most amount of info I could find. – gen_Eric Aug 30 '11 at 19:02
  • Append the correction to your answer, and I'll remove my comment and downmod. Here's the info on the [Subversion revprops](http://svnbook.red-bean.com/nightly/en/svn.ref.properties.html#svn.ref.properties.unversioned-props). Here's info on the [svnlook](http://svnbook.red-bean.com/nightly/en/svn.reposadmin.maint.html#svn.reposadmin.maint.tk.svnlook) command. Don't get discouraged. This is how you learn. – David W. Aug 30 '11 at 19:15
  • 1
    Now you can use `MESSAGE=$(svnlook log $REPOS -r $REV)` – Tanky Woo May 28 '14 at 15:08
1

NO! NO! NO!

The last thing you should be doing is executing an ssh on a post commit!

I'm not sure what your intentions are, and I assume them to be honorable. However, remember that Subversion won't return control to the client until the post-commit hook finishes executing. If your ssh command takes just ten seconds to execute, then the user is seeing that svn commit hanging there for ten seconds before they can do anything.

In those ten seconds, the user will develop a seething hatred of you, the company, and Subversion. They will become embittered shells of their former selves, and it will be your fault! Do you want that guilt hanging over your head? Didn't think so.

The best solution is to use a continuous build server like Jenkins and have that do your SSH command. It can take the results of the command, and if it fails, emails the results to the developer and their team. Jenkins is extremely easy to setup and use, and doing this through Jenkins (i.e., the correct way) shouldn't take more than a few hours (at most) to do.

Thus, the users commits won't be hanging there, yet they'll still get the information they need. And, since you have it tied to Jenkins, you'll probably find all sorts of plugins to Jenkins that do all sorts of marvelous things you didn't think possible. You'll be a hero and revered as a god. Isn't that better than seething hatred?

The choice is yours.

(By the way, you can get the commit message by doing a svn propget --rev-prop -r $REV svn:log)

David W.
  • 105,218
  • 39
  • 216
  • 337
0

Just an FYI, what i just setup was a php script to execut on post-commit. If you're comfortable with PHP, this would give you a lot of control, and the possibility to run ssh command. I've outlined it here: https://stackoverflow.com/a/10146169/654235

Community
  • 1
  • 1
russds
  • 845
  • 5
  • 25
  • 48