SlideShare una empresa de Scribd logo
1 de 13
Descargar para leer sin conexión
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'
如何插入gitolite
• 如何“劫持”掉ssh上来的git-*命令?
• 秘密在~/.ssh/authorized_keys里:
原理实现
•
•
•
•

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.rao
SSH_ORIGINAL_COMMAND="git-receive-pack repo.git"'
gitolite-shell实现
• 设置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.rc
• 整个文件就存了一个%rc大哈希,各种配置。
•
•
•
•
•
•
•
•
•
•
•
•
•

GIT_CONFIG_KEYS
ROLES => {
READERS =>
WRITERS =>
},
LOCAL_CODE
=>
ENABLE => [
'help',
'desc',
'info',
'perms',
'writable',
]

=> 'hooks.*', #允许git_config调用的key
1,
1,
"$ENV{HOME}/.gitolite", #存放hooks、logs等的位置

# 默认可用的gitolite command列表
gitolite command
• gitolite支持的command,脚本判断逻辑分成:
–
–
–
–
–

setup
compile
trigger
list-phy-repos
_which("commands/$command", 'x')

• 所以主要的特殊命令都是在~/bin/commands/下通过一个个同名脚
本实现的。一共有26个——但是注意之前gitolite.rc里有开关,默认
只开了5个。
• 脚本不要求是Perl,实际上也有不少是Bash写的。
gitolite hooks
• 在创建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';
repo specific hook
• 通过trigger触发
• 必须通过gitolite-options.hooks.*设定
• 同样需要在.gitolite.rc配置中开启才能使
用
mailinglist实现
mailinglist解释
• 整个%config模仿了Gitolite::Conf::Store和
Gitolite::Conf::Load
• 因为gitolite git-config命令,采用的
Gitolite::Conf::Load::git_config()里会强制使用$repo.git/glconf文件里的%one_repo和%one_config。而最重要的access()
等函数都会用到这个git_config的返回值。
总结
• 实现mailinglist命令行操作需要:
1. 修改.gitolite.rc文件,添加ENABLE数组里的命令,编辑
允许的GIT_CONFIG_KEYS;
2. 在.gitolite/hooks/common/下创建post-receive文件
,即git默认的post-receive-email
3. 在bin/commands/下创建mailinglist程序
Add mailinglist command to gitolite

Más contenido relacionado

La actualidad más candente

工程師必備第一工具 - Git
工程師必備第一工具 - Git工程師必備第一工具 - Git
工程師必備第一工具 - GitAlan Tsai
 
Git introduction
Git introductionGit introduction
Git introductionmythnc
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學littlebtc
 
Git & Sourcetree 介紹
Git & Sourcetree 介紹Git & Sourcetree 介紹
Git & Sourcetree 介紹Adison wu
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshellNelson Tai
 
Git 入門與實作
Git 入門與實作Git 入門與實作
Git 入門與實作奕浦 郭
 
Mercurial簡介與教學
Mercurial簡介與教學Mercurial簡介與教學
Mercurial簡介與教學芳本 林
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略Lucien Lee
 
Android 程式設計(4)
Android 程式設計(4)Android 程式設計(4)
Android 程式設計(4)Roy Wang
 
git merge 與 rebase 的觀念與實務應用
git merge 與 rebase 的觀念與實務應用git merge 與 rebase 的觀念與實務應用
git merge 與 rebase 的觀念與實務應用Will Huang
 
Git基礎介紹
Git基礎介紹Git基礎介紹
Git基礎介紹Max Ma
 
Git與source tree 基礎教學
Git與source tree 基礎教學Git與source tree 基礎教學
Git與source tree 基礎教學Duncan Chen
 
Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Wen-Tien Chang
 
First meetingwithgit
First meetingwithgitFirst meetingwithgit
First meetingwithgitRhythm Sun
 
Yet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upYet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upWen-Tien Chang
 
Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹PingLun Liao
 
Git & git hub v1.2
Git & git hub v1.2Git & git hub v1.2
Git & git hub v1.2Chris Chen
 

La actualidad más candente (20)

工程師必備第一工具 - Git
工程師必備第一工具 - Git工程師必備第一工具 - Git
工程師必備第一工具 - Git
 
Git introduction
Git introductionGit introduction
Git introduction
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學
 
Git & Sourcetree 介紹
Git & Sourcetree 介紹Git & Sourcetree 介紹
Git & Sourcetree 介紹
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
 
Git
GitGit
Git
 
Git 入門與實作
Git 入門與實作Git 入門與實作
Git 入門與實作
 
Mercurial簡介與教學
Mercurial簡介與教學Mercurial簡介與教學
Mercurial簡介與教學
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略
 
Android 程式設計(4)
Android 程式設計(4)Android 程式設計(4)
Android 程式設計(4)
 
git merge 與 rebase 的觀念與實務應用
git merge 與 rebase 的觀念與實務應用git merge 與 rebase 的觀念與實務應用
git merge 與 rebase 的觀念與實務應用
 
Git基礎介紹
Git基礎介紹Git基礎介紹
Git基礎介紹
 
Git Tutorial 教學
Git Tutorial 教學Git Tutorial 教學
Git Tutorial 教學
 
Git基础培训
Git基础培训Git基础培训
Git基础培训
 
Git與source tree 基礎教學
Git與source tree 基礎教學Git與source tree 基礎教學
Git與source tree 基礎教學
 
Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀
 
First meetingwithgit
First meetingwithgitFirst meetingwithgit
First meetingwithgit
 
Yet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upYet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom up
 
Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹
 
Git & git hub v1.2
Git & git hub v1.2Git & git hub v1.2
Git & git hub v1.2
 

Destacado

