]> sipb.mit.edu Git - ikiwiki.git/blob - doc/rcs/git.mdwn
web commit by ManojSrivastava
[ikiwiki.git] / doc / rcs / git.mdwn
1 [[meta title="Git"]]
2
3 [Git][git] is a distributed revison control system originally developed for
4 the Linux kernel. Ikiwiki supports storing a wiki in git.
5
6 [git]: http://git.or.cz/
7
8 Ikiwiki can run as a `post-update` hook to update a wiki whenever commits
9 come in. When running as a [[cgi]] with Git, ikiwiki automatically
10 commits edited pages, and uses the Git history to generate the
11 [[RecentChanges]] page.
12
13 ## git repository setup
14
15 The suggested setup for git is a set of repositories setup like a
16 shallow, single level tree, with a bare repository (meaning that it
17 does not have a working tree checked out) at the root, and various
18 working clones (with working directories) as leaf nodes.  The root
19 (bare) repository is meant to be pushed to and pulled from the various
20 working clones. The image below displays the relationship between the
21 root repository and the clone repositories (this is not a directory
22 layout):
23
24 ![Git repository relationships](http://people.debian.org/~srivasta/ikiwiki_git.png)
25
26 One of the leaf node clone repositories is special; it has working
27 directory which is used to compile the wiki from, and is also used by the
28 [[cgi]] to commit changes made via the web interface. It is special
29 since the `post-commit` hook for the bare root repository is used to
30 trigger an update of this repository, and then an ikiwiki refresh
31 updates the published  wiki itself.
32
33 The other (optional) leaf node repositories are meant for you to work
34 on, and commit to, changes should then be pushed to the bare root
35 repository.  In theory, you could work on the same leaf node repository
36 that ikiwiki uses to compile the wiki from, and the [[cgi]] commits
37 to, as long as you ensure that permissions and ownership don't hinder
38 the working of the [[cgi]]. This can be done, for example, by using
39 ACL's, in practice, it is easier to just setup separate clones for
40 yourself.
41
42 So, to reiterate, when using Git, you probably want to set up three
43 repositories:
44
45 * The root repository. This should be a bare repository (meaning that
46   it does not have a working tree checked out), which the other
47   repositories will push to/pull from.  It is a bare repository, since
48   there are problems pushing to a repository that has a working
49   directory. This is called _repository_ in [[ikiwiki-makerepo]]'s
50   manual page. 
51
52   Nominally, this bare repository has a `post-commit` hook that either
53   is or calls ikiwiki's git wrapper, which changes to the working
54   directory for ikiwiki, does a _git pull_, and refreshes ikiwiki to
55   regenerate the wiki with any new content.
56
57   The configuration sections below show how to let the post-commit
58   hook be replaced by the ikiwiki git wrapper.
59 * The second repository is a clone of the bare root repository, and
60   has a working tree which is used as ikiwiki's srcdir for compiling
61   the wiki. **Never** push to this repository. When running as a
62   [[cgi]], the changes are committed to this repository, and pushed to
63   the master repository above. This is called _srcdir_ in
64   [[ikiwiki-makerepo]]'s manual page.
65 * The other (third, fourth, fifth, sixth -- however many pleases you)
66   repositories are also clones of the bare root repository above --
67   and these have a working directory for you to work on. Use either
68   the `git` transport (if available), or `ssh`. These repositories may
69   be on remote machines, your laptop, whereever you find convenient to
70   hack on your wiki. you can commit local changes to the version on
71   the laptop, perhaps while offline. You can browse and edit the wiki
72   using a local web server. Any new content should be pushed to the
73   bare master repository when you are ready to publish it, and then
74   the post-commit hook of the bare repository will ensure that the
75   ikiwiki's source directory is updated, and the ikiwiki refreshed
76   with the new content.
77
78 Using three or more of repositories isn't the most obvious set up, but
79 it works the best for typical ikiwiki use. [[ikiwiki-makerepo]] can
80 automate setting this up for the common case where there is no
81 pre-existing wiki. [[tips/Laptop_wiki_with_git]] describes a different
82 way to set up ikiwiki and git.
83
84 It is **paramount** that you **never** push to the non-bare repository
85 ([this FAQ entry explains why](http://git.or.cz/gitwiki/GitFaq#head-b96f48bc9c925074be9f95c0fce69bcece5f6e73)).
86 Instead, clone the bare repository as mentioned above, and push
87 **only** to the bare repository.
88
89 The ikiwiki `post-commit` hook should be put in the bare repository.
90
91 ## git repository with multiple committers
92
93 It can be tricky to get the permissions right to allow multiple people to
94 commit to an ikiwiki git repository. As the [[security]] page mentions,
95 for a secure ikiwiki installation, only one person should be able to write
96 to ikiwiki's srcdir. When other committers make commits, their commits
97 should go to the bare repository, which has a `post-update` hook that uses
98 ikiwiki to pull the changes to the srcdir.
99
100 One setup that will work is to put all committers in a group (say,
101 "ikiwiki"), and use permissions to allow that group to commit to the bare git
102 repository. Make both the post-update hook and ikiwiki.cgi be setgid
103 to the group, as well as suid to the user who admins the wiki. The
104 `wrappergroup` [[setup_file_option|usage]] can be used to make the wrappers
105 be setgid to the right group. Then the srcdir, including its git
106 repository, should only be writable by the wiki's admin, and *not* by the
107 group. Take care that ikiwiki uses a umask that does not cause files in
108 the srcdir to become group writable. (umask 022 will work.)
109
110 ## Configuration of working clone repositories
111
112 These are repositories (Clone 1 .. N in the image) usually setup to
113 avoid permission problems with the working directory used by ikiwiki
114 itself. They also represent the most convenient way to add content to
115 the wiki on a different machine (that is, not the machine the wiki is
116 published on) which is more convenient.
117
118 The use case for these clones is this: If you want to edit your wiki
119 on your development box, or on your laptop, you usually set up a clone
120 as above. But very often, you also want to test what the changes look
121 like, locally, before pushing it to the root repository and publishing
122 the wiki for the world to see.
123
124 In order to do this, you should another setup file and setup a private
125 ikiwiki on the local machine (your laptop, for instance) where you do
126 most of your editing.  You will also need to set up a webserver, and
127 install ikiwiki on this machine. Only when you are happy with any
128 changes do you push them to the root repository.
129
130 Here are some things to be aware of when configuring ikiwiki on the
131 local machine:
132
133 * By default, ikiwiki pulls and pushes from `origin`. This is not
134   ideal for the working clones on the local machine, since you might
135   go through several iterations of a page before pushing to the bare
136   root of the repository tree and publishing it on your public
137   wiki. In the configuration, set:
138
139         gitorigin_branch => "",
140         ## git post-commit wrapper
141         wrapper => "/working/dir/.git/hooks/post-commit",
142
143   Then just committing should refresh the private ikiwiki on the local
144   host.
145
146 * You can optionally enable to the [[plugins/mirrorlist]] plugin,
147   and configure it so that each page links to the corresponding page on the
148   server.
149
150 Now just run `ikiwiki -setup wiki.setup -getctime` and you should be
151 good to go. (You only need the slow `-getctime` option the first time you
152 run setup.)
153
154 Use standard git commands to handle pulling from and pushing to the server.
155
156 Note: Currently, after pulling changes, you will need to manually update
157 the wiki, with a command such as `ikiwiki -setup wiki.setup -refresh`. This
158 is because git 1.5.4 doesn't have a hook that is run locally after pulling
159 changes. Newer versions of git will have a `post-merge` hook that should
160 work for this purpose.