<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sect1 SYSTEM "../../../dtd/dblite.dtd">
<sect1 id="tsvn-repository-hooks">
  <title>Server side hook scripts</title>
  <indexterm>
    <primary>hooks</primary>
  </indexterm>
  <indexterm>
    <primary>hook scripts</primary>
  </indexterm>
  <indexterm>
    <primary>server side hook scripts</primary>
  </indexterm>
  <para>
    A hook script is a program triggered by some repository event,
    such as the creation of a new revision or the modification of an
    unversioned property. Each hook is handed enough information
    to tell what that event is, what target(s) it's operating on,
    and the username of the person who triggered the event.
    Depending on the hook's output or return status, the hook
    program may continue the action, stop it, or suspend it in
    some way. Please refer to the chapter on
    <ulink url="https://svnbook.red-bean.com/en/1.8/svn.reposadmin.create.html#svn.reposadmin.create.hooks">
      <citetitle>Hook Scripts</citetitle>
    </ulink>
    in the Subversion Book for full details about the hooks which
    are implemented.
  </para>
  <para>
    These hook scripts are executed by the server that hosts the
    repository. TortoiseSVN also allows you to configure client side
    hook scripts that are executed locally upon certain events. See
    <xref linkend="tsvn-dug-settings-hooks"/> for more information.
  </para>
  <para>
    Sample hook scripts can be found in the <filename>hooks</filename>
    directory of the repository. These sample scripts are suitable
    for Unix/Linux servers but need to be modified if your server is
    Windows based. The hook can be a batch file or an executable.
    The sample below shows a batch file which might be used to
    implement a pre-revprop-change hook.
    <screen>
rem Only allow log messages to be changed.
if "%4" == "svn:log" exit 0
echo Property '%4' cannot be changed &gt;&amp;2
exit 1
    </screen>
    Note that anything sent to stdout is discarded. If you want
    a message to appear in the Commit Reject dialog you must
    send it to stderr. In a batch file this is achieved using
    <filename>&gt;&amp;2</filename>.
  </para>
  <tip>
    <title>Overriding Hooks</title>
    <para>
      If a hook script rejects your commit then its decision is final.
      But you can build an override mechanism into the script itself
      using the <emphasis>Magic Word</emphasis> technique. If the script
      wants to reject the operation it first scans the log message for
      a special pass phrase, either a fixed phrase or perhaps the
      filename with a prefix. If it finds the magic word then it allows
      the commit to proceed. If the phrase is not found then it can
      block the commit with a message like
      <quote>You didn't say the magic word</quote>. :-)
    </para>
  </tip>
</sect1>
