[Home] You are not logged in. Login here

Just my stuff

Automating svn delete and svn add

Patrick asked me on Friday if I could somehow make
svn move file
svn delete file
and
svn add file
somehow transparent to his not-so-computer-savy secretary. He is using svn to centrally store documents and files other people in his company edit and create, so the people can comment on changes, and work on the files while offline.
We thought a bit about it, and this is what came out:

#!/bin/bash
#this depends on inotify-tools
#folder to watch
FOLDER=~/tmp/svn_test/repo
###############################

inotifywait -m --format '%e %w %f' -r $FOLDER -e move -e create -e delete --exclude .svn 2>/dev/null|
while read EVENT
do
  EV=`echo $EVENT|cut -d' ' -f1|cut -d',' -f1`
  FOLDER=`echo $EVENT|cut -d' ' -f2`
  FILE=`echo $EVENT|cut -d' ' -f3`
  echo event $EVENT
  #continue
  if [ "$EV" == "CREATE" ] || [ "$EV" == "MOVED_TO" ]; then
    svn add --force "$FOLDER/$FILE" 
  elif [ "$EV" == "DELETE" ] || [ "$EV" == "MOVED_FROM" ]; then
    svn delete "$FOLDER/$FILE" 
  fi
done

This way, if Ms. Secretary works on files on her working copy of the svn repository, and this script is running, for every file creation, move or delete the corresponding svn command is executed.
This of course works while offline too, so when Ms. Secretary is back in the office, she can just execute the svn update && svn commit command and everything is back in sync.

 
Comments for this post have been disabled