2012-03-16 02:54:47 +01:00
|
|
|
# gitolite triggers
|
|
|
|
|
2012-06-06 16:30:24 +02:00
|
|
|
[[TOC]]
|
|
|
|
|
2012-03-16 02:54:47 +01:00
|
|
|
## intro and sample rc excerpt
|
|
|
|
|
2012-03-27 12:48:25 +02:00
|
|
|
Gitolite fires off external commands at 7 different times. The [rc][] file
|
2012-03-16 02:54:47 +01:00
|
|
|
specifies what commands to run at each trigger point, but for illustration,
|
|
|
|
here's an excerpt:
|
|
|
|
|
|
|
|
%RC = (
|
|
|
|
|
|
|
|
<...several lines later...>
|
|
|
|
|
|
|
|
# comment out or uncomment as needed
|
|
|
|
# these will run in sequence after post-update
|
|
|
|
POST_COMPILE =>
|
|
|
|
[
|
|
|
|
'post-compile/ssh-authkeys',
|
|
|
|
'post-compile/update-git-configs',
|
|
|
|
'post-compile/update-gitweb-access-list',
|
|
|
|
'post-compile/update-git-daemon-access-list',
|
|
|
|
],
|
|
|
|
|
|
|
|
# comment out or uncomment as needed
|
|
|
|
# these will run in sequence after a new wild repo is created
|
|
|
|
POST_CREATE =>
|
|
|
|
[
|
|
|
|
'post-compile/update-git-configs',
|
|
|
|
'post-compile/update-gitweb-access-list',
|
|
|
|
'post-compile/update-git-daemon-access-list',
|
|
|
|
],
|
|
|
|
|
|
|
|
(As you can see, post-create runs 3 programs that also run from post-compile.
|
|
|
|
This is perfectly fine, by the way)
|
|
|
|
|
2012-05-30 10:44:29 +02:00
|
|
|
## types of trigger programs
|
|
|
|
|
|
|
|
There are two types of trigger programs. Standalone scripts are placed in
|
|
|
|
src/triggers or its subdirectories. They are invoked by being added to a
|
|
|
|
trigger list (using the path after "src/triggers/", as you can see). Such
|
|
|
|
scripts are quick and easy to write in any language of your choice.
|
|
|
|
|
|
|
|
Triggers written as perl modules are placed in src/lib/Gitolite/Triggers.
|
|
|
|
They are invoked by being listed with the package+function name, although even
|
|
|
|
here the 'Gitolite::Triggers' part is skipped. Perl modules have to follow
|
|
|
|
some conventions (see some of the shipped modules to ideas) but the advantage
|
|
|
|
is that they can set environment variables and change the argument list of the
|
|
|
|
gitolite-shell program that invokes them.
|
|
|
|
|
|
|
|
If this does not make sense, please examine a default install of gitolite,
|
|
|
|
paying attention to:
|
|
|
|
|
|
|
|
* the path names in various trigger lists in the rc file
|
|
|
|
* corresponding path names in the src/ directory in gitolite source
|
|
|
|
* and for perl modules, the package names and function names within.
|
|
|
|
|
2012-03-16 02:54:47 +01:00
|
|
|
## manually firing triggers
|
|
|
|
|
|
|
|
...from the server command line is easy. For example:
|
|
|
|
|
|
|
|
gitolite trigger POST_COMPILE
|
|
|
|
|
|
|
|
However if the triggered code depends on arguments (see next section) this
|
|
|
|
won't work. (The `POST_COMPILE` trigger programs all just happen to not
|
|
|
|
require any arguments, so it works).
|
|
|
|
|
2012-03-25 07:13:36 +02:00
|
|
|
## common arguments
|
2012-03-16 02:54:47 +01:00
|
|
|
|
2012-03-25 07:13:36 +02:00
|
|
|
Triggers receive the following arguments:
|
|
|
|
|
|
|
|
1. any arguments mentioned in the rc file (for an example, see the renice
|
|
|
|
command in the PRE_GIT trigger sequence),
|
|
|
|
|
|
|
|
2. the name of the trigger as a string (example, `"POST_COMPILE"`), so you
|
2012-04-05 18:01:23 +02:00
|
|
|
can call the same program from multiple triggers and it can know where it
|
|
|
|
was called from,
|
2012-03-25 07:13:36 +02:00
|
|
|
|
|
|
|
3. followed by zero or more arguments specific to the trigger, as given in
|
|
|
|
the next section.
|
|
|
|
|
2012-04-05 18:01:23 +02:00
|
|
|
## trigger-specific arguments and other details
|
2012-03-25 07:13:36 +02:00
|
|
|
|
2012-04-05 18:01:23 +02:00
|
|
|
Here are the **rest of** the arguments for each trigger, plus a brief
|
|
|
|
description of when the trigger runs:
|
2012-03-27 12:48:25 +02:00
|
|
|
|
2012-05-30 11:16:29 +02:00
|
|
|
* `INPUT` runs before pretty much anything else. INPUT trigger scripts
|
|
|
|
*must* be in perl, since they manipulate the arguments to and the
|
|
|
|
environment of the 'gitolite-shell' program itself. Most commonly they
|
|
|
|
will read/change `@ARGV`, and/or `$ENV{SSH_ORIGINAL_COMMAND}`.
|
|
|
|
|
|
|
|
There are certain conventions to adhere to; please see some of the shipped
|
|
|
|
samples or ask me if you need help writing your own.
|
|
|
|
|
2012-05-25 08:56:52 +02:00
|
|
|
* `ACCESS_1` runs after the first access check. Extra arguments:
|
2012-03-27 12:48:25 +02:00
|
|
|
* repo
|
|
|
|
* user
|
|
|
|
* 'R' or 'W'
|
|
|
|
* 'any'
|
2012-06-06 16:30:24 +02:00
|
|
|
* result (see notes below)
|
2012-03-27 12:48:25 +02:00
|
|
|
|
2012-06-06 16:30:24 +02:00
|
|
|
'result' is the return value of the access() function. If it contains the
|
|
|
|
uppercase word "DENIED", the access was rejected. Otherwise it is the
|
|
|
|
refex that caused the access to succeed.
|
|
|
|
|
|
|
|
*Please note that if access is rejected, gitolite-shell will die as soon
|
|
|
|
as it returns from the trigger*.
|
|
|
|
|
|
|
|
* `ACCESS_2` runs after the second access check, which is invoked by the
|
|
|
|
update hook to check the ref. Extra arguments:
|
2012-03-27 12:48:25 +02:00
|
|
|
* repo
|
|
|
|
* user
|
|
|
|
* any of W, +, C, D, WM, +M, CM, DM
|
|
|
|
* the ref being updated (e.g., 'refs/heads/master')
|
2012-06-06 16:30:24 +02:00
|
|
|
* result
|
|
|
|
* old SHA
|
|
|
|
* new SHA
|
|
|
|
|
|
|
|
`ACCESS_2` also runs on each [VREF][vref] that gets checked. In this case
|
|
|
|
the "ref" argument will start with "VREF/", and the last two arguments
|
|
|
|
won't be passed.
|
|
|
|
|
|
|
|
'result' is similar to `ACCESS_1`, except that it is the *update hook*
|
|
|
|
which dies as soon as access is rejected for the ref or any of the VREFs.
|
|
|
|
Control then returns to git, and then to gitolite-shell, so the `POST_GIT`
|
|
|
|
trigger *will* run.
|
2012-03-27 12:48:25 +02:00
|
|
|
|
2012-04-06 02:57:34 +02:00
|
|
|
* `PRE_GIT` and `POST_GIT` run just before and after the git command.
|
2012-05-25 08:56:52 +02:00
|
|
|
Extra arguments:
|
2012-03-27 12:48:25 +02:00
|
|
|
* repo
|
|
|
|
* user
|
|
|
|
* 'R' or 'W'
|
|
|
|
* 'any'
|
|
|
|
* the git command ('git-receive-pack', 'git-upload-pack', or
|
|
|
|
'git-upload-archive') being invoked.
|
|
|
|
|
|
|
|
* `PRE_CREATE` and `POST_CREATE` run just before and after a new "[wild][]"
|
2012-05-25 08:56:52 +02:00
|
|
|
repo is created by user action. Extra arguments:
|
2012-03-27 12:48:25 +02:00
|
|
|
* repo
|
|
|
|
* user
|
2012-06-14 09:47:34 +02:00
|
|
|
* invoking operation
|
|
|
|
* 'R' for fetch/clone/ls-remote, 'W' for push
|
|
|
|
* can also be anything set by the external command running the
|
|
|
|
trigger (e.g., see the perms and fork commands).
|
2012-03-27 12:48:25 +02:00
|
|
|
|
2012-05-25 08:56:52 +02:00
|
|
|
They are also run when a *normal* repo is created (say by adding a "repo
|
|
|
|
foo" line to the conf file). This case has only one extra argument:
|
|
|
|
* repo
|
|
|
|
|
2012-03-27 12:48:25 +02:00
|
|
|
* `POST_COMPILE` runs after an admin push has successfully "compiled" the
|
|
|
|
config file. By default, the next thing is to update the ssh authkeys
|
|
|
|
file, then all the 'git-config's, gitweb access, and daemon access.
|
|
|
|
|
2012-05-25 08:56:52 +02:00
|
|
|
No extra arguments.
|
2012-06-06 16:30:24 +02:00
|
|
|
|
|
|
|
## tips
|
|
|
|
|
|
|
|
If you have code that latches onto more than one trigger, collecting data
|
|
|
|
(such as for logging), then the outputs may be intermixed. You can record the
|
|
|
|
value of the environment variable `GL_TID` to tie together related entries.
|
|
|
|
|