Make VirtualMin git Module SMART

gitinstallation

I used VirtualMin's git module to setup a private git over http on one of my servers.
I have other servers with git over ssh but this was my first try to setup it over http and with VirtualMin.

Unfortunately, in last few hours I find out that the default VirtualMin's module don't use smart http mode and relay on DAV for pushing commits to the server. Which I don't really like.

Also I tried to move my old repos to this server and I cant use them because there is no /info/ref file. (I also heard that using smart http mode I don't need this file)

In result, I tried to find a document about installing smart git http and found a lot. But I dont think any of them is compatible with VirtualMin or its default git module,

Do any of you people know how I need to customize my git's installation and Apache settings to use smart http protocol with little hurt to VirtualMin and also still be VirtualMin compatible?

I really don't want that my settings and configurations to remove after a VirtualMin update or setting's recreation process that this control panels usually do.

Please share your thoughts on this matter with me. Thanks

OS: CentOs 6.5 x64

Best Answer

Taken from Setting up Smart HTTP for Git on Virtualmin.


From here the solution was to switch from ordinary HTTP to Smart HTTP using the git-http-backend executable, which could execute all the hooks and it supposedly much faster too.

  1. Copy the git-httpd-backend executable to the /home/domain/cgi-bin/directory and set the permissions to domain:domain. This is to avoid suexec problems.

    $ cp /usr/libexec/git-core/git-http-backend /home/domain/cgi-bin
    $ chown domain:domain /home/domain/cgi-bin/git-http-backend
    
  2. On /etc/httpd/conf/httpd.conf, add this to the VirtualHost for the domain:

    [...]
    ServerName domain.com
    
    [...]
    
    # Set the root directory where git repositories reside
    SetEnv GIT_PROJECT_ROOT /home/domain/public_html/git
    
    # By default, the git-http-backend allows push for authenticated
    # users and this directive tells the backend when a user is authenticated.
    SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER
    
    # Export all repositories
    SetEnv GIT_HTTP_EXPORT_ALL
    
    ScriptAlias /dev/ /home/domain/cgi-bin/git-http-backend/
    
    [...]
    
    # Add this if it’s not already there
    
    DAV on
    AuthType Basic
    AuthName domain.com
    AuthUserFile /home/domain/etc/git.basic.passwd
    Require valid-user
    Satisfy All
    
    RedirectMatch ^/git(/+)$ /git/gitweb.cgi
    RewriteEngine off
    AddHandler cgi-script .cgi
    
    [...]
    
  3. And then restart apache. Now all the repos are now available at http://gituser@domain.com/dev/git/*, e.g., http://gituser@domain.com/dev/git/reponame.git, and all the hooks will execute as expected.

Going forward, when you create a new repo via Virtualmin, you need to do these manual steps:

  1. Create an empty file /home/domain/public_html/git/reponame.git/git-daemon-export-ok.

  2. Create this as /home/domain/public_html/git/reponame.git/hooks/post-receive and make it executable by all, and owned by apache:domain:

    #!/bin/sh
    #
    # An example hook script for the "post-receive" event.
    #
    # The "post-receive" script is run after receive-pack has accepted a pack
    # and the repository has been updated. It is passed arguments in through
    # stdin in the form
    #
    # For example:
    # aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
    #
    # see contrib/hooks/ for a sample, or uncomment the next line and
    # rename the file to "post-receive".
    
    # Echo to the client that you’re sending the mail now
    echo "Sending notification email..."
    . /usr/share/git-core/contrib/hooks/post-receive-email
    
    # Make sure to update the git repo info on the server for pulls by other clients
    git update-server-info
    echo "Updated server info."
    
  3. As per this link, set the permissions of the git directory as follows so as to avoid a write-permissions problem when pushing new files in commits (while making sure the gitweb.cgi script is only writable by the owner to avoid suexec errors that would appear in /etc/httpd/logs/suexec.log):

    $ cd /home/domain/public_html/git/
    $ chmod -R g+ws *
    $ chgrp -R domain *
    $ chmod -R g-w gitweb.cgi
    $ chmod -R g-s gitweb.cgi
    
  4. Update /home/domain/public_html/git/reponame.git/config to match the following:

    [core]
        repositoryformatversion = 0
        filemode = true
        bare = true
    [hooks]
       mailinglist = email1@domain.com, email2@domain.com
       envelopesender = git-commits@domain.com
       emailprefix = "[REPONAME] "