Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

# 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:

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?



share|improve this question
This may be better suited for – Daisetsu Dec 22 '10 at 19:25
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 Dec 22 '10 at 19:25
@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 Dec 22 '10 at 19:28
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 Dec 23 '10 at 11:49
@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 Dec 23 '10 at 23:36
up vote 1 down vote accepted

The following might do what you want:



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"

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%/.*%%' \
share|improve this answer
Awesome, thanks! – FLX Jan 5 '11 at 8:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .