Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a SVN repository with a lot of sub-projects stored in it. Right now in my post-commit I just loop through all possible folders on the machine and run svn update on each:

REPOS="$1"
REV="$2"
DIRS=("/path/to/local/copy/firstproject" "/path/to/local/copy/anotherproject" ... "/path/to/local/copy/spam")
LOGNAME=`/usr/bin/whoami`

for DIR in ${DIRS[@]}
do
    cd $DIR
    sudo /usr/bin/svn update --accept=postpone 2>&1 | logger
    logger "$LOGNAME Updated $DIR to revision $REV (from $REPOS) "
done

The problem is that this is slow and redundant when I'm just committing the subfolder of one of the projects. I'm wondering if there's a better way of identifying which of the DIRS I should use and only update that one.

Is there some way to do this? As far as I can tell there's no way to determine which part of a repo was committed and thus which directory needs to be updated.

Is the only alternative to create a separate repository for each project? (Probably should have done that from the start, if so...)

share|improve this question

2 Answers 2

up vote 4 down vote accepted

I'm wondering if there's a better way of identifying which of the DIRS I should use and only update that one.

svnlook dirs-changed is what you're looking for:

# svnlook dirs-changed -r 40270 /path/to/the/repo
project1/foo/bar

Try something like this:

#!/usr/local/bash4/bin/bash

typeset -A IP
typeset -A DOCROOT

PROJECTS="project1 project2"

IP=([project1]="ip1" [project2]="ip2")
DOCROOT=([project1]="/var/www/html/project1/" [project2]="/var/www/html/project2/")

REPO="$1"
REV="$2"

USER='deployer'

PROJECT=`svnlook dirs-changed -r "$REV" "$REPO" | awk -F "/" '{ print $1 }'`

ssh -t "$USER@${IP[$PROJECT]}" "cd ${DOCROOT[$PROJECT]} && svn up"
share|improve this answer
    
Oh neat, I think your answer neatly answered another question I had, which was: "Is there such a thing as hash arrays/dicts in bash?" Turns out the answer is Yes? –  Jordan Reiter Aug 27 '12 at 22:10
1  
Yes. Bash 4 supports associative arrays. –  quanta Aug 28 '12 at 2:24

Here's the script I ended up using, based on quanta's help:

REPO="$1"
REV="$2"
declare -A PROJECTS
PROJECTS=(\
    [project1]="/path/to/projects/project1 /path/to/projects/project1-devel" \
    [project2]="/path/to/projects/project2 /path/to/projects/project2-devel" \
    [project3]="/path/to/projects/project3 /path/to/projects/project3-devel" \
)

PROJECT=`svnlook dirs-changed -r "$REV" "$REPO" | awk -F "/" '{ print $1 }'`
DIRS=${PROJECTS[$PROJECT]}

for DIR in $DIRS
do
    cd $DIR
    sudo /usr/bin/svn update --accept=postpone 2>&1 | logger
    logger "$LOGNAME Updated $DIR to revision $REV (from $REPOS) "
done

Note that the one big thing I had to add was the declare -A PROJECTS line. For some reason the associative array/hash wouldn't work until I did this.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.