t1300: attempting to remove a non-existent .git/config is not an error
[git/jnareb-git.git] / gitweb / README
bloba9988200d6b67066b837e7298e0e1529057a4bca
1 GIT web Interface
2 =================
4 The one working on:
5   http://git.kernel.org/
7 From the git version 1.4.0 gitweb is bundled with git.
10 Runtime gitweb configuration
11 ----------------------------
13 Gitweb obtains configuration data from the following sources in the
14 following order:
16 1. built-in values (some set during build stage),
17 2. common system-wide configuration file (`GITWEB_CONFIG_COMMON`,
18    defaults to '/etc/gitweb-common.conf'),
19 3. either per-instance configuration file (`GITWEB_CONFIG`, defaults to
20    'gitweb_config.perl' in the same directory as the installed gitweb),
21    or if it does not exists then system-wide configuration file
22    (`GITWEB_CONFIG_SYSTEM`, defaults to '/etc/gitweb.conf').
24 Values obtained in later configuration files override values obtained earlier
25 in above sequence.
27 You can read defaults in system-wide GITWEB_CONFIG_SYSTEM from GITWEB_CONFIG
28 by adding
30   read_config_file($GITWEB_CONFIG_SYSTEM);
32 at very beginning of per-instance GITWEB_CONFIG file.  In this case
33 settings in said per-instance file will override settings from
34 system-wide configuration file.  Note that read_config_file checks
35 itself that the $GITWEB_CONFIG_SYSTEM file exists.
37 The most notable thing that is not configurable at compile time are the
38 optional features, stored in the '%features' variable.
40 Ultimate description on how to reconfigure the default features setting
41 in your `GITWEB_CONFIG` or per-project in `project.git/config` can be found
42 as comments inside 'gitweb.cgi'.
44 See also the "Gitweb config file" (with an example of config file), and
45 the "Gitweb repositories" sections in INSTALL file for gitweb.
48 The gitweb config file is a fragment of perl code. You can set variables
49 using "our $variable = value"; text from "#" character until the end
50 of a line is ignored. See perlsyn(1) man page for details.
52 Below is the list of variables which you might want to set in gitweb config.
53 See the top of 'gitweb.cgi' for the full list of variables and their
54 descriptions.
56 Gitweb config file variables
57 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59 You can set, among others, the following variables in gitweb config files
60 (with the exception of $projectroot and $projects_list this list does
61 not include variables usually directly set during build):
62  * $GIT
63    Core git executable to use.  By default set to "$GIT_BINDIR/git", which
64    in turn is by default set to "$(bindir)/git".  If you use git from binary
65    package, set this to "/usr/bin/git".  This can just be "git" if your
66    webserver has a sensible PATH.  If you have multiple git versions
67    installed it can be used to choose which one to use.
68  * $version
69    Gitweb version, set automatically when creating gitweb.cgi from
70    gitweb.perl. You might want to modify it if you are running modified
71    gitweb.
72  * $projectroot
73    Absolute filesystem path which will be prepended to project path;
74    the path to repository is $projectroot/$project.  Set to
75    $GITWEB_PROJECTROOT during installation.  This variable have to be
76    set correctly for gitweb to find repositories.
77  * $projects_list
78    Source of projects list, either directory to scan, or text file
79    with list of repositories (in the "<URI-encoded repository path> SP
80    <URI-encoded repository owner>" line format; actually there can be
81    any sequence of whitespace in place of space (SP)).  Set to
82    $GITWEB_LIST during installation.  If empty, $projectroot is used
83    to scan for repositories.
84  * $my_url, $my_uri
85    Full URL and absolute URL of gitweb script;
86    in earlier versions of gitweb you might have need to set those
87    variables, now there should be no need to do it.  See
88    $per_request_config if you need to set them still.
89  * $base_url
90    Base URL for relative URLs in pages generated by gitweb,
91    (e.g. $logo, $favicon, @stylesheets if they are relative URLs),
92    needed and used only for URLs with nonempty PATH_INFO via
93    <base href="$base_url">.  Usually gitweb sets its value correctly,
94    and there is no need to set this variable, e.g. to $my_uri or "/".
95    See $per_request_config if you need to set it anyway.
96  * $home_link
97    Target of the home link on top of all pages (the first part of view
98    "breadcrumbs").  By default set to absolute URI of a page ($my_uri).
99  * @stylesheets
100    List of URIs of stylesheets (relative to base URI of a page). You
101    might specify more than one stylesheet, for example use gitweb.css
102    as base, with site specific modifications in separate stylesheet
103    to make it easier to upgrade gitweb. You can add 'site' stylesheet
104    for example by using
105       push @stylesheets, "gitweb-site.css";
106    in the gitweb config file.
107  * $logo_url, $logo_label
108    URI and label (title) of GIT logo link (or your site logo, if you choose
109    to use different logo image). By default they point to git homepage;
110    in the past they pointed to git documentation at www.kernel.org.
111  * $projects_list_description_width
112    The width (in characters) of the projects list "Description" column.
113    Longer descriptions will be cut (trying to cut at word boundary);
114    full description is available as 'title' attribute (usually shown on
115    mouseover).  By default set to 25, which might be too small if you
116    use long project descriptions.
117  * $projects_list_group_categories
118    Enables the grouping of projects by category on the project list page.
119    The category of a project is determined by the $GIT_DIR/category
120    file or the 'gitweb.category' variable in its repository configuration.
121    Disabled by default.
122  * $project_list_default_category
123    Default category for projects for which none is specified.  If set
124    to the empty string, such projects will remain uncategorized and
125    listed at the top, above categorized projects.
126  * @git_base_url_list
127    List of git base URLs used for URL to where fetch project from, shown
128    in project summary page.  Full URL is "$git_base_url/$project".
129    You can setup multiple base URLs (for example one for  git:// protocol
130    access, and one for http:// "dumb" protocol access).  Note that per
131    repository configuration in 'cloneurl' file, or as values of gitweb.url
132    project config.
133  * $default_blob_plain_mimetype
134    Default mimetype for blob_plain (raw) view, if mimetype checking
135    doesn't result in some other type; by default 'text/plain'.
136  * $default_text_plain_charset
137    Default charset for text files. If not set, web server configuration
138    would be used.
139  * $mimetypes_file
140    File to use for (filename extension based) guessing of MIME types before
141    trying /etc/mime.types. Path, if relative, is taken currently as
142    relative to the current git repository.
143  * $fallback_encoding
144    Gitweb assumes this charset if line contains non-UTF-8 characters.
145    Fallback decoding is used without error checking, so it can be even
146    'utf-8'. Value must be valid encoding; see Encoding::Supported(3pm) man
147    page for a list.   By default 'latin1', aka. 'iso-8859-1'.
148  * @diff_opts
149    Rename detection options for git-diff and git-diff-tree. By default
150    ('-M'); set it to ('-C') or ('-C', '-C') to also detect copies, or
151    set it to () if you don't want to have renames detection.
152  * $prevent_xss
153    If true, some gitweb features are disabled to prevent content in
154    repositories from launching cross-site scripting (XSS) attacks.  Set this
155    to true if you don't trust the content of your repositories. The default
156    is false.
157  * $maxload
158    Used to set the maximum load that we will still respond to gitweb queries.
159    If server load exceed this value then return "503 Service Unavailable" error.
160    Server load is taken to be 0 if gitweb cannot determine its value.  Set it to
161    undefined value to turn it off.  The default is 300.
162  * $highlight_bin
163    Path to the highlight executable to use (must be the one from
164    http://www.andre-simon.de due to assumptions about parameters and output).
165    Useful if highlight is not installed on your webserver's PATH.
166    [Default: highlight]
167  * $per_request_config
168    If set to code reference, it would be run once per each request.  You can
169    set parts of configuration that change per session, e.g. by setting it to
170      sub { $ENV{GL_USER} = $cgi->remote_user || "gitweb"; }
171    Otherwise it is treated as boolean value: if true gitweb would process
172    config file once per request, if false it would process config file only
173    once.  Note: $my_url, $my_uri, and $base_url are overwritten with
174    their default values before every request, so if you want to change
175    them, be sure to set this variable to true or a code reference effecting
176    the desired changes.  The default is true.
178 Projects list file format
179 ~~~~~~~~~~~~~~~~~~~~~~~~~
181 Instead of having gitweb find repositories by scanning filesystem starting
182 from $projectroot (or $projects_list, if it points to directory), you can
183 provide list of projects by setting $projects_list to a text file with list
184 of projects (and some additional info).  This file uses the following
185 format:
187 One record (for project / repository) per line, whitespace separated fields;
188 does not support (at least for now) lines continuation (newline escaping).
189 Leading and trailing whitespace are ignored, any run of whitespace can be
190 used as field separator (rules for Perl's "split(' ', $line)").  Keyed by
191 the first field, which is project name, i.e. path to repository GIT_DIR
192 relative to $projectroot.  Fields use modified URI encoding, defined in
193 RFC 3986, section 2.1 (Percent-Encoding), or rather "Query string encoding"
194 (see http://en.wikipedia.org/wiki/Query_string#URL_encoding), the difference
195 being that SP (' ') can be encoded as '+' (and therefore '+' has to be also
196 percent-encoded).  Reserved characters are: '%' (used for encoding), '+'
197 (can be used to encode SPACE), all whitespace characters as defined in Perl,
198 including SP, TAB and LF, (used to separate fields in a record).
200 Currently list of fields is
201  * <repository path>  - path to repository GIT_DIR, relative to $projectroot
202  * <repository owner> - displayed as repository owner, preferably full name,
203                         or email, or both
205 You can additionally use $projects_list file to limit which repositories
206 are visible, and together with $strict_export to limit access to
207 repositories (see "Gitweb repositories" section in gitweb/INSTALL).
210 Per-repository gitweb configuration
211 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
213 You can also configure individual repositories shown in gitweb by creating
214 file in the GIT_DIR of git repository, or by setting some repo configuration
215 variable (in GIT_DIR/config).
217 You can use the following files in repository:
218  * README.html
219    A .html file (HTML fragment) which is included on the gitweb project
220    summary page inside <div> block element. You can use it for longer
221    description of a project, to provide links (for example to project's
222    homepage), etc. This is recognized only if XSS prevention is off
223    ($prevent_xss is false); a way to include a readme safely when XSS
224    prevention is on may be worked out in the future.
225  * description (or gitweb.description)
226    Short (shortened by default to 25 characters in the projects list page)
227    single line description of a project (of a repository). Plain text file;
228    HTML will be escaped. By default set to
229      Unnamed repository; edit this file to name it for gitweb.
230    from the template during repository creation. You can use the
231    gitweb.description repo configuration variable, but the file takes
232    precedence.
233  * category (or gitweb.category)
234    Singe line category of a project, used to group projects if
235    $projects_list_group_categories is enabled. By default (file and
236    configuration variable absent), uncategorized projects are put in
237    the $project_list_default_category category. You can use the
238    gitweb.category repo configuration variable, but the file takes
239    precedence.
240  * cloneurl (or multiple-valued gitweb.url)
241    File with repository URL (used for clone and fetch), one per line.
242    Displayed in the project summary page. You can use multiple-valued
243    gitweb.url repository configuration variable for that, but the file
244    takes precedence.
245  * gitweb.owner
246    You can use the gitweb.owner repository configuration variable to set
247    repository's owner. It is displayed in the project list and summary
248    page. If it's not set, filesystem directory's owner is used
249    (via GECOS field / real name field from getpwiud(3)).
250  * various gitweb.* config variables (in config)
251    Read description of %feature hash for detailed list, and some
252    descriptions.
255 Webserver configuration
256 -----------------------
258 If you want to have one URL for both gitweb and your http://
259 repositories, you can configure apache like this:
261 <VirtualHost *:80>
262     ServerName          git.example.org
263     DocumentRoot        /pub/git
264     SetEnv                      GITWEB_CONFIG   /etc/gitweb.conf
266     # turning on mod rewrite
267     RewriteEngine on
269     # make the front page an internal rewrite to the gitweb script
270     RewriteRule ^/$  /cgi-bin/gitweb.cgi
272     # make access for "dumb clients" work
273     RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /cgi-bin/gitweb.cgi%{REQUEST_URI}  [L,PT]
274 </VirtualHost>
276 The above configuration expects your public repositories to live under
277 /pub/git and will serve them as http://git.domain.org/dir-under-pub-git,
278 both as cloneable GIT URL and as browseable gitweb interface.
279 If you then start your git-daemon with --base-path=/pub/git --export-all
280 then you can even use the git:// URL with exactly the same path.
282 Setting the environment variable GITWEB_CONFIG will tell gitweb to use
283 the named file (i.e. in this example /etc/gitweb.conf) as a
284 configuration for gitweb.  Perl variables defined in here will
285 override the defaults given at the head of the gitweb.perl (or
286 gitweb.cgi).  Look at the comments in that file for information on
287 which variables and what they mean.
289 If you use the rewrite rules from the example you'll likely also need
290 something like the following in your gitweb.conf (or gitweb_config.perl) file:
292   @stylesheets = ("/some/absolute/path/gitweb.css");
293   $my_uri = "/";
294   $home_link = "/";
297 Webserver configuration with multiple projects' root
298 ----------------------------------------------------
300 If you want to use gitweb with several project roots you can edit your apache
301 virtual host and gitweb.conf configuration files like this :
303 virtual host configuration :
305 <VirtualHost *:80>
306     ServerName                  git.example.org
307     DocumentRoot                /pub/git
308     SetEnv                              GITWEB_CONFIG   /etc/gitweb.conf
310     # turning on mod rewrite
311     RewriteEngine on
313     # make the front page an internal rewrite to the gitweb script
314     RewriteRule ^/$             /cgi-bin/gitweb.cgi [QSA,L,PT]
316     # look for a public_git folder in unix users' home
317     # http://git.example.org/~<user>/
318     RewriteRule ^/\~([^\/]+)(/|/gitweb.cgi)?$   /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/home/$1/public_git/,L,PT]
320     # http://git.example.org/+<user>/
321     #RewriteRule ^/\+([^\/]+)(/|/gitweb.cgi)?$  /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/home/$1/public_git/,L,PT]
323     # http://git.example.org/user/<user>/
324     #RewriteRule ^/user/([^\/]+)/(gitweb.cgi)?$ /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/home/$1/public_git/,L,PT]
326     # defined list of project roots
327     RewriteRule ^/scm(/|/gitweb.cgi)?$          /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/pub/scm/,L,PT]
328     RewriteRule ^/var(/|/gitweb.cgi)?$          /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/var/git/,L,PT]
330     # make access for "dumb clients" work
331     RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /cgi-bin/gitweb.cgi%{REQUEST_URI}  [L,PT]
332 </VirtualHost>
334 gitweb.conf configuration :
336 $projectroot = $ENV{'GITWEB_PROJECTROOT'} || "/pub/git";
338 These configurations enable two things. First, each unix user (<user>) of the
339 server will be able to browse through gitweb git repositories found in
340 ~/public_git/ with the following url : http://git.example.org/~<user>/
342 If you do not want this feature on your server just remove the second rewrite rule.
344 If you already use mod_userdir in your virtual host or you don't want to use
345 the '~' as first character just comment or remove the second rewrite rule and
346 uncomment one of the following according to what you want.
348 Second, repositories found in /pub/scm/ and /var/git/ will be accesible
349 through http://git.example.org/scm/ and http://git.example.org/var/.
350 You can add as many project roots as you want by adding rewrite rules like the
351 third and the fourth.
354 PATH_INFO usage
355 -----------------------
356 If you enable PATH_INFO usage in gitweb by putting
358    $feature{'pathinfo'}{'default'} = [1];
360 in your gitweb.conf, it is possible to set up your server so that it
361 consumes and produces URLs in the form
363 http://git.example.com/project.git/shortlog/sometag
365 by using a configuration such as the following, that assumes that
366 /var/www/gitweb is the DocumentRoot of your webserver, and that it
367 contains the gitweb.cgi script and complementary static files
368 (stylesheet, favicon):
370 <VirtualHost *:80>
371         ServerAlias git.example.com
373         DocumentRoot /var/www/gitweb
375         <Directory /var/www/gitweb>
376                 Options ExecCGI
377                 AddHandler cgi-script cgi
379                 DirectoryIndex gitweb.cgi
381                 RewriteEngine On
382                 RewriteCond %{REQUEST_FILENAME} !-f
383                 RewriteCond %{REQUEST_FILENAME} !-d
384                 RewriteRule ^.* /gitweb.cgi/$0 [L,PT]
385         </Directory>
386 </VirtualHost>
388 The rewrite rule guarantees that existing static files will be properly
389 served, whereas any other URL will be passed to gitweb as PATH_INFO
390 parameter.
392 Notice that in this case you don't need special settings for
393 @stylesheets, $my_uri and $home_link, but you lose "dumb client" access
394 to your project .git dirs. A possible workaround for the latter is the
395 following: in your project root dir (e.g. /pub/git) have the projects
396 named without a .git extension (e.g. /pub/git/project instead of
397 /pub/git/project.git) and configure Apache as follows:
399 <VirtualHost *:80>
400         ServerAlias git.example.com
402         DocumentRoot /var/www/gitweb
404         AliasMatch ^(/.*?)(\.git)(/.*)?$ /pub/git$1$3
405         <Directory /var/www/gitweb>
406                 Options ExecCGI
407                 AddHandler cgi-script cgi
409                 DirectoryIndex gitweb.cgi
411                 RewriteEngine On
412                 RewriteCond %{REQUEST_FILENAME} !-f
413                 RewriteCond %{REQUEST_FILENAME} !-d
414                 RewriteRule ^.* /gitweb.cgi/$0 [L,PT]
415         </Directory>
416 </VirtualHost>
418 The additional AliasMatch makes it so that
420 http://git.example.com/project.git
422 will give raw access to the project's git dir (so that the project can
423 be cloned), while
425 http://git.example.com/project
427 will provide human-friendly gitweb access.
429 This solution is not 100% bulletproof, in the sense that if some project
430 has a named ref (branch, tag) starting with 'git/', then paths such as
432 http://git.example.com/project/command/abranch..git/abranch
434 will fail with a 404 error.
438 Originally written by:
439   Kay Sievers <kay.sievers@vrfy.org>
441 Any comment/question/concern to:
442   Git mailing list <git@vger.kernel.org>