]> sipb.mit.edu Git - ikiwiki.git/blob - doc/rcs/git.mdwn
removed
[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.
21
22 One of the leaf node clone repositories is special; it has working
23 directory which is used to compile the wiki, and is also used by the
24 [[cgi]] to commit changes made via the web interface. It is special
25 since the `post-update` hook for the bare root repository is used to
26 trigger an update of this repository, and then an ikiwiki refresh
27 updates the published  wiki itself.
28
29 The other (optional) leaf node repositories are meant for you to work
30 on, and commit to, changes should then be pushed to the bare root
31 repository.
32
33 So, to reiterate, when using Git, you probably want to set up three
34 repositories:
35
36 * The root repository. This should be a bare repository (meaning that
37   it does not have a working tree checked out), which the other
38   repositories will push to/pull from.  It is a bare repository, since
39   git does not support pushing to a repository that has a working
40   directory. This is called _repository_ in [[ikiwiki-makerepo]]'s
41   manual page. This bare repository has a `post-update` hook
42   that either is or calls ikiwiki's git wrapper, which changes to the
43   working directory for ikiwiki, does a `git pull`, and refreshes ikiwiki
44   to regenerate the wiki with any new content. The [[setup]] page describes
45   how to do this.
46
47 * The second repository is a clone of the bare root repository, and
48   has a working tree which is used as ikiwiki's srcdir for compiling
49   the wiki. **Never** push to this repository. It is wise to not make
50   changes or commits directly to this repository, to avoid conflicting
51   with ikiwiki's own changes. When running as a [[cgi]], the changes
52   are committed to this repository, and pushed to the master repository
53   above. This is called _srcdir_ in [[ikiwiki-makerepo]]'s manual page.
54
55 * The other (third, fourth, fifth, sixth -- however many pleases you)
56   repositories are also clones of the bare root repository above --
57   and these have a working directory for you to work on. Use either
58   the `git` transport (if available), or `ssh`. These repositories may
59   be on remote machines, your laptop, wherever you find convenient to
60   hack on your wiki. You can commit local changes to the version on
61   the laptop, perhaps while offline. Any new content should be pushed to the
62   bare master repository when you are ready to publish it, and then
63   the post-update hook of the bare repository will ensure that the
64   ikiwiki's source directory is updated, and the ikiwiki refreshed
65   with the new content.
66
67 Using three or more of repositories isn't the most obvious set up, but
68 it works the best for typical ikiwiki use. [[ikiwiki-makerepo]] can
69 automate setting this up for the common case where there is no
70 pre-existing wiki. [[tips/Laptop_wiki_with_git]] describes a different
71 way to set up ikiwiki and git.
72
73 It is **paramount** that you **never** push to the non-bare repository
74 ([this FAQ entry explains why](http://git.or.cz/gitwiki/GitFaq#head-b96f48bc9c925074be9f95c0fce69bcece5f6e73)).
75 Instead, clone the bare repository as mentioned above, and push
76 **only** to the bare repository.
77
78 The ikiwiki `post-update` hook should be put in the bare repository.
79
80 ## git repository with multiple committers
81
82 It can be tricky to get the permissions right to allow multiple people to
83 commit to an ikiwiki git repository. As the [[security]] page mentions,
84 for a secure ikiwiki installation, only one person should be able to write
85 to ikiwiki's srcdir. When other committers make commits, their commits
86 should be pushed to the bare repository, which has a `post-update` hook
87 that uses ikiwiki to pull the changes to the srcdir.
88
89 One setup that will work is to put all committers in a group (say,
90 "ikiwiki"), and use permissions to allow that group to commit to the bare git
91 repository. Make both the post-update hook and ikiwiki.cgi be setgid
92 to the group, as well as suid to the user who admins the wiki. The
93 `wrappergroup` [[setup_file_option|usage]] can be used to make the wrappers
94 be setgid to the right group. Then the srcdir, including its git
95 repository, should only be writable by the wiki's admin, and *not* by the
96 group. Take care that ikiwiki uses a umask that does not cause files in
97 the srcdir to become group writable. (umask 022 will work.)
98
99 ## git repository with untrusted committers
100
101 By default, anyone who can commit to the git repository can modify any file
102 on the wiki however they like. A `pre-receive` hook can be set up to limit
103 incoming commits from untrusted users. Then the same limits that are placed
104 on edits via the web will be in effect for commits to git for the users.
105 They will not be allowed to edit locked pages, they will only be able to
106 delete pages that the [[plugins/remove]] configuration allows them to
107 remove, and they will only be allowed to add non-page attachments that the
108 [[plugins/attachment]] configuration allows.
109
110 To enable this, you need to set up the git repository to have multiple
111 committers. Trusted committers, including the user that ikiwiki runs as, 
112 will not have their commits checked by the `pre-receive` hook. Untrusted
113 committers will have their commits checked. The configuration settings to
114 enable are `git_test_receive_wrapper`, which enables generation of a
115 `pre-receive` hook, and `untrusted_committers`, which is a list of
116 usernames of the untrusted committers.
117
118 Note that when the `pre-receive` hook is checking incoming changes, it
119 ignores the git authorship information, and uses the username of the unix
120 user who made the commit. Then tests including the `locked_pages` [[PageSpec]]
121 are checked to see if that user can edit the pages in the commit.
122
123 You can even set up an [[anonymous_user|tips/untrusted_git_push]], to allow
124 anyone to push changes in via git rather than using the web interface.
125
126 ## Optionally using a local wiki to preview changes
127
128 When working on the "working clones" to add content to your wiki,
129 it is common (but optional) practice to preview your changes using a
130 private wiki on the local host before publishing the updates by
131 sending it to the root repository. If you do want to setup a private
132 wiki, you will have to have another setup file and and an ikiwiki
133 installation on your local machine. You will need all the packages
134 this implies -- a web server, git, ikiwiki, etc.  However, there is a
135 _caveat_: by default, ikiwiki pulls and pushes from `origin`. This is
136 not ideal for the working clones on the local machine, since you might
137 go through several iterations of a page before pushing to the bare
138 root of the repository tree (and thus publishing it on your public wiki).
139 You do not want the action of refreshing the local wiki in order to
140 review your work to accidentally publish the
141 contents before you are ready. In order to prevent the git push that
142 is the normal behaviour of ikiwiki, set the configuration of the local wiki:
143
144       gitorigin_branch => "",
145       ## git post-commit wrapper
146       git_wrapper => "/working/dir/.git/hooks/post-commit",
147
148 Then just committing should refresh the private ikiwiki on the local
149 host.  Now just run `ikiwiki -setup localwiki.setup -getctime` and
150 you should be good to go. (You only need the slow `-getctime` option
151 the first time you run setup.)  Use standard git commands to handle
152 pulling from and pushing to the server.  **Note**: Currently, after
153 pulling changes from the bare root repository, you will need to
154 manually update the local wiki, with a command such as `ikiwiki
155 -setup localwiki.setup -refresh`. This is because git 1.5.4 doesn't
156 have a hook that is run locally after pulling changes. Newer
157 versions of git will have a `post-merge` hook that should work for
158 this purpose.
159
160 ## Fix for error on git pull origin
161
162 Error message when running git pull origin:
163
164     You asked me to pull without telling me which branch you
165     want to merge with, and 'branch.master.merge' in
166     your configuration file does not tell me either.  Please
167     name which branch you want to merge on the command line and
168     try again (e.g. 'git pull <repository> <refspec>').
169     See git-pull(1) for details on the refspec.
170     
171     If you often merge with the same branch, you may want to
172     configure the following variables in your configuration
173     file:
174     
175         branch.master.remote = <nickname>
176         branch.master.merge = <remote-ref>
177         remote.<nickname>.url = <url>
178         remote.<nickname>.fetch = <refspec>
179     
180     See git-config(1) for details.
181
182 The solution is to run this command in your srcdir:
183
184     git config branch.master.remote origin