From c03bc6e2912b2e63a352e1f7e664b32a95aa9cad Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> Date: Sun, 4 Dec 2011 01:08:08 +0200 Subject: [PATCH] gitolite support in progress | requires gitolite umask 0007 --- Gemfile | 1 + Gemfile.lock | 10 ++++++++++ config/gitlab.yml | 2 +- lib/gitosis.rb | 39 ++++++++++++++++++++++++--------------- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index df90446013..4f1f08602c 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index c975a95698..59c3b5e2a4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/config/gitlab.yml b/config/gitlab.yml index caa26ad2dc..3afd9c1111 100644 --- a/config/gitlab.yml +++ b/config/gitlab.yml @@ -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 diff --git a/lib/gitosis.rb b/lib/gitosis.rb index 92d32d8bf7..6aa32849fc 100644 --- a/lib/gitosis.rb +++ b/lib/gitosis.rb @@ -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 -- 2.30.9