[10672] | 1 | #!/bin/bash |
---|
| 2 | #------------------------------------------------------------------------------- |
---|
| 3 | # (C) British Crown Copyright 2006-17 Met Office. |
---|
| 4 | # |
---|
| 5 | # This file is part of FCM, tools for managing and building source code. |
---|
| 6 | # |
---|
| 7 | # FCM is free software: you can redistribute it and/or modify |
---|
| 8 | # it under the terms of the GNU General Public License as published by |
---|
| 9 | # the Free Software Foundation, either version 3 of the License, or |
---|
| 10 | # (at your option) any later version. |
---|
| 11 | # |
---|
| 12 | # FCM is distributed in the hope that it will be useful, |
---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | # GNU General Public License for more details. |
---|
| 16 | # |
---|
| 17 | # You should have received a copy of the GNU General Public License |
---|
| 18 | # along with FCM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 19 | #------------------------------------------------------------------------------- |
---|
| 20 | # NAME |
---|
| 21 | # trac_hook |
---|
| 22 | # |
---|
| 23 | # SYNOPSIS |
---|
| 24 | # . trac_hook |
---|
| 25 | # trac_hook "$REPOS" "$REV" added|modified |
---|
| 26 | # |
---|
| 27 | # DESCRIPTION |
---|
| 28 | # Provide a function called "trac_hook", which updates the corresponding Trac |
---|
| 29 | # environment, for post-commit or post-revprop-change. |
---|
| 30 | # |
---|
| 31 | # ENVIRONMENT VARIABLES |
---|
| 32 | # FCM_SVN_HOOK_TRAC_ROOT_DIR |
---|
| 33 | # The root directories of Trac environments. Update corresponding Trac |
---|
| 34 | # environment if specified. |
---|
| 35 | # FCM_SVN_HOOK_REPOS_SUFFIX |
---|
| 36 | # A suffix that should be removed from the basename of REPOS to get the |
---|
| 37 | # name of the Trac environment. (Default is "".) |
---|
| 38 | #------------------------------------------------------------------------------- |
---|
| 39 | |
---|
| 40 | trac_hook() { |
---|
| 41 | local REPOS=$1 |
---|
| 42 | local REV=$2 |
---|
| 43 | local TRAC_ACT=$3 |
---|
| 44 | if which trac-admin 1>/dev/null 2>&1 \ |
---|
| 45 | && [[ -n ${FCM_SVN_HOOK_TRAC_ROOT_DIR:-} ]] |
---|
| 46 | then |
---|
| 47 | local TRAC_NAME=$(basename "$REPOS") |
---|
| 48 | if [[ -n ${FCM_SVN_HOOK_REPOS_SUFFIX:-} ]]; then |
---|
| 49 | TRAC_NAME=${NAME%$FCM_SVN_HOOK_REPOS_SUFFIX} |
---|
| 50 | fi |
---|
| 51 | local TRAC_DIR="$FCM_SVN_HOOK_TRAC_ROOT_DIR/$TRAC_NAME" |
---|
| 52 | if [[ -d "$TRAC_DIR" ]]; then |
---|
| 53 | if [[ $(trac-admin --version) == trac-admin\ 0.11* ]]; then |
---|
| 54 | # N.B. "added" was automatic on access |
---|
| 55 | if [[ "$TRAC_ACT" == 'modified' ]]; then |
---|
| 56 | echo "trac-admin $TRAC_DIR resync $REV" |
---|
| 57 | trac-admin "$TRAC_DIR" resync "$REV" >/dev/null |
---|
| 58 | fi |
---|
| 59 | else |
---|
| 60 | echo "trac-admin $TRAC_DIR changeset $TRAC_ACT $REPOS $REV" |
---|
| 61 | trac-admin "$TRAC_DIR" changeset "$TRAC_ACT" "$REPOS" "$REV" |
---|
| 62 | fi |
---|
| 63 | fi |
---|
| 64 | fi |
---|
| 65 | } |
---|