Commit bdc658095c6bc7e7a2a49447b404156f3f947fe1
1 parent
8134fe0e
Exists in
master
and in
4 other branches
refcatoring. cleaning after gitosis
Showing
13 changed files
with
58 additions
and
124 deletions
Show diff stats
app/controllers/application_controller.rb
@@ -3,8 +3,8 @@ class ApplicationController < ActionController::Base | @@ -3,8 +3,8 @@ class ApplicationController < ActionController::Base | ||
3 | protect_from_forgery | 3 | protect_from_forgery |
4 | helper_method :abilities, :can? | 4 | helper_method :abilities, :can? |
5 | 5 | ||
6 | - rescue_from Gitlabhq::Gitosis::AccessDenied, Gitlabhq::Gitolite::AccessDenied do |exception| | ||
7 | - render :file => File.join(Rails.root, "public", "gitosis_error"), :layout => false | 6 | + rescue_from Gitlabhq::Gitolite::AccessDenied do |exception| |
7 | + render :file => File.join(Rails.root, "public", "githost_error"), :layout => false | ||
8 | end | 8 | end |
9 | 9 | ||
10 | layout :layout_by_resource | 10 | layout :layout_by_resource |
app/controllers/errors_controller.rb
1 | class ErrorsController < ApplicationController | 1 | class ErrorsController < ApplicationController |
2 | - def gitosis | ||
3 | - render :file => File.join(Rails.root, "public", "gitosis_error"), :layout => false | 2 | + def githost |
3 | + render :file => File.join(Rails.root, "public", "githost_error"), :layout => false | ||
4 | end | 4 | end |
5 | end | 5 | end |
app/controllers/projects_controller.rb
@@ -42,8 +42,8 @@ class ProjectsController < ApplicationController | @@ -42,8 +42,8 @@ class ProjectsController < ApplicationController | ||
42 | format.js | 42 | format.js |
43 | end | 43 | end |
44 | end | 44 | end |
45 | - rescue Gitlabhq::Gitosis::AccessDenied, Gitlabhq::Gitolite::AccessDenied | ||
46 | - render :js => "location.href = '#{errors_gitosis_path}'" and return | 45 | + rescue Gitlabhq::Gitolite::AccessDenied |
46 | + render :js => "location.href = '#{errors_githost_path}'" and return | ||
47 | rescue StandardError => ex | 47 | rescue StandardError => ex |
48 | @project.errors.add(:base, "Cant save project. Please try again later") | 48 | @project.errors.add(:base, "Cant save project. Please try again later") |
49 | respond_to do |format| | 49 | respond_to do |format| |
app/models/key.rb
@@ -11,29 +11,29 @@ class Key < ActiveRecord::Base | @@ -11,29 +11,29 @@ class Key < ActiveRecord::Base | ||
11 | :length => { :within => 0..5000 } | 11 | :length => { :within => 0..5000 } |
12 | 12 | ||
13 | before_save :set_identifier | 13 | before_save :set_identifier |
14 | - after_save :update_gitosis | ||
15 | - after_destroy :gitosis_delete_key | 14 | + after_save :update_repository |
15 | + after_destroy :repository_delete_key | ||
16 | 16 | ||
17 | def set_identifier | 17 | def set_identifier |
18 | self.identifier = "#{user.identifier}_#{Time.now.to_i}" | 18 | self.identifier = "#{user.identifier}_#{Time.now.to_i}" |
19 | end | 19 | end |
20 | 20 | ||
21 | - def update_gitosis | 21 | + def update_repository |
22 | Gitlabhq::GitHost.system.new.configure do |c| | 22 | Gitlabhq::GitHost.system.new.configure do |c| |
23 | c.update_keys(identifier, key) | 23 | c.update_keys(identifier, key) |
24 | 24 | ||
25 | projects.each do |project| | 25 | projects.each do |project| |
26 | - c.update_project(project.path, project.gitosis_writers) | 26 | + c.update_project(project.path, project.repository_writers) |
27 | end | 27 | end |
28 | end | 28 | end |
29 | end | 29 | end |
30 | 30 | ||
31 | - def gitosis_delete_key | 31 | + def repository_delete_key |
32 | Gitlabhq::GitHost.system.new.configure do |c| | 32 | Gitlabhq::GitHost.system.new.configure do |c| |
33 | c.delete_key(identifier) | 33 | c.delete_key(identifier) |
34 | 34 | ||
35 | projects.each do |project| | 35 | projects.each do |project| |
36 | - c.update_project(project.path, project.gitosis_writers) | 36 | + c.update_project(project.path, project.repository_writers) |
37 | end | 37 | end |
38 | end | 38 | end |
39 | end | 39 | end |
app/models/project.rb
@@ -40,8 +40,8 @@ class Project < ActiveRecord::Base | @@ -40,8 +40,8 @@ class Project < ActiveRecord::Base | ||
40 | validate :check_limit | 40 | validate :check_limit |
41 | validate :repo_name | 41 | validate :repo_name |
42 | 42 | ||
43 | - after_destroy :destroy_gitosis_project | ||
44 | - after_save :update_gitosis_project | 43 | + after_destroy :destroy_repository |
44 | + after_save :update_repository | ||
45 | 45 | ||
46 | attr_protected :private_flag, :owner_id | 46 | attr_protected :private_flag, :owner_id |
47 | 47 | ||
@@ -54,8 +54,8 @@ class Project < ActiveRecord::Base | @@ -54,8 +54,8 @@ class Project < ActiveRecord::Base | ||
54 | delegate :repo, | 54 | delegate :repo, |
55 | :url_to_repo, | 55 | :url_to_repo, |
56 | :path_to_repo, | 56 | :path_to_repo, |
57 | - :update_gitosis_project, | ||
58 | - :destroy_gitosis_project, | 57 | + :update_repository, |
58 | + :destroy_repository, | ||
59 | :tags, | 59 | :tags, |
60 | :repo_exists?, | 60 | :repo_exists?, |
61 | :commit, | 61 | :commit, |
@@ -113,7 +113,7 @@ class Project < ActiveRecord::Base | @@ -113,7 +113,7 @@ class Project < ActiveRecord::Base | ||
113 | @writers ||= users_projects.includes(:user).where(:write => true).map(&:user) | 113 | @writers ||= users_projects.includes(:user).where(:write => true).map(&:user) |
114 | end | 114 | end |
115 | 115 | ||
116 | - def gitosis_writers | 116 | + def repository_writers |
117 | keys = Key.joins({:user => :users_projects}).where("users_projects.project_id = ? AND users_projects.write = ?", id, true) | 117 | keys = Key.joins({:user => :users_projects}).where("users_projects.project_id = ? AND users_projects.write = ?", id, true) |
118 | keys.map(&:identifier) | 118 | keys.map(&:identifier) |
119 | end | 119 | end |
@@ -184,8 +184,8 @@ class Project < ActiveRecord::Base | @@ -184,8 +184,8 @@ class Project < ActiveRecord::Base | ||
184 | end | 184 | end |
185 | 185 | ||
186 | def repo_name | 186 | def repo_name |
187 | - if path == "gitosis-admin" && path == "gitolite-admin" | ||
188 | - errors.add(:path, " like 'gitosis-admin' is not allowed") | 187 | + if path == "gitolite-admin" |
188 | + errors.add(:path, " like 'gitolite-admin' is not allowed") | ||
189 | end | 189 | end |
190 | end | 190 | end |
191 | 191 |
app/models/repository.rb
@@ -24,24 +24,20 @@ class Repository | @@ -24,24 +24,20 @@ class Repository | ||
24 | end | 24 | end |
25 | 25 | ||
26 | def url_to_repo | 26 | def url_to_repo |
27 | - if !GIT_HOST["port"] or GIT_HOST["port"] == 22 | ||
28 | - "#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{path}.git" | ||
29 | - else | ||
30 | - "ssh://#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{GIT_HOST["port"]}/#{path}.git" | ||
31 | - end | 27 | + Gitlabhq::GitHost.url_to_repo(path) |
32 | end | 28 | end |
33 | 29 | ||
34 | def path_to_repo | 30 | def path_to_repo |
35 | GIT_HOST["base_path"] + path + ".git" | 31 | GIT_HOST["base_path"] + path + ".git" |
36 | end | 32 | end |
37 | 33 | ||
38 | - def update_gitosis_project | 34 | + def update_repository |
39 | Gitlabhq::GitHost.system.new.configure do |c| | 35 | Gitlabhq::GitHost.system.new.configure do |c| |
40 | - c.update_project(path, project.gitosis_writers) | 36 | + c.update_project(path, project.repository_writers) |
41 | end | 37 | end |
42 | end | 38 | end |
43 | 39 | ||
44 | - def destroy_gitosis_project | 40 | + def destroy_repository |
45 | Gitlabhq::GitHost.system.new.configure do |c| | 41 | Gitlabhq::GitHost.system.new.configure do |c| |
46 | c.destroy_project(@project) | 42 | c.destroy_project(@project) |
47 | end | 43 | end |
app/models/users_project.rb
@@ -4,7 +4,7 @@ class UsersProject < ActiveRecord::Base | @@ -4,7 +4,7 @@ class UsersProject < ActiveRecord::Base | ||
4 | 4 | ||
5 | attr_protected :project_id, :project | 5 | attr_protected :project_id, :project |
6 | 6 | ||
7 | - after_commit :update_gitosis_project | 7 | + after_commit :update_repository |
8 | 8 | ||
9 | validates_uniqueness_of :user_id, :scope => [:project_id] | 9 | validates_uniqueness_of :user_id, :scope => [:project_id] |
10 | validates_presence_of :user_id | 10 | validates_presence_of :user_id |
@@ -13,9 +13,9 @@ class UsersProject < ActiveRecord::Base | @@ -13,9 +13,9 @@ class UsersProject < ActiveRecord::Base | ||
13 | 13 | ||
14 | delegate :name, :email, :to => :user, :prefix => true | 14 | delegate :name, :email, :to => :user, :prefix => true |
15 | 15 | ||
16 | - def update_gitosis_project | 16 | + def update_repository |
17 | Gitosis.new.configure do |c| | 17 | Gitosis.new.configure do |c| |
18 | - c.update_project(project.path, project.gitosis_writers) | 18 | + c.update_project(project.path, project.repository) |
19 | end | 19 | end |
20 | end | 20 | end |
21 | 21 |
config/routes.rb
@@ -14,7 +14,7 @@ Gitlab::Application.routes.draw do | @@ -14,7 +14,7 @@ Gitlab::Application.routes.draw do | ||
14 | root :to => "users#index" | 14 | root :to => "users#index" |
15 | end | 15 | end |
16 | 16 | ||
17 | - get "errors/gitosis" | 17 | + get "errors/githost" |
18 | get "profile/password", :to => "profile#password" | 18 | get "profile/password", :to => "profile#password" |
19 | put "profile/password", :to => "profile#password_update" | 19 | put "profile/password", :to => "profile#password_update" |
20 | put "profile/reset_private_token", :to => "profile#reset_private_token" | 20 | put "profile/reset_private_token", :to => "profile#reset_private_token" |
lib/gitlabhq/git_host.rb
1 | require File.join(Rails.root, "lib", "gitlabhq", "gitolite") | 1 | require File.join(Rails.root, "lib", "gitlabhq", "gitolite") |
2 | -require File.join(Rails.root, "lib", "gitlabhq", "gitosis") | ||
3 | 2 | ||
4 | module Gitlabhq | 3 | module Gitlabhq |
5 | class GitHost | 4 | class GitHost |
6 | def self.system | 5 | def self.system |
7 | - if GIT_HOST["system"] == "gitosis" | ||
8 | - Gitlabhq::Gitosis | ||
9 | - else | ||
10 | - Gitlabhq::Gitolite | ||
11 | - end | 6 | + Gitlabhq::Gitolite |
12 | end | 7 | end |
13 | 8 | ||
14 | def self.admin_uri | 9 | def self.admin_uri |
15 | GIT_HOST["admin_uri"] | 10 | GIT_HOST["admin_uri"] |
16 | end | 11 | end |
12 | + | ||
13 | + def self.url_to_repo(path) | ||
14 | + if !GIT_HOST["port"] or GIT_HOST["port"] == 22 | ||
15 | + "#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{path}.git" | ||
16 | + else | ||
17 | + "ssh://#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{GIT_HOST["port"]}/#{path}.git" | ||
18 | + end | ||
19 | + end | ||
17 | end | 20 | end |
18 | end | 21 | end |
lib/gitlabhq/gitosis.rb
@@ -1,76 +0,0 @@ | @@ -1,76 +0,0 @@ | ||
1 | -require 'inifile' | ||
2 | -require 'timeout' | ||
3 | -require 'fileutils' | ||
4 | - | ||
5 | -module Gitlabhq | ||
6 | - class Gitosis | ||
7 | - class AccessDenied < StandardError; end | ||
8 | - | ||
9 | - def pull | ||
10 | - # create tmp dir | ||
11 | - @local_dir = File.join(Dir.tmpdir,"gitlabhq-gitosis-#{Time.now.to_i}") | ||
12 | - | ||
13 | - Dir.mkdir @local_dir | ||
14 | - | ||
15 | - `git clone #{GitHost.admin_uri} #{@local_dir}/gitosis` | ||
16 | - end | ||
17 | - | ||
18 | - def push | ||
19 | - Dir.chdir(File.join(@local_dir, "gitosis")) | ||
20 | - `git add -A` | ||
21 | - `git commit -am "Gitlab"` | ||
22 | - `git push` | ||
23 | - Dir.chdir(Rails.root) | ||
24 | - | ||
25 | - FileUtils.rm_rf(@local_dir) | ||
26 | - end | ||
27 | - | ||
28 | - def configure | ||
29 | - status = Timeout::timeout(20) do | ||
30 | - File.open(File.join(Dir.tmpdir,"gitlabhq-gitosis.lock"), "w+") do |f| | ||
31 | - begin | ||
32 | - f.flock(File::LOCK_EX) | ||
33 | - pull | ||
34 | - yield(self) | ||
35 | - push | ||
36 | - ensure | ||
37 | - f.flock(File::LOCK_UN) | ||
38 | - end | ||
39 | - end | ||
40 | - end | ||
41 | - rescue Exception => ex | ||
42 | - raise Gitosis::AccessDenied.new("gitosis timeout") | ||
43 | - end | ||
44 | - | ||
45 | - def destroy_project(project) | ||
46 | - `sudo -u git rm -rf #{project.path_to_repo}` | ||
47 | - | ||
48 | - conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf')) | ||
49 | - | ||
50 | - conf.delete_section("group #{project.path}") | ||
51 | - | ||
52 | - conf.write | ||
53 | - end | ||
54 | - | ||
55 | - #update or create | ||
56 | - def update_keys(user, key) | ||
57 | - File.open(File.join(@local_dir, 'gitosis/keydir',"#{user}.pub"), 'w') {|f| f.write(key.gsub(/\n/,'')) } | ||
58 | - end | ||
59 | - | ||
60 | - def delete_key(user) | ||
61 | - File.unlink(File.join(@local_dir, 'gitosis/keydir',"#{user}.pub")) | ||
62 | - `cd #{File.join(@local_dir,'gitosis')} ; git rm keydir/#{user}.pub` | ||
63 | - end | ||
64 | - | ||
65 | - #update or create | ||
66 | - def update_project(repo_name, name_writers) | ||
67 | - # write config file | ||
68 | - conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf')) | ||
69 | - | ||
70 | - conf["group #{repo_name}"]['writable'] = repo_name | ||
71 | - conf["group #{repo_name}"]['members'] = name_writers.join(' ') | ||
72 | - | ||
73 | - conf.write | ||
74 | - end | ||
75 | - end | ||
76 | -end |
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +desc "Rebuild each project at gitolite config" | ||
2 | +task :gitolite_rebuild => :environment do | ||
3 | + puts "Starting..." | ||
4 | + Project.find_each(:batch_size => 100) do |project| | ||
5 | + puts | ||
6 | + puts "=== #{project.name}" | ||
7 | + project.update_repository | ||
8 | + puts | ||
9 | + end | ||
10 | + puts "Done" | ||
11 | +end |
spec/models/project_spec.rb
@@ -18,12 +18,12 @@ describe Project do | @@ -18,12 +18,12 @@ describe Project do | ||
18 | describe "Respond to" do | 18 | describe "Respond to" do |
19 | it { should respond_to(:readers) } | 19 | it { should respond_to(:readers) } |
20 | it { should respond_to(:writers) } | 20 | it { should respond_to(:writers) } |
21 | - it { should respond_to(:gitosis_writers) } | 21 | + it { should respond_to(:repository_writers) } |
22 | it { should respond_to(:admins) } | 22 | it { should respond_to(:admins) } |
23 | it { should respond_to(:add_access) } | 23 | it { should respond_to(:add_access) } |
24 | it { should respond_to(:reset_access) } | 24 | it { should respond_to(:reset_access) } |
25 | - it { should respond_to(:update_gitosis_project) } | ||
26 | - it { should respond_to(:destroy_gitosis_project) } | 25 | + it { should respond_to(:update_repository) } |
26 | + it { should respond_to(:destroy_repository) } | ||
27 | it { should respond_to(:public?) } | 27 | it { should respond_to(:public?) } |
28 | it { should respond_to(:private?) } | 28 | it { should respond_to(:private?) } |
29 | it { should respond_to(:url_to_repo) } | 29 | it { should respond_to(:url_to_repo) } |
@@ -35,9 +35,9 @@ describe Project do | @@ -35,9 +35,9 @@ describe Project do | ||
35 | it { should respond_to(:commit) } | 35 | it { should respond_to(:commit) } |
36 | end | 36 | end |
37 | 37 | ||
38 | - it "should not allow 'gitosis-admin' as repo name" do | 38 | + it "should not allow 'gitolite-admin' as repo name" do |
39 | should allow_value("blah").for(:path) | 39 | should allow_value("blah").for(:path) |
40 | - should_not allow_value("gitosis-admin").for(:path) | 40 | + should_not allow_value("gitolite-admin").for(:path) |
41 | end | 41 | end |
42 | 42 | ||
43 | it "should return valid url to repo" do | 43 | it "should return valid url to repo" do |
spec/monkeypatch.rb
1 | -# Stubbing Project <-> gitosis path | 1 | +# Stubbing Project <-> git host path |
2 | # create project using Factory only | 2 | # create project using Factory only |
3 | class Project | 3 | class Project |
4 | - def update_gitosis_project | 4 | + def update_repository |
5 | true | 5 | true |
6 | end | 6 | end |
7 | 7 | ||
8 | - def update_gitosis | 8 | + def update_repository |
9 | true | 9 | true |
10 | end | 10 | end |
11 | 11 | ||
@@ -15,17 +15,17 @@ class Project | @@ -15,17 +15,17 @@ class Project | ||
15 | end | 15 | end |
16 | 16 | ||
17 | class Key | 17 | class Key |
18 | - def update_gitosis | 18 | + def update_repository |
19 | true | 19 | true |
20 | end | 20 | end |
21 | 21 | ||
22 | - def gitosis_delete_key | 22 | + def repository_delete_key |
23 | true | 23 | true |
24 | end | 24 | end |
25 | end | 25 | end |
26 | 26 | ||
27 | class UsersProject | 27 | class UsersProject |
28 | - def update_gitosis_project | 28 | + def update_repository |
29 | true | 29 | true |
30 | end | 30 | end |
31 | end | 31 | end |