add warning to repo-specific hooks doc
[gitolite-doc.git] / non-core.mkd
blobe60038ae46148bd5ea9e769da5059adcc91586a7
1 <!-- options: toc -->
3 % "non-core" gitolite
5 include sidebar-toc
7 Much of gitolite's functionality comes from programs and scripts that are not
8 considered "core".  This keeps the core simpler, and allows you to enhance
9 gitolite for your own site without too much fuss.
11 Documentation for non-core gitolite is organised as follows:
13   * This page describes the types of non-core programs and how/where to
14     install code that is specific to your site.
16   * The [developer notes][dev-notes] page tells you how to write your own
17     non-core programs.
19   * The [list of non-core programs][list-non-core] talks about what's already
20     shipped with gitolite, with a brief description of each.
22 ----
24 # core versus non-core {#ncintro}
26 Gitolite has five types of non-core code:
28   * *Commands* can be run from the shell command line.  Among those, the ones
29     in the ENABLE list in the rc file can also be run remotely.
30   * *Hooks* are standard git hooks.
31   * *Sugar scripts* change the conf language for your convenience.  The word
32     sugar comes from "syntactic sugar".
33   * *Triggers* are to gitolite what hooks are to git.  I just chose a
34     different name to avoid confusion and constant disambiguation in the docs.
35   * *VREFs* are extensions to the access control check part of gitolite.
37 # locations... {#ncloc}
39 ## ...for non-core programs shipped with gitolite
41 .#d
43 `gitolite query-rc GL_BINDIR` will tell you where gitolite's code has been
44 installed.  That directory should look like this.  Among these, the
45 directories in green are considered "non-core", while the ones in red are
46 considered "core".  In addition, the two files "gitolite" and "gitolite-shell"
47 in src are also considered "core"
49 You might notice that there are two locations for [triggers][]; that is simply
50 because there are two types of them.  You might also notice that there is no
51 place for hooks -- gitolite doesn't *ship* with any hooks that are non-core.
53 .#d
55 <pre style="font-family: 'Andale mono',monospace; margin-top: 0; font-weight: bold; padding: 4px; color: #ffffff; background-color: #000000;">
58 ├── <span style="color: #00ff00">commands</span>
59 ├── lib
60 │   └── Gitolite
61 │       ├── <span style="color: #ff0000">Conf</span>
62 │       ├── <span style="color: #ff0000">Hooks</span>
63 │       ├── <span style="color: #ff0000">Test</span>
64 │       └── <span style="color: #00ff00">Triggers</span>
65 ├── <span style="color: #00ff00">syntactic-sugar</span>
66 ├── <span style="color: #00ff00">triggers</span>
67 └── <span style="color: #00ff00">VREF</span>
69 </pre>
71 .#t
73 ## ...for *your* non-core programs {#localcode}
75 .#d
77 If you want to add your own non-core programs, or even *override* the shipped
78 ones with your own, you can.
80 Put your programs in some convenient directory and use the `LOCAL_CODE` rc
81 variable to tell gitolite where that is.  **Please supply the FULL path** to
82 this variable.  (You'll find the rc file already has examples lines, commented
83 out, so it's easy to know where to put it and what syntax to use).
85 Within that directory, you can use any or all of the subdirectories shown
86 here.
88 If you add a program in your local code directory with the same name as a
89 shipped program, gitolite uses your version.
91 @@gray(Notice that there are two directories related to hooks here, neither of
92 which exist in the shipped non-core code.  Also, the `hooks/common` directory
93 is a bit special.  If you add new hooks to this, you must run `gitolite
94 setup`, or at least `gitolite setup --hooks-only`.)@@
96 .#d
98 <pre style="float: right; font-family: 'Andale mono',monospace; margin-top: 0; font-weight: bold; padding: 4px; color: #ffffff; background-color: #000000;">
101 ├── <span style="color: #00ff00">commands</span>
102 ├── hooks
103 │   └── <span style="color: #00ff00">common</span>
104 │   └── <span style="color: #00ff00">repo-specific</span>
105 ├── lib
106 │   └── Gitolite
107 │       └── <span style="color: #00ff00">Triggers</span>
108 ├── <span style="color: #00ff00">syntactic-sugar</span>
109 ├── <span style="color: #00ff00">triggers</span>
110 └── <span style="color: #00ff00">VREF</span>
112 </pre>
116 ## using the gitolite-admin repo to manage non-core code {#pushcode}
118 <div class="box-r" style="margin-left:4px; width: 33%">
120 @@red(**IMPORTANT SECURITY NOTE**)@@
122 **In this mode, anyone who can push changes to the admin repo will effectively
123 be able to run any arbitrary command on the server.**  See [gitolite admin and
124 shell access][privesc] for more background.
126 </div>
128 The location given in `LOCAL_CODE` could be anywhere on disk, like say
129 `$ENV{HOME}/local`.
131 However, some administrators find it convenient to use the admin repo to
132 manage this code as well, getting the benefits of versioning them as well as
133 making changes to them without having to log on to the server.
135 To do this, simply point `LOCAL_CODE` to someplace inside `$GL_ADMIN_BASE` in
136 the rc file.  I **strongly** suggest:
138     LOCAL_CODE  =>  "$rc{GL_ADMIN_BASE}/local",
140 Then you create a directory called "local" in your gitolite clone, and create
141 the directory structure (shown in the previous section) within that directory.
142 Thus, when you push the admin repo, the files will land up, with the correct
143 paths, in the location pointed to by LOCAL\_CODE.
145 (Note: when you do this, gitolite takes care of running `gitolite setup
146 --hooks-only` when you change any hooks and push).
148 # types of non-core programs {#nctypes}
150 ## gitolite "commands" {#commands}
152 Gitolite comes with several commands that users can run.  Remote users run
153 commands by saying:
155     ssh git@host command-name [args...]
157 while on the server you can run
159     gitolite command [args...]
161 Very few commands are designed to be run both ways, but it can be done, by
162 checking for the presence of env var `GL_USER`.
164 All commands respond to a single `-h` option with a suitable message.
166 You can get a **list of available commands** by using the `help` command.
167 Naturally, a remote user will see a much smaller list than the server user.
169 You allow a command to be run from remote clients by adding its name to (or
170 uncommenting it if it's already added but commented out) the ENABLE list in
171 the [rc][] file.
173 ## hooks and gitolite {#hooks}
175 You can install any hooks except these:
177   * (all repos) Gitolite reserves the `update` hook.  See the "update hook"
178     section in [dev-notes][] if you want additional update hook functionality.
180   * (gitolite-admin repo only) Gitolite reserves the `post-update` hook.
182 How/where to install them is described in detail in the "locations" section
183 above, especially [this][localcode] and [this][pushcode].  The summary is that
184 you put them in the "hooks/common" sub-directory within the directory whose
185 name is given in the `LOCAL_CODE` rc variable, then run `gitolite setup`.
187 ### repo-specific hooks {#rsh}
189 @@red(**WARNING**: If your site makes a distinction between "right to push the
190 admin repo" and "right to run arbitrary commands on the server" (i.e., if not
191 all of your "admins" have shell access to the server), this is a security
192 risk. If that is the case, **do not enable this feature**.)@@
194 If you want to add hooks only to specific repos, you can just do it manually
195 if you wish -- just log on to the server and add hooks (except update hook
196 and, for the special gitolite-admin repo, the post-update hook -- touch these
197 and all bets on gitolite's functionality are off).
199 However, if you want to do that from within gitolite, and thus keep everything
200 together, you can do that also.  Here's how.
202   * Create a directory called `hooks/repo-specific` in whatever location you
203     decided to use for your non-core code (i.e., direct on the server, or
204     within the gitolite-admin repo).
206   * Add your hooks here, with descriptive names (i.e., not "post-receive",
207     etc., but maybe "jenkins" or "deploy" or whatever).
209   * Uncomment the 'repo-specific-hooks' line in the rc file or add it to the
210     ENABLE list if it doesn't exist.
212     If your rc file does not have an ENABLE list, you need to add this to the
213     POST_COMPILE and the POST_CREATE lists.  Click [here][addtrig] for more on
214     all this.
216   * Now add lines like this to your conf file:
217 .#! conf/vim-color
218         repo    foo
219             option hook.post-receive    =   deploy
220 .end
222     The syntax should be fairly obvious, but just to be clear, in this case a
223     symlink called "post-receive" will be placed in foo.git/hooks, pointing to
224     the executable called "deploy" in hooks/repo-specific in the local-code
225     area.
227     **WARNING**: if the hook already exists, it is silently overwritten.
229     **WARNING**: @@gray((v3.5.x or below))@@ once the hook is placed, you can't remove it through
230     gitolite.  That is, removing the option line won't do anything.  You'll
231     have to go to the server and remove it manually.
233   * @@gray((v3.6+))@@ You can assign multiple targets for each hook.  For
234     example, you could say
235 .#! conf/vim-color
236         repo    foo
237             option hook.post-receive    =   deploy mail-admins
238 .end
240     where "deploy" and "mail-admins" are pieces of code that do whatever their
241     names suggest, and both are, independently, candidates for being run from
242     a post-receive hook.
244     When you do this, gitolite does whatever is needed to run each of them as
245     independent post-receive hooks (including sending them info over their
246     STDIN as documented in 'man githooks').
248   * @@gray((v3.6+))@@ You can change these hooks by saying:
249 .#! conf/vim-color
250         repo    foo
251             option hook.post-receive    =   deploy mail-admins
252 .end
254     or delete all of them by saying:
255 .#! conf/vim-color
256         repo    foo
257             option hook.post-receive    =   ""
258 .end
260 ## syntactic sugar {#sugar}
262 Sugar scripts help you change the perceived syntax of the conf language.  The
263 base syntax of the language is very simple, so sugar scripts take something
264 *else* and convert it into that.
266 That way, the admin sees additional features (like allowing continuation
267 lines), while the parser in the core gitolite engine does not change.
269 If you want to write your own sugar scripts, please read the "your own sugar"
270 section in [dev-notes][] first then email me.
272 You enable a sugar script by uncommenting the feature name in the ENABLE list
273 in the rc file.
275 ## triggers
277 Triggers have their own [page][triggers].
279 ## VREFs
281 VREFs also have their own [page][vref].