<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sect2 SYSTEM "../../../dtd/dblite.dtd">
<sect2 id="tsvn-dug-settings-hooks">
	<title>Client Side Hook Scripts</title>
	<?dbhh topicname="HIDD_SETTINGSHOOKS"?>
	<?dbhh topicname="HIDD_SETTINGSHOOKCONFIG"?>
	<indexterm>
		<primary>client hooks</primary>
	</indexterm>
	<indexterm>
		<primary>hook scripts</primary>
	</indexterm>
	<para>
		<figure id="tsvn-dug-settings-dia-hooks">
			<title>The Settings Dialog, Hook Scripts Page</title>
			<graphic fileref="../images/SettingsHooks.png"/>
		</figure>
		This dialog allows you to set up hook scripts which will be
		executed automatically when certain Git actions are performed.
		As opposed to the hook scripts explained in <xref linkend="tsvn-repository-hooks"/>,
		these scripts are executed locally on the client. 
	</para>
	<para>
		One application for such hooks might be to call a program like
		<literal>SubWCRev.exe</literal> to update version numbers after a commit,
		and perhaps to trigger a rebuild.
	</para>
	<para>
		For various security and implementation reasons, hook scripts are defined
		locally on a machine, rather than as project properties. You define what
		happens, no matter what someone else commits to the repository. Of course
		you can always choose to call a script which is itself under version control.
	</para>
	<para>
		<figure id="tsvn-dug-settings-dia-hook-edit">
			<title>The Settings Dialog, Configure Hook Scripts</title>
			<graphic fileref="../images/SettingsHookEdit.png"/>
		</figure>
		To add a new hook script, simply click <guibutton>Add</guibutton>
		and fill in the details.
	</para>
	<para>
		There are currently six types of hook script available
		<variablelist>
			<varlistentry>
				<term>Start-commit</term>
				<listitem>
					<para>
						Called before the commit dialog is shown.
						You might want to use this if the hook modifies a versioned
						file and affects the list of files that need to be committed
						and/or commit message. However you should note that because
						the hook is called at an early stage, the full list of objects
						selected for commit is not available.
					</para>
				</listitem>
			</varlistentry>
			<varlistentry>
				<term>Pre-commit</term>
				<listitem>
					<para>
						Called after the user clicks <guibutton>OK</guibutton>
						in the commit dialog, and before the actual commit begins.
						This hook has a list of exactly what will be committed.
					</para>
				</listitem>
			</varlistentry>
			<varlistentry>
				<term>Post-commit</term>
				<listitem>
					<para>
						Called after the commit finishes (whether successful or not).
					</para>
				</listitem>
			</varlistentry>
			<varlistentry>
				<term>Start-update</term>
				<listitem>
					<para>
						Called before the update-to-revision dialog is shown.
					</para>
				</listitem>
			</varlistentry>
			<varlistentry>
				<term>Pre-update</term>
				<listitem>
					<para>
						Called before the actual Git update begins.
					</para>
				</listitem>
			</varlistentry>
			<varlistentry>
				<term>Post-update</term>
				<listitem>
					<para>
						Called after the update finishes (whether successful or not).
					</para>
				</listitem>
			</varlistentry>
		</variablelist>
	</para>
	<para>
		A hook is defined for a particular working copy path. You only need to
		specify the top level path; if you perform an operation in a sub-folder,
		TortoiseGit will automatically search upwards for a matching path.
	</para>
	<para>
		Next you must specify the command line to execute, starting with the path
		to the hook script or executable.
		This could be a batch file, an executable file or any other file which
		has a valid windows file association, eg. a perl script.
	</para>
	<para>
		The command line includes several parameters which get filled in
		by TortoiseGit. The parameters passed depend upon which hook is called.
		Each hook has its own parameters which are passed in the following order:
		<variablelist>
			<varlistentry>
				<term>Start-commit</term>
				<listitem condition="pot">
					<para>
						<literal>PATH</literal>
						<literal>MESSAGEFILE</literal>
						<literal>CWD</literal>
					</para>
				</listitem>
			</varlistentry>
			<varlistentry>
				<term>Pre-commit</term>
				<listitem condition="pot">
					<para>
						<literal>PATH</literal>
						<literal>DEPTH</literal>
						<literal>MESSAGEFILE</literal>
						<literal>CWD</literal>
					</para>
				</listitem>
			</varlistentry>
			<varlistentry>
				<term>Post-commit</term>
				<listitem condition="pot">
					<para>
						<literal>PATH</literal>
						<literal>DEPTH</literal>
						<literal>MESSAGEFILE</literal>
						<literal>REVISION</literal>
						<literal>ERROR</literal>
						<literal>CWD</literal>
					</para>
				</listitem>
			</varlistentry>
			<varlistentry>
				<term>Start-update</term>
				<listitem condition="pot">
					<para>
						<literal>PATH</literal>
						<literal>CWD</literal>
					</para>
				</listitem>
			</varlistentry>
			<varlistentry>
				<term>Pre-update</term>
				<listitem condition="pot">
					<para>
						<literal>PATH</literal>
						<literal>DEPTH</literal>
						<literal>REVISION</literal>
						<literal>CWD</literal>
					</para>
				</listitem>
			</varlistentry>
			<varlistentry>
				<term>Post-update</term>
				<listitem condition="pot">
					<para>
						<literal>PATH</literal>
						<literal>DEPTH</literal>
						<literal>REVISION</literal>
						<literal>ERROR</literal>
						<literal>CWD</literal>
					</para>
				</listitem>
			</varlistentry>
		</variablelist>
	</para>
	<para>
		The meaning of each of these parameters is described here:
		<variablelist>
			<varlistentry>
				<term condition="pot">PATH</term>
				<listitem>
					<para>
						A path to a temporary file which contains all the
						paths for which the operation was started.
						Each path is on a separate line in the temp file.
					</para>
				</listitem>
			</varlistentry>
			<varlistentry>
				<term condition="pot">DEPTH</term>
				<listitem>
					<para>
						The depth with which the commit/update is done.
					</para>
					<para>
					Possible values are:
					<variablelist>
						<varlistentry>
							<term condition="pot">-2</term>
							<listitem>
								<para>
									<literal>svn_depth_unknown</literal>
								</para>
							</listitem>
						</varlistentry>
						<varlistentry>
							<term condition="pot">-1</term>
							<listitem>
								<para>
									<literal>svn_depth_exclude</literal>
								</para>
							</listitem>
						</varlistentry>
						<varlistentry>
							<term condition="pot">0</term>
							<listitem>
								<para>
									<literal>svn_depth_empty</literal>
								</para>
							</listitem>
						</varlistentry>
						<varlistentry>
							<term condition="pot">1</term>
							<listitem>
								<para>
									<literal>svn_depth_files</literal>
								</para>
							</listitem>
						</varlistentry>
						<varlistentry>
							<term condition="pot">2</term>
							<listitem>
								<para>
									<literal>svn_depth_immediates</literal>
								</para>
							</listitem>
						</varlistentry>
						<varlistentry>
							<term condition="pot">3</term>
							<listitem>
								<para>
									<literal>svn_depth_infinity</literal>
								</para>
							</listitem>
						</varlistentry>
					</variablelist>
					</para>
				</listitem>
			</varlistentry>
			<varlistentry>
				<term condition="pot">MESSAGEFILE</term>
				<listitem>
					<para>
						Path to a file containing the log message for
						the commit. The file contains the text in UTF-8
						encoding. After successful execution of the
						start-commit hook, the log message is read back,
						giving the hook a chance to modify it.
					</para>
				</listitem>
			</varlistentry>
			<varlistentry>
				<term condition="pot">REVISION</term>
				<listitem>
					<para>
						The repository revision to which the update should
						be done or after a commit completes.
					</para>
				</listitem>
			</varlistentry>
			<varlistentry>
				<term condition="pot">ERROR</term>
				<listitem>
					<para>
						Path to a file containing the error message.
						If there was no error, the file will be empty.
					</para>
				</listitem>
			</varlistentry>
			<varlistentry>
				<term condition="pot">CWD</term>
				<listitem>
					<para>
						The current working directory with which the script is run.
						This is set to the common root directory of all affected paths.
					</para>
				</listitem>
			</varlistentry>
		</variablelist>
	</para>
	<para>
		Note that although we have given these parameters names for convenience,
		you do not have to refer to those names in the hook settings.
		All parameters listed for a particular hook are always passed,
		whether you want them or not ;-)
	</para>
	<para>
		If you want the Git operation to hold off until the hook has completed,
		check <guilabel>Wait for the script to finish</guilabel>.
	</para>
	<para>
		Normally you will want to hide ugly DOS boxes when the script runs,
		so <guilabel>Hide the script while running</guilabel> is checked by default.
	</para>
	<para>
		Sample client hook scripts can be found in the <literal>contrib</literal> folder in the
		<ulink url="http://TortoiseGit.tigris.org/svn/TortoiseGit/trunk/contrib/hook-scripts">
			<citetitle>TortoiseGit repository</citetitle>
		</ulink>.
		(<xref linkend="tsvn-preface-source"/> explains how to access the repository).
	</para>
	<sect3 id="tsvn-dug-settings-hooks-issuetracker">
		<title>Issue Tracker Integration</title>
		<?dbhh topicname="HIDD_SETTINGSBUGTRAQ"?>
		<?dbhh topicname="HIDD_SETTINGSBUGTRAQADV"?>
		<para>
			TortoiseGit can use a COM plugin to query issue trackers when in the
			commit dialog. The use of such plugins is described in
			<xref linkend="tsvn-dug-bugtracker-ref" />.
			If your system administrator has provided you with a plugin, which
			you have already installed and registered, this is the place to
			specify how it integrates with your working copy.
		</para>
		<para>
			<figure id="tsvn-dug-settings-dia-issuetracker">
				<title>The Settings Dialog, Issue Tracker Integration Page</title>
				<graphic fileref="../images/SettingsIssueTracker.png"/>
			</figure>
			Click on <guibutton>Add...</guibutton> to use the plugin with
			a particular working copy. Here you can specify the working copy
			path, choose which plugin to use from a drop down list of all
			registered issue tracker plugins, and any parameters to pass.
			The parameters will be specific to the plugin, but might include
			your user name on the issue tracker so that the plugin can
			query for issues which are assigned to you.
		</para>
		<para>
			If you want all users to use the same COM plugin for your project, you
			can specify the plugin also with the properties <literal>bugtraq:provideruuid</literal>
			and <literal>bugtraq:providerparams</literal>.

			<variablelist>
				<varlistentry>
					<term condition="pot">bugtraq:provideruuid</term>
					<listitem>
						<para>
							This property specifies the COM UUID of the IBugTraqProvider,
							for example <literal>{91974081-2DC7-4FB1-B3BE-0DE1C8D6CE4E}</literal>.
						</para>
					</listitem>
				</varlistentry>
				<varlistentry>
					<term condition="pot">bugtraq:providerparams</term>
					<listitem>
						<para>
							This property specifies the parameters passed to the IBugTraqProvider.
						</para>
					</listitem>
				</varlistentry>
			</variablelist>
			Please check the documentation of your IBugTraqProvider plugin to find out what
			to specify in these two properties.
		</para>
	</sect3>
</sect2>
