Commit c03bc6e2912b2e63a352e1f7e664b32a95aa9cad

Authored by Dmitriy Zaporozhets
1 parent 6a2c7d80

gitolite support in progress | requires gitolite umask 0007

Gemfile
... ... @@ -9,6 +9,7 @@ gem "kaminari"
9 9 gem "haml-rails"
10 10 gem "jquery-rails"
11 11 gem "grit", :git => "https://github.com/gitlabhq/grit.git"
  12 +gem "gitolite", :git => "https://github.com/gitlabhq/gitolite.git"
12 13 gem "carrierwave"
13 14 gem "six"
14 15 gem "therubyracer"
... ...
Gemfile.lock
... ... @@ -5,6 +5,14 @@ GIT
5 5 annotate (2.4.1.beta1)
6 6  
7 7 GIT
  8 + remote: https://github.com/gitlabhq/gitolite.git
  9 + revision: 36dabd226caa40ff052677719adaacbfe667b36c
  10 + specs:
  11 + gitolite (0.0.3.alpha)
  12 + grit (~> 2.4.1)
  13 + hashery (~> 1.4.0)
  14 +
  15 +GIT
8 16 remote: https://github.com/gitlabhq/grit.git
9 17 revision: ff015074ef35bd94cba943f9c0f98e161ab5851c
10 18 specs:
... ... @@ -101,6 +109,7 @@ GEM
101 109 activesupport (~> 3.0)
102 110 haml (~> 3.0)
103 111 railties (~> 3.0)
  112 + hashery (1.4.0)
104 113 hike (1.2.1)
105 114 i18n (0.6.0)
106 115 inifile (0.4.1)
... ... @@ -259,6 +268,7 @@ DEPENDENCIES
259 268 drapper
260 269 faker
261 270 git
  271 + gitolite!
262 272 grit!
263 273 haml-rails
264 274 inifile
... ...
config/gitlab.yml
... ... @@ -8,7 +8,7 @@ email:
8 8  
9 9 # Gitosis congiguration
10 10 gitosis:
11   - admin_uri: git@localhost:gitosis-admin.git
  11 + admin_uri: git@localhost:gitolite-admin
12 12 base_path: /home/git/repositories/
13 13 host: localhost
14 14 git_user: git
... ...
lib/gitosis.rb
  1 +require 'gitolite'
  2 +
1 3 require 'inifile'
2 4 require 'timeout'
3 5 require 'fileutils'
... ... @@ -7,15 +9,15 @@ class Gitosis
7 9  
8 10 def pull
9 11 # create tmp dir
10   - @local_dir = File.join(Dir.tmpdir,"gitlabhq-gitosis-#{Time.now.to_i}")
  12 + @local_dir = File.join(Dir.tmpdir,"gitlabhq-gitolite-#{Time.now.to_i}")
11 13  
12 14 Dir.mkdir @local_dir
13 15  
14   - `git clone #{GITOSIS['admin_uri']} #{@local_dir}/gitosis`
  16 + `git clone #{GITOSIS['admin_uri']} #{@local_dir}/gitolite`
15 17 end
16 18  
17 19 def push
18   - Dir.chdir(File.join(@local_dir, "gitosis"))
  20 + Dir.chdir(File.join(@local_dir, "gitolite"))
19 21 `git add -A`
20 22 `git commit -am "Gitlab"`
21 23 `git push`
... ... @@ -26,7 +28,7 @@ class Gitosis
26 28  
27 29 def configure
28 30 status = Timeout::timeout(20) do
29   - File.open(File.join(Dir.tmpdir,"gitlabhq-gitosis.lock"), "w+") do |f|
  31 + File.open(File.join(Dir.tmpdir,"gitlabhq-gitolite.lock"), "w+") do |f|
30 32 begin
31 33 f.flock(File::LOCK_EX)
32 34 pull
... ... @@ -37,14 +39,14 @@ class Gitosis
37 39 end
38 40 end
39 41 end
40   - rescue Exception => ex
41   - raise Gitosis::AccessDenied.new("gitosis timeout")
  42 + #rescue Exception => ex
  43 + #raise Gitosis::AccessDenied.new("gitolite timeout")
42 44 end
43 45  
44 46 def destroy_project(project)
45 47 `sudo -u git rm -rf #{project.path_to_repo}`
46 48  
47   - conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf'))
  49 + conf = IniFile.new(File.join(@local_dir,'gitolite', 'conf', 'gitolite.conf'))
48 50  
49 51 conf.delete_section("group #{project.path}")
50 52  
... ... @@ -53,22 +55,29 @@ class Gitosis
53 55  
54 56 #update or create
55 57 def update_keys(user, key)
56   - File.open(File.join(@local_dir, 'gitosis/keydir',"#{user}.pub"), 'w') {|f| f.write(key.gsub(/\n/,'')) }
  58 + File.open(File.join(@local_dir, 'gitolite/keydir',"#{user}.pub"), 'w') {|f| f.write(key.gsub(/\n/,'')) }
57 59 end
58 60  
59 61 def delete_key(user)
60   - File.unlink(File.join(@local_dir, 'gitosis/keydir',"#{user}.pub"))
61   - `cd #{File.join(@local_dir,'gitosis')} ; git rm keydir/#{user}.pub`
  62 + File.unlink(File.join(@local_dir, 'gitolite/keydir',"#{user}.pub"))
  63 + `cd #{File.join(@local_dir,'gitolite')} ; git rm keydir/#{user}.pub`
62 64 end
63 65  
64 66 #update or create
65 67 def update_project(repo_name, name_writers)
66   - # write config file
67   - conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf'))
  68 + ga_repo = Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite'))
  69 + conf = ga_repo.config
68 70  
69   - conf["group #{repo_name}"]['writable'] = repo_name
70   - conf["group #{repo_name}"]['members'] = name_writers.join(' ')
  71 + repo = if conf.has_repo?(repo_name)
  72 + conf.get_repo(repo_name)
  73 + else
  74 + Gitolite::Config::Repo.new(repo_name)
  75 + end
71 76  
72   - conf.write
  77 + repo.add_permission("RW+", "", name_writers) unless name_writers.blank?
  78 +
  79 + conf.add_repo(repo)
  80 +
  81 + ga_repo.save
73 82 end
74 83 end
... ...