I'm trying to configure my own git repository server with Git SmartHTTP and Apache2. So followed these instuctions from the official git manual. But during the configuration it becomes not clear to me, what the GIT_PROJECT_ROOT variable exactly configures: Does it set the path to exactly one repository on a webserver or can you set it's value to a folder path which contains all your repositories.
And what other things does this variable affects?
The problem is that there is no description or explanation in the official git manual neither in the SmartHTTP chapter nor in the environment variables chapter.
1 Answer
There is a description in the git-http-backend manual.
Variable GIT_PROJECT_ROOT is set to a parent path of all repositories and similar to the Apache DocumentRoot directive, it is used to translate an URL-path to the filesystem:
URL TRANSLATION
To determine the location of the repository on disk, git http-backend concatenates the environment variables
PATH_INFO, which is set automatically by the web server, andGIT_PROJECT_ROOT, which must be set manually in the web server configuration. IfGIT_PROJECT_ROOTis not set, git http-backend readsPATH_TRANSLATED, which is also set automatically by the web server.EXAMPLES
All of the following examples map
http://$hostname/git/foo/bar.gitto/var/www/git/foo/bar.git.Apache 2.x
Ensure mod_cgi, mod_alias, and mod_env are enabled, set
GIT_PROJECT_ROOT(or DocumentRoot) appropriately, and create a ScriptAlias to the CGI:SetEnv GIT_PROJECT_ROOT /var/www/git SetEnv GIT_HTTP_EXPORT_ALL ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
So the /git/ part in http://hostname/git/foo/bar.git is mapped to the git-http-backend CGI script and the remaining part foo/bar.git is appended to the path of the GIT_PROJECT_ROOT (or DocumentRoot) variable which should match a Git repo.
-
So if I get it right, an incoming request to the webserver just reaches the
http://hostname/gitpart of the url and thefoo/bar.gitpart (which resides inside thePATH_INFOvariable) is combined with theGIT_PROJECT_ROOTto access the repository itself. And secondly, is this the reason why the webserver returns a 404 error if you're trying to access thehttp://hostname/git/folder in your webbrowser?Daniel– Daniel2019-11-04 14:34:41 +00:00Commented Nov 4, 2019 at 14:34 -
(1) Yes and (2) I would guess that depends on your Apache configuration, i.e. if it finds an index.html, index.php or whatever (see DirectoryIndex) or if directory listings are allowed (Options Indexes). Look into your Apache error.log if there is more information.Freddy– Freddy2019-11-04 18:41:10 +00:00Commented Nov 4, 2019 at 18:41
-
The problem occured because of my Apache2 configuration: The
ScriptAliassetting had the same url path (/repos/git) as the repositories on the local filesystem (DocumentRoot /repos/git). So if you callhttp://hostname/gitthe webserver passed the request always to the CGI script instead of serving the files to the webbrowser. SettingScriptRootto a fictive path (/git/) and let the repos reside in/repos/gitsolved it.Daniel– Daniel2019-11-04 19:48:11 +00:00Commented Nov 4, 2019 at 19:48