Ok, so the other week I wrote a little bit about migrating my git server from gitosis (which is no longer maintained), over to gitolite.

Along side this, I also run a gitlist server. Gitlist is a web front end for git, similar to gitweb, which provides a slick and modern looking “github” style interface. It is also remarkably easy to set up and configure.

One gotcha I found was that, while unmodified gitosis repositories displayed correctly, as soon as you pushed a change, gitlist presented an error:

Oops! fatal: Failed to resolve HEAD as a valid ref.

After some investigation, it seems the problem stems from a permission issue. By default, gitolite creates new files and repositories with a slightly more restricted set of permissions.

Fixing the problem

Once the problem was identified, the solution is thankfully fairly trivial:

  1. First, stop gitolite making the situation any worse. Go to the gitolite home directory and edit .gitolite.rc, and set

    $REPO_UMASK = 0027;

    This will cause new files to be created with access to group, as well as user.

  2. Next, give your web server process access to the gitolite group. Assuming, as with me, the user is git, modify /etc/group and add your webserver user to the git group, e.g. git:x:128:www-data
  3. Restart apache for your changes to come into effect.

Fixing broken repositories

New repositories and files should now be created using the more permissive access permissions, which gitlist/gitweb will now be able to see. However, you may need to fix the permissions on some existing repositories.

find repository-name.git -type d | xargs -i{} chmod 750 {};
find repository-name.git -type f | xargs -i{} chmod 640 {}

Hope this helps!

One thought on “Running gitlist (or gitweb) with Gitolite

  1. 在亚马逊AWS上建立Git服务器

    Posted February 21, 2014

    by Joel Ma

    本文可以算是前文用亚马逊的云(AWS)免费建立wordpress blog的一个延续,在上文的基础上我们可以建立一个属于自己的git服务器。这里介绍的方法会用到gitolite和gitlist,gitolite是一个git的用户管理层,方便的管理用户和git repository,而gitlist是一个方便从网页查看git reposito的工具。本文假设你对git有基本的了解,并且基于提到的前文已经假设好了环境
    在EC2上安装配置gitolite (sudo su)
    cd /tmp
    # 准备key文件,或者使用你现有的key文件
    ssh-keygen -t rsa
    cp id_rsa.pub /tmp/your-name.pub

    # install packages 安装工具
    sudo apt-get install git gitolite git-daemon-run
    # create git user 创建git用户
    sudo adduser –system –shell /bin/bash –gecos ‘git version control’ –group –disabled-password –home /home/git git
    sudo su – git
    cd /home/git
    echo “PATH=$HOME/bin:$PATH” > .bashrc
    # gl-setup gitolite初始化
    gl-setup /tmp/your-name.pub
    # 执行上面命令后gitolite会让选择熟悉的编辑器你修改配置文件,打开配置后座如下修改
    $REPO_UMASK = 0022;
    至此gitolite安装完毕,建议
    配置你工作机上的~/.ssh/config文件
    以方便连接
    config文件如下
    Host 你喜欢的名字,如gs
    Hostname 亚马逊PUBLIC DNS
    User git
    IdentityFile C:/Users/test/.ssh/id_rsa #你的私钥路径
    #PreferredAuthentications publickey

    在工作机上管理gitolite
    这样你就可以在你的工作机上进行连接了,现在clone管理目录git clone git@gs:gitolite-admin.git
    编辑conf/gitolite.conf可以添加repository如
    repo anothertest
    RW+ = @all
    添加用户只需将的公钥添加到keydir就可以了,如果用户有多个公钥,如工作机一个,笔记本一个,可以在keydir下添加目录然后添加key如为tom添加 laptop/tom.pub和workspace/tom.pub即可
    修改完成之后commit并push回主机相应的repositoy和user了
    在EC2上配置gitlist
    用git来管理repository和user很方便,但如果你的老板要查看git上的提交就不那么方便了(:P),通过安装gitlist网页查看就会方便很多
    从gitlist.org 上下载最新版并完成配置
    cd /tmp
    wget https://s3.amazonaws.com/gitlist/gitlist-0.4.0.tar.gz
    tar -zxf gitlist-0.4.0.tar.gz
    mv gitlist /sites/
    cd /sites/gitlist
    mv config.ini-example config.ini
    edit config.ini
    repositories[] = ‘/data/git/repositories/’
    hidden[] = ‘/data/git/repositories/gitolite-admin.git’ #建议添加,管理目录不必被网页查看
    mkdir cache #必须手动添加
    chown -Rh www-data:www-data /sites/gitlist
    创建site的nginx配置/etc/nginx/sites-available/gitlist
    server {
    listen 80;
    server_name gitlist;
    keepalive_timeout 70;

    access_log /var/log/nginx/gitlist-access.log;
    error_log /var/log/nginx/gitlist-error.log;

    root /sites/gitlist;
    index index.php;
    location ~ /include {
    deny all;
    return 403;
    }

    location ~ ^/api/(tickets|tasks)(.*)$ {
    try_files $uri $uri/ /api/http.php;
    }

    location ~ ^/scp/ajax.php/(.*)$ {
    try_files $uri $uri/ /scp/ajax.php;
    }

    location / {
    index index.php;
    try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    include fastcgi_params;
    fastcgi_pass unix:/var/run/php5-admin.sock;
    #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    }
    如果你此处用的fastcgi_pass是之前用过的那不需要额外的设置,如果没有那需要建立
    cd /etc/php5/fpm/pool.d/
    cp http://www.conf gitlist.conf
    edit gitlist.conf
    name ->gitlist
    listen ->nginx config 中的
    然后重启php5-fpm 和nginx访问你的地址就可以见到gitlist页面了
    如果你在第一步设置配置是没有问题,那网页应该就可以正常显示了,如果那时设置的不对那么
    编辑 /home/git/.gitolite.rc找到$REPO_UMASK改成0022然后手动设置已有的文件权限 chmod -R 755 /home/git应该就可以了
    参考
    setup git server on ec2
    run gitweb on gitolite
    gitlist issue
    public repository in gitolite with umask
    gitweb gitolite nginx
    gitlist

    Categories: Uncategorized

    « 用亚马逊的云(AWS)免费建立wordpress blog

    Leave a Reply Cancel reply

    Your email address will not be published. Author *
    Email *
    Website

    two × = 2 You may use these HTML tags and attributes:

Leave a Reply