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