Subversion multi checkout post-commit hook?

2

1

The title must sound strange but I'm trying to achieve the following:

SVN repo location: /home/flx/svn/flxdev SVN repo "flxdev" structure:

 + Project1
 ++ files
 + Project2
 + Project3
 + Project4

I'm trying to set up a post-commit hook that automatically checks out on the other end when I do a commit.

The post-commit doc explicitly lists the following:

# POST-COMMIT HOOK
#
# The post-commit hook is invoked after a commit.  Subversion runs
# this hook by invoking a program (script, executable, binary, etc.)
# named 'post-commit' (for which this file is a template) with the
# following ordered arguments:
#
#   [1] REPOS-PATH   (the path to this repository)
#   [2] REV          (the number of the revision just committed)

So I made the following command to test:

REPOS="$1"
REV="$2"
echo "Updated project $REPOS to $REV"

However when I edit files in Project1 for example, this outputs "Updated project /home/flx/svn/flxdev to 1016"

I'd like this to be: "Updated project Project1 to 1016"

Having this variable allows me to specify to do different actions per project post-commit. How can I specify the project parameter?

Thanks!

Dennis

FLX

Posted 2010-12-22T18:55:45.820

Reputation: 319

This may be better suited for stackoverflow.com – Daisetsu – 2010-12-22T19:25:34.870

The repository is fixdev, Project1 is just a path within. How would you handle commits that modify multiple projects in a single action? You just have to take the data you get, and svn log for details. – Daniel Beck – 2010-12-22T19:25:51.650

@Daisetsu SVN can be used as a general purpose tool. How do you know that these projects are software development related (I know, they probably are)? If Visual Studio questions are acceptable, so is this. – Daniel Beck – 2010-12-22T19:28:20.523

I would suspect that you would have to make a call to svnlook with $REPOS, pass $REV as --revision, and parse out the results yourself to get what you are looking for. The info or cat commands might give you the answer you are looking for, I'm a bit rusty on the details. – vcsjones – 2010-12-23T11:49:30.447

@Daniel Beck, yes, you can version any file but the reason why I recommended stack overflow is because they probably have someone who has asked a question similar to this already, and a lot of the users over there really know SVN like the back of their hand. – Daisetsu – 2010-12-23T23:36:17.707

@Daisetsu Of course, you're right. I mistook your comment as suggestion that this might be off-topic for this site. – Daniel Beck – 2010-12-23T23:38:53.413

Answers

1

The following might do what you want:

#!/bin/bash

REPOS="$1"
REV="$2"

echo In revision $REV, the following projects were changed:
svnlook dirs-changed "$REPOS" --revision "$REV" \ 
    | sed 's%/.*%%' \
    | sort -u \
    | while read PROJ ; do
          echo "$PROJ"
      done

An explanation of what's going on, in case you're not too familiar with shell scripting:

  • we use svnlook to get the list of directories that were changed
  • we use sed to chop off the first "/" and everything after it -- so we then have a list of project names, possibly with duplicates.
  • we use sort -u ("sort unique") to eliminate duplicates
  • one by one, we read each name into $PROJ and do something with it.

You can replace the echo "$PROJ" line with whatever you want to do with the project name. If multiple projects were changed in the same commit, whatever you put there will be run once for each project changed, with $PROJ set appropriately.

This script will not show whether files were added to the root of the repository, but if directories were added, they will show up in the list of projects modified. If you want the root to be listed as well, you can substitute the following sed line, and it will show up as "/". If you do this, be careful you don't check out the entire repository by accident!

...
    | sed '/^\/$/!s%/.*%%' \
...

Jander

Posted 2010-12-22T18:55:45.820

Reputation: 824