gitolite support in progress | requires gitolite umask 0007

This commit is contained in:
Dmitriy Zaporozhets 2011-12-04 01:08:08 +02:00
parent 6a2c7d80cb
commit c03bc6e291
4 changed files with 36 additions and 16 deletions

View file

@ -9,6 +9,7 @@ gem "kaminari"
gem "haml-rails"
gem "jquery-rails"
gem "grit", :git => "https://github.com/gitlabhq/grit.git"
gem "gitolite", :git => "https://github.com/gitlabhq/gitolite.git"
gem "carrierwave"
gem "six"
gem "therubyracer"

View file

@ -4,6 +4,14 @@ GIT
specs:
annotate (2.4.1.beta1)
GIT
remote: https://github.com/gitlabhq/gitolite.git
revision: 36dabd226caa40ff052677719adaacbfe667b36c
specs:
gitolite (0.0.3.alpha)
grit (~> 2.4.1)
hashery (~> 1.4.0)
GIT
remote: https://github.com/gitlabhq/grit.git
revision: ff015074ef35bd94cba943f9c0f98e161ab5851c
@ -101,6 +109,7 @@ GEM
activesupport (~> 3.0)
haml (~> 3.0)
railties (~> 3.0)
hashery (1.4.0)
hike (1.2.1)
i18n (0.6.0)
inifile (0.4.1)
@ -259,6 +268,7 @@ DEPENDENCIES
drapper
faker
git
gitolite!
grit!
haml-rails
inifile

View file

@ -8,7 +8,7 @@ email:
# Gitosis congiguration
gitosis:
admin_uri: git@localhost:gitosis-admin.git
admin_uri: git@localhost:gitolite-admin
base_path: /home/git/repositories/
host: localhost
git_user: git

View file

@ -1,3 +1,5 @@
require 'gitolite'
require 'inifile'
require 'timeout'
require 'fileutils'
@ -7,15 +9,15 @@ class Gitosis
def pull
# create tmp dir
@local_dir = File.join(Dir.tmpdir,"gitlabhq-gitosis-#{Time.now.to_i}")
@local_dir = File.join(Dir.tmpdir,"gitlabhq-gitolite-#{Time.now.to_i}")
Dir.mkdir @local_dir
`git clone #{GITOSIS['admin_uri']} #{@local_dir}/gitosis`
`git clone #{GITOSIS['admin_uri']} #{@local_dir}/gitolite`
end
def push
Dir.chdir(File.join(@local_dir, "gitosis"))
Dir.chdir(File.join(@local_dir, "gitolite"))
`git add -A`
`git commit -am "Gitlab"`
`git push`
@ -26,7 +28,7 @@ class Gitosis
def configure
status = Timeout::timeout(20) do
File.open(File.join(Dir.tmpdir,"gitlabhq-gitosis.lock"), "w+") do |f|
File.open(File.join(Dir.tmpdir,"gitlabhq-gitolite.lock"), "w+") do |f|
begin
f.flock(File::LOCK_EX)
pull
@ -37,14 +39,14 @@ class Gitosis
end
end
end
rescue Exception => ex
raise Gitosis::AccessDenied.new("gitosis timeout")
#rescue Exception => ex
#raise Gitosis::AccessDenied.new("gitolite timeout")
end
def destroy_project(project)
`sudo -u git rm -rf #{project.path_to_repo}`
conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf'))
conf = IniFile.new(File.join(@local_dir,'gitolite', 'conf', 'gitolite.conf'))
conf.delete_section("group #{project.path}")
@ -53,22 +55,29 @@ class Gitosis
#update or create
def update_keys(user, key)
File.open(File.join(@local_dir, 'gitosis/keydir',"#{user}.pub"), 'w') {|f| f.write(key.gsub(/\n/,'')) }
File.open(File.join(@local_dir, 'gitolite/keydir',"#{user}.pub"), 'w') {|f| f.write(key.gsub(/\n/,'')) }
end
def delete_key(user)
File.unlink(File.join(@local_dir, 'gitosis/keydir',"#{user}.pub"))
`cd #{File.join(@local_dir,'gitosis')} ; git rm keydir/#{user}.pub`
File.unlink(File.join(@local_dir, 'gitolite/keydir',"#{user}.pub"))
`cd #{File.join(@local_dir,'gitolite')} ; git rm keydir/#{user}.pub`
end
#update or create
def update_project(repo_name, name_writers)
# write config file
conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf'))
ga_repo = Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite'))
conf = ga_repo.config
conf["group #{repo_name}"]['writable'] = repo_name
conf["group #{repo_name}"]['members'] = name_writers.join(' ')
repo = if conf.has_repo?(repo_name)
conf.get_repo(repo_name)
else
Gitolite::Config::Repo.new(repo_name)
end
conf.write
repo.add_permission("RW+", "", name_writers) unless name_writers.blank?
conf.add_repo(repo)
ga_repo.save
end
end