.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.if !\nF .nr F 0
.if \nF>0 \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
.\}
.\" ========================================================================
.\"
.IX Title "SVN::Hooks 3pm"
.TH SVN::Hooks 3pm "2017-06-24" "perl v5.24.1" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
SVN::Hooks \- Framework for implementing Subversion hooks
.SH "VERSION"
.IX Header "VERSION"
version 1.34
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
A single script can implement several hooks:
.PP
.Vb 1
\& #!/usr/bin/perl
\&
\& use SVN::Hooks;
\&
\& START_COMMIT {
\& my ($repo_path, $username, $capabilities, $txn_name) = @_;
\& # ...
\& };
\&
\& PRE_COMMIT {
\& my ($svnlook) = @_;
\& # ...
\& };
\&
\& run_hook($0, @ARGV);
.Ve
.PP
Or you can use already implemented hooks via plugins:
.PP
.Vb 1
\& #!/usr/bin/perl
\&
\& use SVN::Hooks;
\& use SVN::Hooks::DenyFilenames;
\& use SVN::Hooks::DenyChanges;
\& use SVN::Hooks::CheckProperty;
\& ...
\&
\& run_hook($0, @ARGV);
.Ve
.SH "INTRODUCTION"
.IX Header "INTRODUCTION"
In order to really understand what this is all about you need to
understand Subversion and its
hooks. You can read everything about this in the svnbook,
a.k.a. Version Control with Subversion, at
.
.PP
Subversion is a version control system, and as such it is used to keep
historical revisions of files and directories. Each revision maintains
information about all the changes introduced since the previous one:
date, author, log message, files changed, files renamed, etc.
.PP
Subversion uses a client/server model. The server maintains the
\&\fBrepository\fR, which is the database containing all the historical
information we talked about above. Users use a Subversion client tool
to query and change the repository but also to maintain one or more
\&\fBworking areas\fR. A working area is a directory in the user machine
containing a copy of a particular revision of the repository. The user
can use the client tool to make all sorts of changes in his working
area and to \*(L"commit\*(R" them all in an atomic operation that bumps the
repository to a new revision.
.PP
A hook is a specifically named program that is called by the
Subversion server during the execution of some operations. There are
exactly nine hooks which must reside under the \f(CW\*(C`hooks\*(C'\fR directory in
the repository. When you create a new repository, you get nine
template files in this directory, all of them having the \f(CW\*(C`.tmpl\*(C'\fR
suffix and helpful instructions inside explaining how to convert them
into working hooks.
.PP
When Subversion is performing a commit operation on behalf of a
client, for example, it calls the \f(CW\*(C`start\-commit\*(C'\fR hook, then the
\&\f(CW\*(C`pre\-commit\*(C'\fR hook, and then the \f(CW\*(C`post\-commit\*(C'\fR hook. The first two
can gather all sorts of information about the specific commit
transaction being performed and decide to reject it in case it doesn't
comply to specified policies. The \f(CW\*(C`post\-commit\*(C'\fR can be used to log or
alert interested parties about the commit just done.
.PP
\&\s-1IMPORTANT NOTE\s0 from the svnbook: \*(L"For security reasons, the Subversion
repository executes hook programs with an empty environment\-\-\-that is,
no environment variables are set at all, not even \f(CW$PATH\fR (or \f(CW%PATH\fR%,
under Windows). Because of this, many administrators are baffled when
their hook program runs fine by hand, but doesn't work when run by
Subversion. Be sure to explicitly set any necessary environment
variables in your hook program and/or use absolute paths to programs.\*(R"
.PP
Not even the current directory where the hooks run is specified by
Subversion. However, the hooks executed by the SVN::Hooks framework run with
their currect directory set to the repository's root directory in the
server. This can be useful sometimes.
.PP
There are several useful hook scripts available elsewhere
,
mainly for those three associated with the commit operation. However,
when you try to combine the functionality of two or more of those
scripts in a single hook you normally end up facing two problems.
.IP "\fBComplexity\fR" 4
.IX Item "Complexity"
In order to integrate the funcionality of more than one script you
have to write a driver script that's called by Subversion and calls
all the other scripts in order, passing to them the arguments they
need. Moreover, some of those scripts may have configuration files to
read and you may have to maintain several of them.
.IP "\fBInefficiency\fR" 4
.IX Item "Inefficiency"
This arrangement is inefficient in two ways. First because each script
runs as a separate process, which usually have a high startup cost
because they are, well, scripts and not binaries. And second, because
as each script is called in turn they have no memory of the scripts
called before and have to gather the information about the transaction
again and again, normally by calling the \f(CW\*(C`svnlook\*(C'\fR command, which
spawns yet another process.
.PP
SVN::Hooks is a framework for implementing Subversion hooks that tries
to solve these problems.
.PP
Instead of having separate scripts implementing different
functionality you have a single script implementing all the
funcionality you need either directly or using some of the existing
plugins, which are implemented by Perl modules in the SVN::Hooks::
namespace. This single script can be used to implement all nine
standard hooks, because each hook knows when to perform based on the
context in which the script was called.
.SH "USAGE"
.IX Header "USAGE"
In the Subversion server, go to the \f(CW\*(C`hooks\*(C'\fR directory under the
directory where the repository was created. You should see there the
nine hook templates. Create a script there using the SVN::Hooks module.
.PP
.Vb 1
\& $ cd /path/to/repo/hooks
\&
\& $ cat >svn\-hooks.pl <added()) {
\& $added !~ /\e.(exe|o|jar|zip)$/
\& or die "Please, don\*(Aqt commit binary files such as \*(Aq$added\*(Aq.\en";
\& }
\& };
\&
\& run_hook($0, @ARGV);
.Ve
.PP
Note that the hook directives resemble function definitions but
they're not. They are function calls, and as such must end with a
semi-colon.
.PP
Most of the \f(CW\*(C`start\-commit\*(C'\fR and \f(CW\*(C`pre\-*\*(C'\fR hooks are used to check some
condition. If the condition holds, they must simply end without
returning anything. Otherwise, they must \f(CW\*(C`die\*(C'\fR with a suitable error
message.
.PP
Also note that each hook directive can be called more than once if you
need to implement more than one specific hook. The hooks will run
in the order they were defined.
.SS "Using Plugins"
.IX Subsection "Using Plugins"
There are several hooks already implemented as plugin modules under
the namespace \f(CW\*(C`SVN::Hooks::\*(C'\fR, which you can use. The main ones are
described succinctly below. Please, see their own documentation for
more details.
.IP "SVN::Hooks::AllowPropChange" 4
.IX Item "SVN::Hooks::AllowPropChange"
Allow only specified users make changes in revision properties.
.IP "SVN::Hooks::CheckCapability" 4
.IX Item "SVN::Hooks::CheckCapability"
Check if the Subversion client implements the required capabilities.
.IP "SVN::Hooks::CheckJira" 4
.IX Item "SVN::Hooks::CheckJira"
Integrate Subversion with the \s-1JIRA
\&\s0 ticketing system.
.IP "SVN::Hooks::CheckLog" 4
.IX Item "SVN::Hooks::CheckLog"
Check if the log message in a commit conforms to a Regexp.
.IP "SVN::Hooks::CheckMimeTypes" 4
.IX Item "SVN::Hooks::CheckMimeTypes"
Check if the files added to the repository have the \f(CW\*(C`svn:mime\-type\*(C'\fR
property set. Moreover, for text files, check if the properties
\&\f(CW\*(C`svn:eol\-style\*(C'\fR and \f(CW\*(C`svn:keywords\*(C'\fR are also set.
.IP "SVN::Hooks::CheckProperty" 4
.IX Item "SVN::Hooks::CheckProperty"
Check for specific properties for specific kinds of files.
.IP "SVN::Hooks::CheckStructure" 4
.IX Item "SVN::Hooks::CheckStructure"
Check if the files and directories being added to the repository
conform to a specific structure.
.IP "SVN::Hooks::DenyChanges" 4
.IX Item "SVN::Hooks::DenyChanges"
Deny the addition, modification, or deletion of specific files and
directories in the repository. Usually used to deny modifications in
the \f(CW\*(C`tags\*(C'\fR directory.
.IP "SVN::Hooks::DenyFilenames" 4
.IX Item "SVN::Hooks::DenyFilenames"
Deny the addition of files which file names doesn't comply with a
Regexp. Usually used to disallow some characteres in the filenames.
.IP "SVN::Hooks::Notify" 4
.IX Item "SVN::Hooks::Notify"
Sends notification emails after successful commits.
.IP "SVN::Hooks::UpdateConfFile" 4
.IX Item "SVN::Hooks::UpdateConfFile"
Allows you to maintain Subversion configuration files versioned in the
same repository where they are used. Usually used to maintain the
configuration file for the hooks and the repository access control
file.
.PP
This is an example of a script using some plugins:
.PP
.Vb 1
\& #!/usr/bin/perl
\&
\& use SVN::Hooks;
\& use SVN::Hooks::CheckProperty;
\& use SVN::Hooks::DenyChanges;
\& use SVN::Hooks::DenyFilenames;
\&
\& # Accept only letters, digits, underlines, periods, and hifens
\& DENY_FILENAMES(qr/[^\-\e/\e.\ew]/i);
\&
\& # Disallow modifications in the tags directory
\& DENY_UPDATE(qr:^tags:);
\&
\& # OpenOffice.org documents need locks
\& CHECK_PROPERTY(qr/\e.(?:od[bcfgimpst]|ot[ghpst])$/i => \*(Aqsvn:needs\-lock\*(Aq);
\&
\& run_hook($0, @ARGV);
.Ve
.PP
Those directives are implemented and exported by the hooks. Note that
using hooks you don't need to be explicit about which one of the nine
hooks will be triggered by the directives. This is on purpose, because
some plugins can trigger more than one hook. The plugin documentation
should tell you which hooks can be triggered so that you know which
symbolic links you need to create in the \fIhooks\fR repository
directory.
.SS "Configuration file"
.IX Subsection "Configuration file"
Before calling the hooks, the function \f(CW\*(C`run_hook\*(C'\fR evaluates a file
called \fIsvn\-hooks.conf\fR under the \fIconf\fR directory in the
repository, if it exists. Hence, you can choose to put all the
directives in this file and not in the script under the \fIhooks\fR
directory.
.PP
The advantage of this is that you can then manage the configuration
file with the \f(CW\*(C`SVN::Hooks::UpdateConfFile\*(C'\fR and have it versioned
under the same repository that it controls.
.PP
One way to do this is to use this hook script:
.PP
.Vb 1
\& #!/usr/bin/perl
\&
\& use SVN::Hooks;
\& use SVN::Hooks::UpdateConfFile;
\& use ...
\&
\& UPDATE_CONF_FILE(
\& \*(Aqconf/svn\-hooks.conf\*(Aq => \*(Aqsvn\-hooks.conf\*(Aq,
\& validator => [qw(/usr/bin/perl \-c)],
\& rotate => 2,
\& );
\&
\& run_hook($0, @ARGV);
.Ve
.PP
Use this hook script and create a directory called \fIconf\fR at the root
of the repository (besides the common \fItrunk\fR, \fIbranches\fR, and
\&\fItags\fR directories). Add the \fIsvn\-hooks.conf\fR file under the \fIconf\fR
directory. Then, whenever you commit a new version of the file, the
pre-commit hook will validate it sintactically (\f(CW\*(C`/usr/bin/perl \-c\*(C'\fR)
and copy its new version to the \fIconf/svn\-hooks.conf\fR file in the
repository. (Read the SVN::Hooks::UpdateConfFile documentation to
understand it in details.)
.PP
Being a Perl script, it's possible to get fancy with the configuration
file, using variables, functions, and whatever. But for most purposes
it consists just in a series of configuration directives.
.PP
Don't forget to end it with the \f(CW\*(C`1;\*(C'\fR statement, though, because it's
evaluated with a \f(CW\*(C`do\*(C'\fR statement and needs to end with a true
expression.
.PP
Please, see the plugins documentation to know about the directives.
.SH "PLUGIN DEVELOPER TUTORIAL"
.IX Header "PLUGIN DEVELOPER TUTORIAL"
Yet to do.
.SH "EXPORT"
.IX Header "EXPORT"
.SS "run_hook"
.IX Subsection "run_hook"
This is responsible to invoke the right plugins depending on the
context in which it was called.
.PP
Its first argument must be the name of the hook that was
called. Usually you just pass \f(CW$0\fR to it, since it knows to extract
the basename of the parameter.
.PP
Its second argument must be the path to the directory where the
repository was created.
.PP
The remaining arguments depend on the hook for which it's being
called, like this:
.IP "\(bu" 4
start-commit repo-path user capabilities txn-name
.IP "\(bu" 4
pre-commit repo-path txn
.IP "\(bu" 4
post-commit repo-path rev
.IP "\(bu" 4
pre-lock repo-path path user
.IP "\(bu" 4
post-lock repo-path user
.IP "\(bu" 4
pre-unlock repo-path path user
.IP "\(bu" 4
post-unlock repo-path user
.IP "\(bu" 4
pre-revprop-change repo-path rev user propname action
.IP "\(bu" 4
post-revprop-change repo-path rev user propname action
.PP
But as these are exactly the arguments Subversion passes when it calls
the hooks, you usually call \f(CW\*(C`run_hook\*(C'\fR like this:
.PP
.Vb 1
\& run_hook($0, @ARGV);
.Ve
.SH "REPOSITORY"
.IX Header "REPOSITORY"
.SH "AUTHOR"
.IX Header "AUTHOR"
Gustavo L. de M. Chaves
.SH "COPYRIGHT AND LICENSE"
.IX Header "COPYRIGHT AND LICENSE"
This software is copyright (c) 2016 by CPqD .
.PP
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.