forked from metomi/fcm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trac_hook
65 lines (64 loc) · 2.49 KB
/
trac_hook
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
#-------------------------------------------------------------------------------
# (C) British Crown Copyright 2006-16 Met Office.
#
# 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/>.
#-------------------------------------------------------------------------------
# NAME
# trac_hook
#
# SYNOPSIS
# . trac_hook
# trac_hook "$REPOS" "$REV" added|modified
#
# DESCRIPTION
# Provide a function called "trac_hook", which updates the corresponding Trac
# environment, for post-commit or post-revprop-change.
#
# ENVIRONMENT VARIABLES
# FCM_SVN_HOOK_TRAC_ROOT_DIR
# The root directories of Trac environments. Update corresponding Trac
# environment if specified.
# FCM_SVN_HOOK_REPOS_SUFFIX
# A suffix that should be removed from the basename of REPOS to get the
# name of the Trac environment. (Default is "".)
#-------------------------------------------------------------------------------
trac_hook() {
local REPOS=$1
local REV=$2
local TRAC_ACT=$3
if which trac-admin 1>/dev/null 2>&1 \
&& [[ -n ${FCM_SVN_HOOK_TRAC_ROOT_DIR:-} ]]
then
local TRAC_NAME=$(basename "$REPOS")
if [[ -n ${FCM_SVN_HOOK_REPOS_SUFFIX:-} ]]; then
TRAC_NAME=${NAME%$FCM_SVN_HOOK_REPOS_SUFFIX}
fi
local TRAC_DIR="$FCM_SVN_HOOK_TRAC_ROOT_DIR/$TRAC_NAME"
if [[ -d "$TRAC_DIR" ]]; then
if [[ $(trac-admin --version) == trac-admin\ 0.11* ]]; then
# N.B. "added" was automatic on access
if [[ "$TRAC_ACT" == 'modified' ]]; then
echo "trac-admin $TRAC_DIR resync $REV"
trac-admin "$TRAC_DIR" resync "$REV" >/dev/null
fi
else
echo "trac-admin $TRAC_DIR changeset $TRAC_ACT $REPOS $REV"
trac-admin "$TRAC_DIR" changeset "$TRAC_ACT" "$REPOS" "$REV"
fi
fi
fi
}