Commit c03bc6e2912b2e63a352e1f7e664b32a95aa9cad

Authored by Dmitriy Zaporozhets
1 parent 6a2c7d80

gitolite support in progress | requires gitolite umask 0007

@@ -9,6 +9,7 @@ gem "kaminari" @@ -9,6 +9,7 @@ gem "kaminari"
9 gem "haml-rails" 9 gem "haml-rails"
10 gem "jquery-rails" 10 gem "jquery-rails"
11 gem "grit", :git => "https://github.com/gitlabhq/grit.git" 11 gem "grit", :git => "https://github.com/gitlabhq/grit.git"
  12 +gem "gitolite", :git => "https://github.com/gitlabhq/gitolite.git"
12 gem "carrierwave" 13 gem "carrierwave"
13 gem "six" 14 gem "six"
14 gem "therubyracer" 15 gem "therubyracer"
@@ -5,6 +5,14 @@ GIT @@ -5,6 +5,14 @@ GIT
5 annotate (2.4.1.beta1) 5 annotate (2.4.1.beta1)
6 6
7 GIT 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 remote: https://github.com/gitlabhq/grit.git 16 remote: https://github.com/gitlabhq/grit.git
9 revision: ff015074ef35bd94cba943f9c0f98e161ab5851c 17 revision: ff015074ef35bd94cba943f9c0f98e161ab5851c
10 specs: 18 specs:
@@ -101,6 +109,7 @@ GEM @@ -101,6 +109,7 @@ GEM
101 activesupport (~> 3.0) 109 activesupport (~> 3.0)
102 haml (~> 3.0) 110 haml (~> 3.0)
103 railties (~> 3.0) 111 railties (~> 3.0)
  112 + hashery (1.4.0)
104 hike (1.2.1) 113 hike (1.2.1)
105 i18n (0.6.0) 114 i18n (0.6.0)
106 inifile (0.4.1) 115 inifile (0.4.1)
@@ -259,6 +268,7 @@ DEPENDENCIES @@ -259,6 +268,7 @@ DEPENDENCIES
259 drapper 268 drapper
260 faker 269 faker
261 git 270 git
  271 + gitolite!
262 grit! 272 grit!
263 haml-rails 273 haml-rails
264 inifile 274 inifile
config/gitlab.yml
@@ -8,7 +8,7 @@ email: @@ -8,7 +8,7 @@ email:
8 8
9 # Gitosis congiguration 9 # Gitosis congiguration
10 gitosis: 10 gitosis:
11 - admin_uri: git@localhost:gitosis-admin.git 11 + admin_uri: git@localhost:gitolite-admin
12 base_path: /home/git/repositories/ 12 base_path: /home/git/repositories/
13 host: localhost 13 host: localhost
14 git_user: git 14 git_user: git
lib/gitosis.rb
  1 +require 'gitolite'
  2 +
1 require 'inifile' 3 require 'inifile'
2 require 'timeout' 4 require 'timeout'
3 require 'fileutils' 5 require 'fileutils'
@@ -7,15 +9,15 @@ class Gitosis @@ -7,15 +9,15 @@ class Gitosis
7 9
8 def pull 10 def pull
9 # create tmp dir 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 Dir.mkdir @local_dir 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 end 17 end
16 18
17 def push 19 def push
18 - Dir.chdir(File.join(@local_dir, "gitosis")) 20 + Dir.chdir(File.join(@local_dir, "gitolite"))
19 `git add -A` 21 `git add -A`
20 `git commit -am "Gitlab"` 22 `git commit -am "Gitlab"`
21 `git push` 23 `git push`
@@ -26,7 +28,7 @@ class Gitosis @@ -26,7 +28,7 @@ class Gitosis
26 28
27 def configure 29 def configure
28 status = Timeout::timeout(20) do 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 begin 32 begin
31 f.flock(File::LOCK_EX) 33 f.flock(File::LOCK_EX)
32 pull 34 pull
@@ -37,14 +39,14 @@ class Gitosis @@ -37,14 +39,14 @@ class Gitosis
37 end 39 end
38 end 40 end
39 end 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 end 44 end
43 45
44 def destroy_project(project) 46 def destroy_project(project)
45 `sudo -u git rm -rf #{project.path_to_repo}` 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 conf.delete_section("group #{project.path}") 51 conf.delete_section("group #{project.path}")
50 52
@@ -53,22 +55,29 @@ class Gitosis @@ -53,22 +55,29 @@ class Gitosis
53 55
54 #update or create 56 #update or create
55 def update_keys(user, key) 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 end 59 end
58 60
59 def delete_key(user) 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 end 64 end
63 65
64 #update or create 66 #update or create
65 def update_project(repo_name, name_writers) 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 end 82 end
74 end 83 end