Change-commit triggers

Use the change-commit trigger type to create triggers that fire after changelist creation, file transfer, and changelist commission to the database. Use change-commit triggers for processes that assume (or require) the successful submission of a changelist, such as a change to a file or stream spec.

Warning

When a change-commit trigger fires, any file or stream spec in the committed changelist has already been submitted and could be changed by a user while the change-commit trigger executes.

Tip

Replicas that are metadata-only do not support triggers of type change-commit and change-content.

Example    

Here is a change-commit trigger that sends emails to other users who have files open in the submitted changelist.

#!/bin/sh
# mailopens.sh - Notify users when open files are updated
changelist="$1
workspace="$2"
user="$3"
p4 fstat -e "$changelist" //... | while read -r line
do
   # Parse out the name/value pair.
   name=$(echo "$line" | sed 's/[\. ]\+\([^ ]\+\) .\+/\1/')
   value=$(echo "$line" | sed 's/[\. ]\+[^ ]\+ \(.\+\)/\1/')
   if [ "$name" = "depotFile" ]
   then
     # Line is "... depotFile <depotFile>". Parse to get depotFile.
     depotfile="$value"
   elif [ "$(echo "$name" | cut -b-9)" = "otherOpen" ] && \
        [ "$name" != "otherOpen" ]
   then
     # Line is "... ... otherOpen[0-9]+ <otherUser@otherWorkspace>".
     # Parse to get otherUser and otherWorkspace.
     otheruser=$(echo "$value" | sed 's/\(.\+\)@.\+/\1/')
     otherworkspace=$(echo "$value" | sed 's/.\+@\(.\+\)/\1/')
     # Get email address of the other user from p4 user -o.
     othermail=$(p4 user -o "$otheruser" | grep "Email:" | \
         grep -v \# | cut -b8-)

     # Mail other user that a file they have open has been updated
     mail -s "$depotfile was just submitted" "$othermail" <<EOM
The Perforce file: $depotfile
was just submitted in changelist $changelist by Perforce user $user
from the $workspace workspace.  You have been sent this message
because you have this file open in the $otherworkspace workspace.
EOM
   fi
done
exit 0

To use the trigger, add the following line to your triggers table:

sample3  change-commit //... "mailopens.sh %change% %client% %user%"

Whenever a user submits a changelist, any users with open files affected by that changelist receive an email notification.