Skyline 简介
Skyline 简介Skyline 简介
Skyline 简介琛琳 饶
 
DNS协议与应用简介
DNS协议与应用简介DNS协议与应用简介
DNS协议与应用简介琛琳 饶
 
Logstash family introduction
Logstash family introductionLogstash family introduction
Logstash family introductionOwen Wu
 
Perl调用微博API实现自动查询应答
Perl调用微博API实现自动查询应答Perl调用微博API实现自动查询应答
Perl调用微博API实现自动查询应答琛琳 饶
 
Monitor is all for ops
Monitor is all for opsMonitor is all for ops
Monitor is all for ops琛琳 饶
 
{{more}} Kibana4
{{more}} Kibana4{{more}} Kibana4
{{more}} Kibana4琛琳 饶
 
ELK stack at weibo.com
ELK stack at weibo.comELK stack at weibo.com
ELK stack at weibo.com琛琳 饶
 
How ElasticSearch lives in my DevOps life
How ElasticSearch lives in my DevOps lifeHow ElasticSearch lives in my DevOps life
How ElasticSearch lives in my DevOps life琛琳 饶
 

Destacado (10)

Skyline 简介
Skyline 简介Skyline 简介
Skyline 简介
 
DNS协议与应用简介
DNS协议与应用简介DNS协议与应用简介
DNS协议与应用简介
 
Logstash family introduction
Logstash family introductionLogstash family introduction
Logstash family introduction
 
Perl调用微博API实现自动查询应答
Perl调用微博API实现自动查询应答Perl调用微博API实现自动查询应答
Perl调用微博API实现自动查询应答
 
Monitor is all for ops
Monitor is all for opsMonitor is all for ops
Monitor is all for ops
 
{{more}} Kibana4
{{more}} Kibana4{{more}} Kibana4
{{more}} Kibana4
 
ELK stack at weibo.com
ELK stack at weibo.comELK stack at weibo.com
ELK stack at weibo.com
 
How ElasticSearch lives in my DevOps life
How ElasticSearch lives in my DevOps lifeHow ElasticSearch lives in my DevOps life
How ElasticSearch lives in my DevOps life
 
More kibana
More kibanaMore kibana
More kibana
 
Logstash
LogstashLogstash
Logstash
 

Similar a Add mailinglist command to gitolite

Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)flylon
 
Git使用进阶
Git使用进阶Git使用进阶
Git使用进阶Han Qin
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to gitBo-Yi Wu
 
COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報Bachue Zhou
 
20170510 git 懶人包
20170510 git 懶人包20170510 git 懶人包
20170510 git 懶人包Chen-Ming Yang
 
為自己學 Git
為自己學 Git為自己學 Git
為自己學 Git昀 李
 
Git原理与实战 201607
Git原理与实战 201607Git原理与实战 201607
Git原理与实战 201607Charles Tang
 
Git 入门实战
Git 入门实战Git 入门实战
Git 入门实战icy leaf
 
Github简介及实用入门
Github简介及实用入门Github简介及实用入门
Github简介及实用入门Rongxing Liu
 
Git初步入門
Git初步入門Git初步入門
Git初步入門recast203
 
Code review on github training ( beginner )
Code review on github training ( beginner )Code review on github training ( beginner )
Code review on github training ( beginner )JS Lee
 
Git Flow 管理
Git Flow 管理Git Flow 管理
Git Flow 管理Pu Lee
 
Git server account management
Git server account managementGit server account management
Git server account managementPingLun Liao
 
Git & git flow
Git & git flowGit & git flow
Git & git flowAmo Wu
 
Git and git hub
Git and git hubGit and git hub
Git and git hub唯 李
 
容器與 Gitlab CI 應用
容器與 Gitlab CI 應用容器與 Gitlab CI 應用
容器與 Gitlab CI 應用Philip Zheng
 
Learning to Use Git | WeiYuan
Learning to Use Git | WeiYuanLearning to Use Git | WeiYuan
Learning to Use Git | WeiYuanWei-Yuan Chang
 

Similar a Add mailinglist command to gitolite (20)

Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)
 
Git使用进阶
Git使用进阶Git使用进阶
Git使用进阶
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報
 
20170510 git 懶人包
20170510 git 懶人包20170510 git 懶人包
20170510 git 懶人包
 
為自己學 Git
為自己學 Git為自己學 Git
為自己學 Git
 
Git原理与实战 201607
Git原理与实战 201607Git原理与实战 201607
Git原理与实战 201607
 
Git 入门实战
Git 入门实战Git 入门实战
Git 入门实战
 
Github简介及实用入门
Github简介及实用入门Github简介及实用入门
Github简介及实用入门
 
Git教學
Git教學Git教學
Git教學
 
Git初步入門
Git初步入門Git初步入門
Git初步入門
 
Code review on github training ( beginner )
Code review on github training ( beginner )Code review on github training ( beginner )
Code review on github training ( beginner )
 
Git Flow 管理
Git Flow 管理Git Flow 管理
Git Flow 管理
 
Git server account management
Git server account managementGit server account management
Git server account management
 
Git 教學
Git 教學Git 教學
Git 教學
 
Git & git flow
Git & git flowGit & git flow
Git & git flow
 
Git and git hub
Git and git hubGit and git hub
Git and git hub
 
Git Tutorial
Git TutorialGit Tutorial
Git Tutorial
 
容器與 Gitlab CI 應用
容器與 Gitlab CI 應用容器與 Gitlab CI 應用
容器與 Gitlab CI 應用
 
Learning to Use Git | WeiYuan
Learning to Use Git | WeiYuanLearning to Use Git | WeiYuan
Learning to Use Git | WeiYuan
 

Add mailinglist command to gitolite