Skip to content

Commit 2f4038a

Browse files
spearcegitster
authored andcommitted
Git-aware CGI to provide dumb HTTP transport
The git-http-backend CGI can be configured into any Apache server using ScriptAlias, such as with the following configuration: LoadModule cgi_module /usr/libexec/apache2/mod_cgi.so LoadModule alias_module /usr/libexec/apache2/mod_alias.so ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/ Repositories are accessed via the translated PATH_INFO. The CGI is backwards compatible with the dumb client, allowing all older HTTP clients to continue to download repositories which are managed by the CGI. Signed-off-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d8f67d2 commit 2f4038a

File tree

4 files changed

+396
-0
lines changed

4 files changed

+396
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ git-get-tar-commit-id
5555
git-grep
5656
git-hash-object
5757
git-help
58+
git-http-backend
5859
git-http-fetch
5960
git-http-push
6061
git-imap-send

Documentation/git-http-backend.txt

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
git-http-backend(1)
2+
===================
3+
4+
NAME
5+
----
6+
git-http-backend - Server side implementation of Git over HTTP
7+
8+
SYNOPSIS
9+
--------
10+
[verse]
11+
'git-http-backend'
12+
13+
DESCRIPTION
14+
-----------
15+
A simple CGI program to serve the contents of a Git repository to Git
16+
clients accessing the repository over http:// and https:// protocols.
17+
18+
By default, only the `upload-pack` service is enabled, which serves
19+
'git-fetch-pack' and 'git-ls-remote' clients, which are invoked from
20+
'git-fetch', 'git-pull', and 'git-clone'.
21+
22+
This is ideally suited for read-only updates, i.e., pulling from
23+
git repositories.
24+
25+
URL TRANSLATION
26+
---------------
27+
'git-http-backend' relies on the invoking web server to perform
28+
URL to path translation, and store the repository path into the
29+
PATH_TRANSLATED environment variable. Most web servers will do
30+
this translation automatically, resolving the suffix after the
31+
CGI name relative to the server's document root.
32+
33+
EXAMPLES
34+
--------
35+
36+
Apache 2.x::
37+
To serve all Git repositories contained within the '/git/'
38+
subdirectory of the DocumentRoot, ensure mod_cgi and
39+
mod_alias are enabled, and create a ScriptAlias to the CGI:
40+
+
41+
----------------------------------------------------------------
42+
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/git/
43+
44+
<Directory /usr/libexec/git-core>
45+
Options None
46+
</Directory>
47+
<Files /usr/libexec/git-core/git-http-backend>
48+
Options ExecCGI
49+
</Files>
50+
----------------------------------------------------------------
51+
+
52+
To require authentication for reads, use a Directory
53+
directive around the repository, or one of its parent directories:
54+
+
55+
----------------------------------------------------------------
56+
<Directory /var/www/git/private>
57+
AuthType Basic
58+
AuthName "Private Git Access"
59+
Require group committers
60+
...
61+
</Directory>
62+
----------------------------------------------------------------
63+
64+
Accelerated static Apache 2.x::
65+
Similar to the above, but Apache can be used to return static
66+
files that are stored on disk. On many systems this may
67+
be more efficient as Apache can ask the kernel to copy the
68+
file contents from the file system directly to the network:
69+
+
70+
----------------------------------------------------------------
71+
DocumentRoot /var/www
72+
73+
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/git/
74+
Alias /git_static/ /var/www/git/
75+
76+
RewriteEngine on
77+
RewriteRule ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /git_static/$1 [PT]
78+
RewriteRule ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.pack)$ /git_static/$1 [PT]
79+
RewriteRule ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.idx)$ /git_static/$1 [PT]
80+
----------------------------------------------------------------
81+
82+
83+
ENVIRONMENT
84+
-----------
85+
'git-http-backend' relies upon the CGI environment variables set
86+
by the invoking web server, including:
87+
88+
* PATH_TRANSLATED
89+
* REMOTE_USER
90+
* REMOTE_ADDR
91+
* CONTENT_TYPE
92+
* QUERY_STRING
93+
* REQUEST_METHOD
94+
95+
Author
96+
------
97+
Written by Shawn O. Pearce <[email protected]>.
98+
99+
Documentation
100+
--------------
101+
Documentation by Shawn O. Pearce <[email protected]>.
102+
103+
GIT
104+
---
105+
Part of the linkgit:git[1] suite

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ PROGRAMS += git-show-index$X
365365
PROGRAMS += git-unpack-file$X
366366
PROGRAMS += git-upload-pack$X
367367
PROGRAMS += git-var$X
368+
PROGRAMS += git-http-backend$X
368369

369370
# List built-in command $C whose implementation cmd_$C() is not in
370371
# builtin-$C.o but is linked in as part of some other command.

0 commit comments

Comments
 (0)