gitolite/doc/dev-notes.mkd

118 lines
3.9 KiB
Markdown
Raw Normal View History

2012-03-16 02:54:47 +01:00
# notes for developers
2012-05-18 09:18:43 +02:00
[[TOC]]
----
2012-03-16 02:54:47 +01:00
Gitolite has a huge bunch of existing features that gradually need to moved
over. Plus you may want to write your own programs to interact with it.
Here are some random notes on developing hooks, commands, triggers, and sugar
scripts.
2012-03-26 08:23:00 +02:00
## environment variables and other inputs
2012-03-16 02:54:47 +01:00
In general, the following environment variables should always be available:
GL_BINDIR
GL_REPO_BASE
GL_ADMIN_BASE
Commands invoked by a remote client will also have `GL_USER` set. Hooks will
have `GL_REPO` also set.
Finally, note that triggers get a lot of relevant information from gitolite as
arguments; see [here][triggers] for details.
2012-03-26 08:23:00 +02:00
2012-03-16 02:54:47 +01:00
## APIs
### the shell API
The following commands exist to help you write shell scripts that interact
easily with gitolite. Each of them responds to `-h` so please run that for
2012-03-16 02:54:47 +01:00
more info.
* `gitolite access` to check access rights given repo, user, type of access
2012-04-17 03:13:13 +02:00
(R, W, ...) and refname (optional). Example use: src/commands/desc.
2012-03-16 02:54:47 +01:00
* `gitolite creator` to get/check the creator of a repo. Example use:
2012-04-17 03:13:13 +02:00
src/commands/desc.
2012-03-16 02:54:47 +01:00
* `gitolite git-config` to check gitolite options or git config variables
directly from gitolite's "compiled" output, (i.e., without looking at the
2012-03-16 02:54:47 +01:00
actual `repo.git/config` file or using the `git config` command). Example
2012-05-18 09:18:43 +02:00
use: src/triggers/post-compile/update-gitweb-access-list.
2012-03-16 02:54:47 +01:00
* `gitolite query-rc` to check the value of an RC variable. Example use:
src/commands/desc.
2012-04-14 09:15:53 +02:00
In addition, you can also look at the comments in src/lib/Gitolite/Easy.pm
(the perl API module) for ideas.
2012-03-16 02:54:47 +01:00
### the perl API
2012-04-14 09:15:53 +02:00
...is implemented by Gitolite::Easy; the comments in src/lib/Gitolite/Easy.pm
2012-03-27 08:01:02 +02:00
serve as documentation.
2012-03-16 02:54:47 +01:00
## writing your own...
### ...hooks
2012-03-16 02:54:47 +01:00
#### anything but the update hook
2012-03-16 02:54:47 +01:00
If you want to add your own hook, it's easy as long as it's not the 'update'
hook. Just add it to `$HOME/.gitolite/hooks/common` and run `gitolite setup`.
The rest is between you and 'man githooks' :-)
#### update hook
2012-03-16 02:54:47 +01:00
If you want to add additional `update` hook functionality, do this:
2012-04-17 03:13:13 +02:00
* Write and test your update hook separately from gitolite.
2012-03-16 02:54:47 +01:00
2012-04-17 03:13:13 +02:00
* Now add the code to src/VREF. Let's say it is called "foo".
2012-03-16 02:54:47 +01:00
2012-04-17 03:13:13 +02:00
* To call your new update hook to all accesses for all repos, add this to
2012-03-16 02:54:47 +01:00
the end of your conf file:
repo @all
- VREF/foo = @all
As you probably guessed, you can now make your additional update hooks more
selective, applying them only to some repos / users / combinations.
Note: a normal update hook expects 3 arguments (ref, old SHA, new SHA). A
VREF will get those three, followed by at least 4 more. Your VREF should just
ignore the extra args.
### ...commands
2012-03-16 02:54:47 +01:00
You can add your own commands. You can run them on the server (example,
`gitolite access`). Then you can enable certain commands to be allowed to run
by a remote user by adding them to the "COMMANDS" hash of the [rc][] file.
Commands are standalone programs, in any language you like. They simply
receive the arguments you append. In addition, the env var `GL_USER` is
available if it is being run remotely. src/commands/desc is the best example
at present.
### ...trigger programs
2012-03-16 02:54:47 +01:00
Trigger programs run at specific points in gitolite's execution, with specific
arguments being passed to them. See the [triggers][] page for details.
2012-03-16 02:54:47 +01:00
You can write programs that are both manually runnable as well as callable by
trigger events, especially if they don't *need* any arguments.
### ..."sugar"
2012-03-16 02:54:47 +01:00
Syntactic sugar helpers are NOT complete, standalone, programs. They must
include a perl sub called `sugar_script` that takes in a listref, and returns
a listref. The listrefs point to a list that contains the entire conf file
(with all [include][] processing already done). You create a new list with
contents modified as you like and return a ref to it.
There are a couple of examples in src/syntactic-sugar.