#! /bin/sh
# $Id: //guest/rick_richardson/perforce/utils/triggers/Jobs.sh#1 $
# Copyright (c) 1999 Softweyr LLC. All rights reserved.
#
# Redistribution and use in source form, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notices,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# 3. The name of Softweyr LLC and it contributors may not be used to endorse
# or promote products derived from this software without specific prior
# written permission.
#
# This software is provided by Softweyr LLC and contributors ``AS IS'' and any
# express or implied warranties, including, but not limited to, the implied
# warranties of merchantability and fitness for a particular purpose are
# DISCLAIMED. In no event shall Softweyr LLC or contributors be liable for
# any direct, indirect, incidental, special, exemplary, or consequential
# damages (including, but not limited to, procurement of substitute goods or
# services; loss of use, data, or profits; or business interruption) however
# caused and on any theory of liability, whether in contract, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#
# mustfix: Require Perforce commits to have a job number associated with
# every change.
#
# Note that the p4 server collects the output from this program and shows it
# to the client user if the program returns non-zero, indicating failure.
# Success is silent to avoid nattering at the user unnecessarily.
#
# args:
#
# $1 - the changelist being submitted
# $2 - the Perforce username
# $3 - the Perforce clientspec
#
# Section to add to "p4 triggers":
# Triggers:
# must_fix //depot/... "/usr/local/bin/mustfix %change% %user% %client%"
# (Note that if you have more than one server on this machine, you might want to
# add "%serverport%" to the argument list and process it in the script, below.)
PATH=$PATH:/usr/local/bin
change=$1
user=$2
client=$3
P4USER=$user; export P4USER
P4CLIENT=$client; export P4CLIENT
P4PORT=obie:1666; export P4PORT
fixes=`p4 fixes -c $change | wc -l`
result=`p4 fixes -c $change`
info=`p4 info`
if [ $fixes -gt 0 ] ; then
#echo "Submitting change $change for $fixes problems"
exit 0
else
echo "Client $client user $user."
echo "Change $change doesn't fix anything."
echo P4 result is $result.
echo $info
exit 1
fi