]> 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. Nominally, this bare repository has a `post-commit`
51   hook that would change directory to the ikiwiki leaf node repository
52   below (the working directory for ikiwiki), do a _git pull_, and
53   refresh ikiwiki to regenerate the wiki with any new content.
54 * The second repository is a clone of the bare root repository, and
55   has a working tree which is used as ikiwiki's srcdir for compiling
56   the wiki. **Never** push to this repository. When running as a
57   [[cgi]], the changes are committed to this repository, and pushed to
58   the master repository above. This is called _srcdir_ in
59   [[ikiwiki-makerepo]]'s manual page.
60 * The other (third, fourth, fifth, sixth -- however many pleases you)
61   repositories are also clones of the bare root repository above --
62   and these have a working directory for you to work on. Use either
63   the `git` transport (if available), or `ssh`. These repositories may
64   be on remote machines, your laptop, whereever you find convenient to
65   hack on your wiki. you can commit local changes to the version on
66   the laptop, perhaps while offline. You can browse and edit the wiki
67   using a local web server. Any new content should be pushed to the
68   bare master repository when you are ready to publish it, and then
69   the post-commit hook of the bare repository will ensure that the
70   ikiwiki's source directory is updated, and the ikiwiki refreshed
71   with the new content.
72
73 Using three or more of repositories isn't the most obvious set up, but
74 it works the best for typical ikiwiki use. [[ikiwiki-makerepo]] can
75 automate setting this up for the common case where there is no
76 pre-existing wiki. [[tips/Laptop_wiki_with_git]] describes a different
77 way to set up ikiwiki and git.
78
79 It is **paramount** that you **never** push to the non-bare repository
80 ([this FAQ entry explains why](http://git.or.cz/gitwiki/GitFaq#head-b96f48bc9c925074be9f95c0fce69bcece5f6e73)).
81 Instead, clone the bare repository as mentioned above, and push
82 **only** to the bare repository.
83
84 The ikiwiki `post-commit` hook should be put in the bare repository.
85
86 ## git repository with multiple committers
87
88 It can be tricky to get the permissions right to allow multiple people to
89 commit to an ikiwiki git repository. As the [[security]] page mentions,
90 for a secure ikiwiki installation, only one person should be able to write
91 to ikiwiki's srcdir. When other committers make commits, their commits
92 should go to the bare repository, which has a `post-update` hook that uses
93 ikiwiki to pull the changes to the srcdir.
94
95 One setup that will work is to put all committers in a group (say,
96 "ikiwiki"), and use permissions to allow that group to commit to the bare git
97 repository. Make both the post-update hook and ikiwiki.cgi be setgid
98 to the group, as well as suid to the user who admins the wiki. The
99 `wrappergroup` [[setup_file_option|usage]] can be used to make the wrappers
100 be setgid to the right group. Then the srcdir, including its git
101 repository, should only be writable by the wiki's admin, and *not* by the
102 group. Take care that ikiwiki uses a umask that does not cause files in
103 the srcdir to become group writable. (umask 022 will work.)
104
105 ## Configuration
106
107 ### Ikiwiki working directory
108
109 * Configure a cgi wrapper as usual, but configure the git wrapper to
110   be written to the post-commit hook of the git clone being used by
111   the ikiwiki (clone 0 in the image). Set in the configuration:
112
113         gitorigin_branch=> "origin",
114         ## git post-commit wrapper
115         wrapper => "/path/to/bare/repo/.git/hooks/post-commit",
116
117
118
119 ### Working clones (Clone 1 .. N in the image)
120
121 * By default, ikiwiki pulls and pushes from `origin`. This is not
122   ideal for the working clones, since the user might go through
123   several iterations of a posting before pushing to the bare root of
124   the repository tree. In the configuration, set:
125
126         gitorigin_branch => "",
127         ## git post-commit wrapper
128         wrapper => "/working/dir/.git/hooks/post-commit",
129
130   Then just committing should refresh the ikiwiki on the local host.
131
132 * You can optionally enable to the [[plugins/mirrorlist]] plugin,
133   and configure it so that each page links to the corresponding page on the
134   server.
135
136 Now just run `ikiwiki -setup wiki.setup -getctime` and you should be
137 good to go. (You only need the slow `-getctime` option the first time you
138 run setup.)
139
140 Use standard git commands to handle pulling from and pushing to the server.
141
142 Note: Currently, after pulling changes, you will need to manually update
143 the wiki, with a command such as `ikiwiki -setup wiki.setup -refresh`. This
144 is because git 1.5.4 doesn't have a hook that is run locally after pulling
145 changes. Newer versions of git will have a `post-merge` hook that should
146 work for this purpose.