Enable Smart HTTP on GIT repos

The Virtualmin GIT plugin implements the outdated "dumb HTTP (web-dav)" method for git push functionality rather than the much improved Smart HTTP Transport.

The advantages of the Smart HTTP transport are numerous. To name a few, git hooks are executed when doing a push via Smart HTTP but not when using dumb http. The speed of git transactions (push/pull) are significantly improved.

Implementing Smart HTTP is straight forward. The changes required are as follows:

Create ~cgi-bin/wrapper.cgi in order to pass environment variables to git-http-backend

#!/bin/sh

export GIT_PROJECT_ROOT=/home/sandbox/public_html/git
export GIT_HTTP_EXPORT_ALL=1
export REMOTE_USER=$REDIRECT_REMOTE_USER

exec /usr/libexec/git-core/git-http-backend

Add the following directives to the virtual-host config. Note, the "ScriptAliasMatch" allows gitweb and git-http-backend to be served from the same url /git

ScriptAliasMatch \
        "(?x)^/git/(.*/(HEAD | \
                        info/refs | \
                        objects/(info/[^/]+ | \
                                 [0-9a-f]{2}/[0-9a-f]{38} | \
                                 pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
                        git-(upload|receive)-pack))$" \
        /home/sandbox/cgi-bin/wrapper.cgi/$1


<Files "git-http-backend">
    AuthType Basic
    AuthName "Git Access"
    AuthUserFile /home/sandbox/etc/git.basic.passwd
    Require expr !(%{QUERY_STRING} -strmatch '*service=git-receive-pack*' || %{REQUEST_URI} =~ m#/git-receive-pack$#)
    Require valid-user
</Files>

The current method of initializing repositories needs to include this git command git config http.receivepack true to enable users to push.

I've implemented this setup on a Virtualmin virtual-host and it works as expected.

Additional documentation on implementing Smart HTTP functionality can be found here.

Status: 
Needs work

Comments

You'll also need to set the repo as shared in addition to above git config http.receivepack true

git config core.sharedRepository group

Thanks, I didn't know about this - I'll look into implementing the change you suggested.

You'll need to change the < files > directive to include the name of the wrapper script. I mistakenly included the wrong file name. The correct name would be wrapper.cgi

Thanks

Hi, is there any progress on this, was reported in january 2018, now september 2020 still listed as open....

No we haven't worked on this yet, sorry.

Hi! I did all the steps (including comments after post) and I have error 500 :(