13
Gitolite

Add mailinglist command to gitolite

  • Upload
    -

  • View
    455

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Add mailinglist command to gitolite

Gitolite

Page 2: Add mailinglist command to gitolite

• gitolite的最基本原理(基于ssh的git命令):

• git clone git@host:repo.git

• 等价于

• ssh git@host 'git-upload-pack repo.git'

• git push

• 等价于

• ssh git@host 'git-receive-pack repo.git'

基础原理

Page 3: Add mailinglist command to gitolite

如何插入gitolite

• 如何“劫持”掉ssh上来的git-*命令?

• 秘密在~/.ssh/authorized_keys里:

Page 4: Add mailinglist command to gitolite

• gitolite实际效果:

• git clone git@host:repo.git

• 等价于

• ssh git@host '/home/git/bin/gitolite-shell chenlin.rao SSH_ORIGINAL_COMMAND="git-upload-pack repo.git"'

• git push

• 等价于

• ssh git@host '/home/git/bin/gitolite-shell chenlin.raoSSH_ORIGINAL_COMMAND="git-receive-pack repo.git"'

原理实现

Page 5: Add mailinglist command to gitolite

• 设置GL_USER环境变量

• 解析校验sshd设置的SSH_ORIGINAL_COMMAND环境变量匹配git-upload-pack|git-receive-pack|git-upload-archive的就是git命令匹配$rc{COMMANDS}的就是gitolite命令

• 设置GL_REPO环境变量

• 检查是否存在,不存在且允许的话就创建新repo

• 检查GL_BYPASS_ACCESS_CHECKS环境变量是否可以跳过

• 调用Gitolite::Conf::Load::access()函数检查操作权限

• 调用常规git命令 / 调用gitolite command脚本

gitolite-shell实现

Page 6: Add mailinglist command to gitolite

• 整个文件就存了一个%rc大哈希,各种配置。• GIT_CONFIG_KEYS => 'hooks.*', #允许git_config调用的key

• ROLES => {

• READERS => 1,

• WRITERS => 1,

• },

• LOCAL_CODE => "$ENV{HOME}/.gitolite", #存放hooks、logs等的位置

• ENABLE => [

• 'help',

• 'desc',

• 'info',

• 'perms',

• 'writable',

• ] # 默认可用的gitolite command列表

gitolite.rc

Page 7: Add mailinglist command to gitolite

• gitolite支持的command,脚本判断逻辑分成:– setup

– compile

– trigger

– list-phy-repos

– _which("commands/$command", 'x')

• 所以主要的特殊命令都是在~/bin/commands/下通过一个个同名脚本实现的。一共有26个——但是注意之前gitolite.rc里有开关,默认只开了5个。

• 脚本不要求是Perl,实际上也有不少是Bash写的。

gitolite command

Page 8: Add mailinglist command to gitolite

• 在创建repo的时候,Gitolite::Conf::Store::new_repo里在git init --bare之后还调用了一个hook_1()函数。这个函数干的事情:

# propagate user-defined (custom) hooks to all repos

ln_sf( "$rc{LOCAL_CODE}/hooks/common", "*", "$repo.git/hooks" ) if $rc{LOCAL_CODE};

# override/propagate gitolite defined hooks for all repos

ln_sf( "$rc{GL_ADMIN_BASE}/hooks/common", "*", "$repo.git/hooks" );

# override/propagate gitolite defined hooks for the admin repo

ln_sf( "$rc{GL_ADMIN_BASE}/hooks/gitolite-admin", "*", "$repo.git/hooks" ) if $repo eq 'gitolite-admin';

gitolite hooks

Page 9: Add mailinglist command to gitolite

• 通过trigger触发

• 必须通过gitolite-options.hooks.*设定

• 同样需要在.gitolite.rc配置中开启才能使用

repo specific hook

Page 10: Add mailinglist command to gitolite

mailinglist实现

Page 11: Add mailinglist command to gitolite

• 整个%config模仿了Gitolite::Conf::Store和Gitolite::Conf::Load

• 因为gitolite git-config命令,采用的Gitolite::Conf::Load::git_config()里会强制使用$repo.git/gl-conf文件里的%one_repo和%one_config。而最重要的access()等函数都会用到这个git_config的返回值。

mailinglist解释

Page 12: Add mailinglist command to gitolite

• 实现mailinglist命令行操作需要:1.修改.gitolite.rc文件,添加ENABLE数组里的命令,编辑

允许的GIT_CONFIG_KEYS;

2.在.gitolite/hooks/common/下创建post-receive文件,即git默认的post-receive-email

3.在bin/commands/下创建mailinglist程序

总结

Page 13: Add mailinglist command to gitolite