#!/bin/bash
#-------------------------------------------------------------------------------
# Copyright (C) 2006-2021 British Crown (Met Office) & Contributors.
#
# This file is part of FCM, tools for managing and building source code.
#
# FCM is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FCM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with FCM. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
set -eu
LOCK=/path/to/lock
WC_OF_PROJECT=/path/to/working/copy/of/project

if [[ -e $LOCK ]]; then
    exit
fi

mkdir -p $LOCK
echo "$(whoami)@$(hostname):$$" >$LOCK/info # info on who created the lock

while true; do
    UPDATED=$(cd $WC_OF_PROJECT && svn update | sed '$d' | cut -c6-)
    if [[ -z $UPDATED ]]; then
        break
    fi
    if [[ -n $(echo "$UPDATED" | grep '^foo/bar/[^/]*\.baz$') ]]; then
        : # Performs some update if foo/bar/*.baz has changed
    fi
done

rm $LOCK/info
rmdir $LOCK
exit
