]> sipb.mit.edu Git - ikiwiki.git/blob - doc/rcs/git.mdwn
trimmed git page
[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 [[!img wiki_edit_flow.svg size=490x align=right]]
9
10 Ikiwiki can run as a git `post-update` hook to update a wiki
11 whenever commits come in. When running as a [[cgi]],
12 ikiwiki automatically commits edited pages, and uses the
13 git history to generate the [[RecentChanges]] page.
14
15 ## git repository setup
16
17 The suggested setup for git is a set of repositories setup like a
18 shallow, single level tree, with a bare repository (meaning that it
19 does not have a working tree checked out) at the root, and various
20 working clones (with working directories) as leaf nodes.  The root
21 (bare) repository is meant to be pushed to and pulled from the various
22 working clones.
23
24 One of the leaf node clone repositories is special; it has srcdir
25 which is used to compile the wiki, and is also used by the
26 [[cgi]] to commit changes made via the web interface. It is special
27 since the `post-update` hook for the bare root repository is used to
28 trigger an update of this repository, and then an ikiwiki refresh
29 updates the published  wiki itself.
30
31 The other (optional) leaf node repositories are meant for you to work
32 on, and commit to, changes should then be pushed to the bare root
33 repository.
34
35 Using three or more of repositories isn't the most obvious set up, but
36 it works the best for typical ikiwiki use. [[ikiwiki-makerepo]] can
37 automate setting this up for the common case where there is no
38 pre-existing wiki. [[tips/Laptop_wiki_with_git]] describes a different
39 way to set up ikiwiki and git.
40
41 ## git repository with multiple committers
42
43 It can be tricky to get the permissions right to allow multiple people to
44 commit to an ikiwiki git repository. As the [[security]] page mentions,
45 for a secure ikiwiki installation, only one person should be able to write
46 to ikiwiki's srcdir. When other committers make commits, their commits
47 should be pushed to the bare repository, which has a `post-update` hook
48 that uses ikiwiki to pull the changes to the srcdir.
49
50 One setup that will work is to put all committers in a group (say,
51 "ikiwiki"), and use permissions to allow that group to commit to the bare git
52 repository. Make both the post-update hook and ikiwiki.cgi be setgid
53 to the group, as well as suid to the user who admins the wiki. The
54 `wrappergroup` [[setup_file_option|usage]] can be used to make the wrappers
55 be setgid to the right group. Then the srcdir, including its git
56 repository, should only be writable by the wiki's admin, and *not* by the
57 group. Take care that ikiwiki uses a umask that does not cause files in
58 the srcdir to become group writable. (umask 022 will work.)
59
60 ## git repository with untrusted committers
61
62 By default, anyone who can commit to the git repository can modify any file
63 on the wiki however they like. A `pre-receive` hook can be set up to limit
64 incoming commits from untrusted users. Then the same limits that are placed
65 on edits via the web will be in effect for commits to git for the users.
66 They will not be allowed to edit locked pages, they will only be able to
67 delete pages that the [[plugins/remove]] configuration allows them to
68 remove, and they will only be allowed to add non-page attachments that the
69 [[plugins/attachment]] configuration allows.
70
71 To enable this, you need to set up the git repository to have multiple
72 committers. Trusted committers, including the user that ikiwiki runs as, 
73 will not have their commits checked by the `pre-receive` hook. Untrusted
74 committers will have their commits checked. The configuration settings to
75 enable are `git_test_receive_wrapper`, which enables generation of a
76 `pre-receive` hook, and `untrusted_committers`, which is a list of
77 usernames of the untrusted committers.
78
79 Note that when the `pre-receive` hook is checking incoming changes, it
80 ignores the git authorship information, and uses the username of the unix
81 user who made the commit. Then tests including the `locked_pages`
82 [[ikiwiki/PageSpec]]
83 are checked to see if that user can edit the pages in the commit.
84
85 You can even set up an [[anonymous_user|tips/untrusted_git_push]], to allow
86 anyone to push changes in via git rather than using the web interface.
87
88 ## Optionally using a local wiki to preview changes
89
90 When working on the "working clones" to add content to your wiki,
91 it is common (but optional) practice to preview your changes using a
92 private wiki on the local host before publishing the updates by
93 sending it to the root repository. If you do want to setup a private
94 wiki, you will have to have another setup file and and an ikiwiki
95 installation on your local machine. You will need all the packages
96 this implies -- a web server, git, ikiwiki, etc.  However, there is a
97 _caveat_: by default, ikiwiki pulls and pushes from `origin`. This is
98 not ideal for the working clones on the local machine, since you might
99 go through several iterations of a page before pushing to the bare
100 root of the repository tree (and thus publishing it on your public wiki).
101 You do not want the action of refreshing the local wiki in order to
102 review your work to accidentally publish the
103 contents before you are ready. In order to prevent the git push that
104 is the normal behaviour of ikiwiki, set the configuration of the local wiki:
105
106       gitorigin_branch => "",
107       ## git post-commit wrapper
108       git_wrapper => "/working/dir/.git/hooks/post-commit",
109
110 Then just committing should refresh the private ikiwiki on the local
111 host.  Now just run `ikiwiki -setup localwiki.setup -getctime` and
112 you should be good to go. (You only need the slow `-getctime` option
113 the first time you run setup.)  Use standard git commands to handle
114 pulling from and pushing to the server.  **Note**: Currently, after
115 pulling changes from the bare root repository, you will need to
116 manually update the local wiki, with a command such as `ikiwiki
117 -setup localwiki.setup -refresh`. This is because git 1.5.4 doesn't
118 have a hook that is run locally after pulling changes. Newer
119 versions of git will have a `post-merge` hook that should work for
120 this purpose.