Commit e14a0eb8d0d22215d5185e023d4c8e3bbe91168b
Exists in
master
and in
4 other branches
Merge branch 'gitolite'
Showing
28 changed files
with
283 additions
and
152 deletions
Show diff stats
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 | ... | ... |
README.md
... | ... | @@ -29,7 +29,8 @@ git clone git://github.com/gitlabhq/gitlabhq.git |
29 | 29 | cd gitlabhq/ |
30 | 30 | |
31 | 31 | # install this library first |
32 | -sudo easy_install pygments | |
32 | +sudo pip install pygments | |
33 | +sudo apt-get install python-dev | |
33 | 34 | |
34 | 35 | # give your user access to remove git repo |
35 | 36 | # Ex. |
... | ... | @@ -56,10 +57,9 @@ Install gitosis, edit `config/gitlab.yml` and start server |
56 | 57 | bundle exec rails s -e production |
57 | 58 | ``` |
58 | 59 | |
59 | -## Install Gitosis | |
60 | +### Create git user | |
60 | 61 | |
61 | 62 | ```bash |
62 | -sudo aptitude install gitosis | |
63 | 63 | |
64 | 64 | sudo adduser \ |
65 | 65 | --system \ |
... | ... | @@ -70,6 +70,22 @@ sudo adduser \ |
70 | 70 | --home /home/git \ |
71 | 71 | git |
72 | 72 | |
73 | + | |
74 | +# Add your user to git group | |
75 | +usermod -a -G git gitlabhq_user_name | |
76 | + | |
77 | +``` | |
78 | + | |
79 | +## Install Gitolite | |
80 | + | |
81 | +### !!! IMPORTANT !!! Gitolite umask should be 0007 so users from git group has read/write access to repo | |
82 | + | |
83 | +## Install Gitosis | |
84 | + | |
85 | +```bash | |
86 | +sudo aptitude install gitosis | |
87 | + | |
88 | + | |
73 | 89 | ssh-keygen -t rsa |
74 | 90 | |
75 | 91 | sudo -H -u git gitosis-init < ~/.ssh/id_rsa.pub |
... | ... | @@ -79,6 +95,7 @@ sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update |
79 | 95 | cd /tmp && git clone git@localhost:gitosis-admin.git |
80 | 96 | |
81 | 97 | rm -rf gitosis-admin.git && cd |
98 | + | |
82 | 99 | ``` |
83 | 100 | |
84 | 101 | ## Install ruby 1.9.2 | ... | ... |
app/controllers/application_controller.rb
... | ... | @@ -3,8 +3,8 @@ class ApplicationController < ActionController::Base |
3 | 3 | protect_from_forgery |
4 | 4 | helper_method :abilities, :can? |
5 | 5 | |
6 | - rescue_from Gitosis::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 | 8 | end |
9 | 9 | |
10 | 10 | layout :layout_by_resource |
... | ... | @@ -70,7 +70,7 @@ class ApplicationController < ActionController::Base |
70 | 70 | end |
71 | 71 | |
72 | 72 | def require_non_empty_project |
73 | - redirect_to @project unless @project.repo_exists? | |
73 | + redirect_to @project unless @project.repo_exists? && @project.has_commits? | |
74 | 74 | end |
75 | 75 | |
76 | 76 | def respond_with_notes | ... | ... |
app/controllers/errors_controller.rb
app/controllers/projects_controller.rb
... | ... | @@ -8,7 +8,7 @@ class ProjectsController < ApplicationController |
8 | 8 | before_filter :add_project_abilities |
9 | 9 | before_filter :authorize_read_project!, :except => [:index, :new, :create] |
10 | 10 | before_filter :authorize_admin_project!, :only => [:edit, :update, :destroy] |
11 | - before_filter :require_non_empty_project, :only => [:blob, :tree] | |
11 | + before_filter :require_non_empty_project, :only => [:blob, :tree, :graph] | |
12 | 12 | before_filter :load_refs, :only => :tree # load @branch, @tag & @ref |
13 | 13 | |
14 | 14 | def index |
... | ... | @@ -42,8 +42,8 @@ class ProjectsController < ApplicationController |
42 | 42 | format.js |
43 | 43 | end |
44 | 44 | end |
45 | - rescue Gitosis::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 | 47 | rescue StandardError => ex |
48 | 48 | @project.errors.add(:base, "Cant save project. Please try again later") |
49 | 49 | respond_to do |format| |
... | ... | @@ -65,7 +65,7 @@ class ProjectsController < ApplicationController |
65 | 65 | end |
66 | 66 | |
67 | 67 | def show |
68 | - return render "projects/empty" unless @project.repo_exists? | |
68 | + return render "projects/empty" unless @project.repo_exists? && @project.has_commits? | |
69 | 69 | limit = (params[:limit] || 20).to_i |
70 | 70 | @activities = @project.cached_updates(limit) |
71 | 71 | end | ... | ... |
app/controllers/refs_controller.rb
1 | 1 | class RefsController < ApplicationController |
2 | 2 | before_filter :project |
3 | - before_filter :ref | |
4 | - before_filter :define_tree_vars, :only => [:tree, :blob] | |
5 | - layout "project" | |
6 | 3 | |
7 | 4 | # Authorize |
8 | 5 | before_filter :add_project_abilities |
9 | 6 | before_filter :authorize_read_project! |
10 | 7 | before_filter :require_non_empty_project |
11 | 8 | |
9 | + before_filter :ref | |
10 | + before_filter :define_tree_vars, :only => [:tree, :blob] | |
11 | + layout "project" | |
12 | + | |
12 | 13 | def switch |
13 | 14 | new_path = if params[:destination] == "tree" |
14 | 15 | tree_project_ref_path(@project, params[:ref]) |
... | ... | @@ -51,6 +52,8 @@ class RefsController < ApplicationController |
51 | 52 | @commit = project.commit(@ref) |
52 | 53 | @tree = Tree.new(@commit.tree, project, @ref, params[:path]) |
53 | 54 | @tree = TreeDecorator.new(@tree) |
55 | + rescue | |
56 | + return render_404 | |
54 | 57 | end |
55 | 58 | |
56 | 59 | def ref | ... | ... |
app/models/key.rb
... | ... | @@ -11,29 +11,29 @@ class Key < ActiveRecord::Base |
11 | 11 | :length => { :within => 0..5000 } |
12 | 12 | |
13 | 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 | 17 | def set_identifier |
18 | 18 | self.identifier = "#{user.identifier}_#{Time.now.to_i}" |
19 | 19 | end |
20 | 20 | |
21 | - def update_gitosis | |
22 | - Gitosis.new.configure do |c| | |
21 | + def update_repository | |
22 | + Gitlabhq::GitHost.system.new.configure do |c| | |
23 | 23 | c.update_keys(identifier, key) |
24 | 24 | |
25 | 25 | projects.each do |project| |
26 | - c.update_project(project.path, project.gitosis_writers) | |
26 | + c.update_project(project.path, project.repository_writers) | |
27 | 27 | end |
28 | 28 | end |
29 | 29 | end |
30 | 30 | |
31 | - def gitosis_delete_key | |
32 | - Gitosis.new.configure do |c| | |
31 | + def repository_delete_key | |
32 | + Gitlabhq::GitHost.system.new.configure do |c| | |
33 | 33 | c.delete_key(identifier) |
34 | 34 | |
35 | 35 | projects.each do |project| |
36 | - c.update_project(project.path, project.gitosis_writers) | |
36 | + c.update_project(project.path, project.repository_writers) | |
37 | 37 | end |
38 | 38 | end |
39 | 39 | end | ... | ... |
app/models/project.rb
... | ... | @@ -40,8 +40,8 @@ class Project < ActiveRecord::Base |
40 | 40 | validate :check_limit |
41 | 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 | 46 | attr_protected :private_flag, :owner_id |
47 | 47 | |
... | ... | @@ -54,8 +54,8 @@ class Project < ActiveRecord::Base |
54 | 54 | delegate :repo, |
55 | 55 | :url_to_repo, |
56 | 56 | :path_to_repo, |
57 | - :update_gitosis_project, | |
58 | - :destroy_gitosis_project, | |
57 | + :update_repository, | |
58 | + :destroy_repository, | |
59 | 59 | :tags, |
60 | 60 | :repo_exists?, |
61 | 61 | :commit, |
... | ... | @@ -95,6 +95,10 @@ class Project < ActiveRecord::Base |
95 | 95 | notes.where(:noteable_id => commit.id, :noteable_type => "Commit") |
96 | 96 | end |
97 | 97 | |
98 | + def has_commits? | |
99 | + !!commit | |
100 | + end | |
101 | + | |
98 | 102 | def add_access(user, *access) |
99 | 103 | opts = { :user => user } |
100 | 104 | access.each { |name| opts.merge!(name => true) } |
... | ... | @@ -109,7 +113,7 @@ class Project < ActiveRecord::Base |
109 | 113 | @writers ||= users_projects.includes(:user).where(:write => true).map(&:user) |
110 | 114 | end |
111 | 115 | |
112 | - def gitosis_writers | |
116 | + def repository_writers | |
113 | 117 | keys = Key.joins({:user => :users_projects}).where("users_projects.project_id = ? AND users_projects.write = ?", id, true) |
114 | 118 | keys.map(&:identifier) |
115 | 119 | end |
... | ... | @@ -180,8 +184,8 @@ class Project < ActiveRecord::Base |
180 | 184 | end |
181 | 185 | |
182 | 186 | def repo_name |
183 | - if path == "gitosis-admin" | |
184 | - errors.add(:path, " like 'gitosis-admin' is not allowed") | |
187 | + if path == "gitolite-admin" | |
188 | + errors.add(:path, " like 'gitolite-admin' is not allowed") | |
185 | 189 | end |
186 | 190 | end |
187 | 191 | ... | ... |
app/models/repository.rb
1 | +require File.join(Rails.root, "lib", "gitlabhq", "git_host") | |
2 | + | |
1 | 3 | class Repository |
2 | 4 | attr_accessor :project |
3 | 5 | |
... | ... | @@ -22,25 +24,21 @@ class Repository |
22 | 24 | end |
23 | 25 | |
24 | 26 | def url_to_repo |
25 | - if !GITOSIS["port"] or GITOSIS["port"] == 22 | |
26 | - "#{GITOSIS["git_user"]}@#{GITOSIS["host"]}:#{path}.git" | |
27 | - else | |
28 | - "ssh://#{GITOSIS["git_user"]}@#{GITOSIS["host"]}:#{GITOSIS["port"]}/#{path}.git" | |
29 | - end | |
27 | + Gitlabhq::GitHost.url_to_repo(path) | |
30 | 28 | end |
31 | 29 | |
32 | 30 | def path_to_repo |
33 | - GITOSIS["base_path"] + path + ".git" | |
31 | + GIT_HOST["base_path"] + path + ".git" | |
34 | 32 | end |
35 | 33 | |
36 | - def update_gitosis_project | |
37 | - Gitosis.new.configure do |c| | |
38 | - c.update_project(path, project.gitosis_writers) | |
34 | + def update_repository | |
35 | + Gitlabhq::GitHost.system.new.configure do |c| | |
36 | + c.update_project(path, project.repository_writers) | |
39 | 37 | end |
40 | 38 | end |
41 | 39 | |
42 | - def destroy_gitosis_project | |
43 | - Gitosis.new.configure do |c| | |
40 | + def destroy_repository | |
41 | + Gitlabhq::GitHost.system.new.configure do |c| | |
44 | 42 | c.destroy_project(@project) |
45 | 43 | end |
46 | 44 | end | ... | ... |
app/models/users_project.rb
... | ... | @@ -4,7 +4,7 @@ class UsersProject < ActiveRecord::Base |
4 | 4 | |
5 | 5 | attr_protected :project_id, :project |
6 | 6 | |
7 | - after_commit :update_gitosis_project | |
7 | + after_commit :update_repository | |
8 | 8 | |
9 | 9 | validates_uniqueness_of :user_id, :scope => [:project_id] |
10 | 10 | validates_presence_of :user_id |
... | ... | @@ -13,9 +13,9 @@ class UsersProject < ActiveRecord::Base |
13 | 13 | |
14 | 14 | delegate :name, :email, :to => :user, :prefix => true |
15 | 15 | |
16 | - def update_gitosis_project | |
16 | + def update_repository | |
17 | 17 | Gitosis.new.configure do |c| |
18 | - c.update_project(project.path, project.gitosis_writers) | |
18 | + c.update_project(project.path, project.repository) | |
19 | 19 | end |
20 | 20 | end |
21 | 21 | ... | ... |
app/views/projects/_form.html.haml
... | ... | @@ -20,13 +20,13 @@ |
20 | 20 | %tr |
21 | 21 | %td |
22 | 22 | .left= f.label :path |
23 | - %cite.right= "git@#{GITOSIS["host"]}:" | |
23 | + %cite.right= "git@#{GIT_HOST["host"]}:" | |
24 | 24 | %td |
25 | 25 | = f.text_field :path, :placeholder => "example_project", :disabled => !@project.new_record? |
26 | 26 | %tr |
27 | 27 | %td |
28 | 28 | .left= f.label :code |
29 | - %cite.right= "http://#{GITOSIS["host"]}/" | |
29 | + %cite.right= "http://#{GIT_HOST["host"]}/" | |
30 | 30 | %td= f.text_field :code, :placeholder => "example" |
31 | 31 | |
32 | 32 | %tr | ... | ... |
config/environment.rb
config/gitlab.yml
... | ... | @@ -6,9 +6,13 @@ email: |
6 | 6 | from: notify@gitlabhq.com |
7 | 7 | host: gitlabhq.com |
8 | 8 | |
9 | -# Gitosis congiguration | |
10 | -gitosis: | |
11 | - admin_uri: git@localhost:gitosis-admin.git | |
9 | +# Git Hosting congiguration | |
10 | +# You can use both gitolite & gitosis | |
11 | +# But gitosis wiil be deprecated & | |
12 | +# some new features wont work with it | |
13 | +git_host: | |
14 | + system: gitolite | |
15 | + admin_uri: git@localhost:gitolite-admin | |
12 | 16 | base_path: /home/git/repositories/ |
13 | 17 | host: localhost |
14 | 18 | git_user: git | ... | ... |
config/initializers/gitlabhq/10_load_config.rb
1 | -GITOSIS = YAML.load_file("#{Rails.root}/config/gitlab.yml")["gitosis"] | |
1 | +GIT_HOST = YAML.load_file("#{Rails.root}/config/gitlab.yml")["git_host"] | |
2 | 2 | EMAIL_OPTS = YAML.load_file("#{Rails.root}/config/gitlab.yml")["email"] |
3 | 3 | GIT_OPTS = YAML.load_file("#{Rails.root}/config/gitlab.yml")["git"] | ... | ... |
config/routes.rb
... | ... | @@ -14,7 +14,7 @@ Gitlab::Application.routes.draw do |
14 | 14 | root :to => "users#index" |
15 | 15 | end |
16 | 16 | |
17 | - get "errors/gitosis" | |
17 | + get "errors/githost" | |
18 | 18 | get "profile/password", :to => "profile#password" |
19 | 19 | put "profile/password", :to => "profile#password_update" |
20 | 20 | put "profile/reset_private_token", :to => "profile#reset_private_token" | ... | ... |
db/fixtures/development/001_admin.rb
1 | -admin = User.create( | |
2 | - :email => "admin@local.host", | |
3 | - :name => "Administrator", | |
4 | - :password => "5iveL!fe", | |
5 | - :password_confirmation => "5iveL!fe" | |
6 | -) | |
1 | +unless User.count > 0 | |
2 | + admin = User.create( | |
3 | + :email => "admin@local.host", | |
4 | + :name => "Administrator", | |
5 | + :password => "5iveL!fe", | |
6 | + :password_confirmation => "5iveL!fe" | |
7 | + ) | |
7 | 8 | |
8 | -admin.projects_limit = 10000 | |
9 | -admin.admin = true | |
10 | -admin.save! | |
9 | + admin.projects_limit = 10000 | |
10 | + admin.admin = true | |
11 | + admin.save! | |
11 | 12 | |
12 | -if admin.valid? | |
13 | -puts %q[ | |
14 | -Administrator account created: | |
13 | + if admin.valid? | |
14 | + puts %q[ | |
15 | + Administrator account created: | |
15 | 16 | |
16 | -login.........admin@local.host | |
17 | -password......5iveL!fe | |
18 | -] | |
17 | + login.........admin@local.host | |
18 | + password......5iveL!fe | |
19 | + ] | |
20 | + end | |
19 | 21 | end | ... | ... |
... | ... | @@ -0,0 +1,5 @@ |
1 | +Project.seed(:id, [ | |
2 | + { :id => 1, :name => "Gitlab HQ", :path => "gitlabhq", :code => "gitlabhq", :owner_id => 1 }, | |
3 | + { :id => 2, :name => "Diaspora", :path => "diaspora", :code => "diaspora", :owner_id => 1 }, | |
4 | + { :id => 3, :name => "Ruby on Rails", :path => "ruby_on_rails", :code => "ruby_on_rails", :owner_id => 1 } | |
5 | +]) | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +User.seed(:id, [ | |
2 | + { :id => 2, :name => Faker::Internet.user_name, :email => Faker::Internet.email}, | |
3 | + { :id => 3, :name => Faker::Internet.user_name, :email => Faker::Internet.email}, | |
4 | + { :id => 4, :name => Faker::Internet.user_name, :email => Faker::Internet.email}, | |
5 | + { :id => 5, :name => Faker::Internet.user_name, :email => Faker::Internet.email}, | |
6 | + { :id => 6, :name => Faker::Internet.user_name, :email => Faker::Internet.email}, | |
7 | + { :id => 7, :name => Faker::Internet.user_name, :email => Faker::Internet.email}, | |
8 | + { :id => 8, :name => Faker::Internet.user_name, :email => Faker::Internet.email}, | |
9 | + { :id => 9, :name => Faker::Internet.user_name, :email => Faker::Internet.email} | |
10 | +]) | |
11 | + | ... | ... |
... | ... | @@ -0,0 +1,21 @@ |
1 | +UsersProject.seed(:id, [ | |
2 | + { :id => 1, :project_id => 1, :user_id => 1, :read => true, :write => true, :admin => true }, | |
3 | + { :id => 2, :project_id => 1, :user_id => 2, :read => true, :write => false, :admin => false }, | |
4 | + { :id => 3, :project_id => 1, :user_id => 3, :read => true, :write => false, :admin => false }, | |
5 | + { :id => 4, :project_id => 1, :user_id => 4, :read => true, :write => false, :admin => false }, | |
6 | + { :id => 5, :project_id => 1, :user_id => 5, :read => true, :write => false, :admin => false }, | |
7 | + | |
8 | + { :id => 6, :project_id => 2, :user_id => 1, :read => true, :write => true, :admin => true }, | |
9 | + { :id => 7, :project_id => 2, :user_id => 2, :read => true, :write => false, :admin => false }, | |
10 | + { :id => 8, :project_id => 2, :user_id => 3, :read => true, :write => false, :admin => false }, | |
11 | + { :id => 9, :project_id => 2, :user_id => 4, :read => true, :write => false, :admin => false }, | |
12 | + { :id => 11, :project_id => 2, :user_id => 5, :read => true, :write => false, :admin => false }, | |
13 | + | |
14 | + { :id => 12, :project_id => 3, :user_id => 1, :read => true, :write => true, :admin => true }, | |
15 | + { :id => 13, :project_id => 3, :user_id => 2, :read => true, :write => false, :admin => false }, | |
16 | + { :id => 14, :project_id => 3, :user_id => 3, :read => true, :write => false, :admin => false }, | |
17 | + { :id => 15, :project_id => 3, :user_id => 4, :read => true, :write => false, :admin => false }, | |
18 | + { :id => 16, :project_id => 3, :user_id => 5, :read => true, :write => false, :admin => false } | |
19 | +]) | |
20 | + | |
21 | + | ... | ... |
... | ... | @@ -0,0 +1,21 @@ |
1 | +require File.join(Rails.root, "lib", "gitlabhq", "gitolite") | |
2 | + | |
3 | +module Gitlabhq | |
4 | + class GitHost | |
5 | + def self.system | |
6 | + Gitlabhq::Gitolite | |
7 | + end | |
8 | + | |
9 | + def self.admin_uri | |
10 | + GIT_HOST["admin_uri"] | |
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 | |
20 | + end | |
21 | +end | ... | ... |
... | ... | @@ -0,0 +1,80 @@ |
1 | +require 'gitolite' | |
2 | +require 'timeout' | |
3 | +require 'fileutils' | |
4 | + | |
5 | +module Gitlabhq | |
6 | + class Gitolite | |
7 | + class AccessDenied < StandardError; end | |
8 | + | |
9 | + def pull | |
10 | + # create tmp dir | |
11 | + @local_dir = File.join(Dir.tmpdir,"gitlabhq-gitolite-#{Time.now.to_i}") | |
12 | + Dir.mkdir @local_dir | |
13 | + | |
14 | + `git clone #{GitHost.admin_uri} #{@local_dir}/gitolite` | |
15 | + end | |
16 | + | |
17 | + def push | |
18 | + Dir.chdir(File.join(@local_dir, "gitolite")) | |
19 | + `git add -A` | |
20 | + `git commit -am "Gitlab"` | |
21 | + `git push` | |
22 | + Dir.chdir(Rails.root) | |
23 | + | |
24 | + FileUtils.rm_rf(@local_dir) | |
25 | + end | |
26 | + | |
27 | + def configure | |
28 | + status = Timeout::timeout(20) do | |
29 | + File.open(File.join(Dir.tmpdir,"gitlabhq-gitolite.lock"), "w+") do |f| | |
30 | + begin | |
31 | + f.flock(File::LOCK_EX) | |
32 | + pull | |
33 | + yield(self) | |
34 | + push | |
35 | + ensure | |
36 | + f.flock(File::LOCK_UN) | |
37 | + end | |
38 | + end | |
39 | + end | |
40 | + rescue Exception => ex | |
41 | + raise Gitolite::AccessDenied.new("gitolite timeout") | |
42 | + end | |
43 | + | |
44 | + def destroy_project(project) | |
45 | + `sudo -u git rm -rf #{project.path_to_repo}` | |
46 | + | |
47 | + ga_repo = ::Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite')) | |
48 | + conf = ga_repo.config | |
49 | + conf.rm_repo(project.path) | |
50 | + ga_repo.save | |
51 | + end | |
52 | + | |
53 | + #update or create | |
54 | + def update_keys(user, key) | |
55 | + File.open(File.join(@local_dir, 'gitolite/keydir',"#{user}.pub"), 'w') {|f| f.write(key.gsub(/\n/,'')) } | |
56 | + end | |
57 | + | |
58 | + def delete_key(user) | |
59 | + File.unlink(File.join(@local_dir, 'gitolite/keydir',"#{user}.pub")) | |
60 | + `cd #{File.join(@local_dir,'gitolite')} ; git rm keydir/#{user}.pub` | |
61 | + end | |
62 | + | |
63 | + # update or create | |
64 | + def update_project(repo_name, name_writers) | |
65 | + ga_repo = ::Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite')) | |
66 | + conf = ga_repo.config | |
67 | + | |
68 | + repo = if conf.has_repo?(repo_name) | |
69 | + conf.get_repo(repo_name) | |
70 | + else | |
71 | + ::Gitolite::Config::Repo.new(repo_name) | |
72 | + end | |
73 | + | |
74 | + repo.add_permission("RW+", "", name_writers) unless name_writers.blank? | |
75 | + conf.add_repo(repo) | |
76 | + | |
77 | + ga_repo.save | |
78 | + end | |
79 | + end | |
80 | +end | ... | ... |
lib/gitosis.rb
... | ... | @@ -1,74 +0,0 @@ |
1 | -require 'inifile' | |
2 | -require 'timeout' | |
3 | -require 'fileutils' | |
4 | - | |
5 | -class Gitosis | |
6 | - class AccessDenied < StandardError; end | |
7 | - | |
8 | - def pull | |
9 | - # create tmp dir | |
10 | - @local_dir = File.join(Dir.tmpdir,"gitlabhq-gitosis-#{Time.now.to_i}") | |
11 | - | |
12 | - Dir.mkdir @local_dir | |
13 | - | |
14 | - `git clone #{GITOSIS['admin_uri']} #{@local_dir}/gitosis` | |
15 | - end | |
16 | - | |
17 | - def push | |
18 | - Dir.chdir(File.join(@local_dir, "gitosis")) | |
19 | - `git add -A` | |
20 | - `git commit -am "Gitlab"` | |
21 | - `git push` | |
22 | - Dir.chdir(Rails.root) | |
23 | - | |
24 | - FileUtils.rm_rf(@local_dir) | |
25 | - end | |
26 | - | |
27 | - def configure | |
28 | - status = Timeout::timeout(20) do | |
29 | - File.open(File.join(Dir.tmpdir,"gitlabhq-gitosis.lock"), "w+") do |f| | |
30 | - begin | |
31 | - f.flock(File::LOCK_EX) | |
32 | - pull | |
33 | - yield(self) | |
34 | - push | |
35 | - ensure | |
36 | - f.flock(File::LOCK_UN) | |
37 | - end | |
38 | - end | |
39 | - end | |
40 | - rescue Exception => ex | |
41 | - raise Gitosis::AccessDenied.new("gitosis timeout") | |
42 | - end | |
43 | - | |
44 | - def destroy_project(project) | |
45 | - `sudo -u git rm -rf #{project.path_to_repo}` | |
46 | - | |
47 | - conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf')) | |
48 | - | |
49 | - conf.delete_section("group #{project.path}") | |
50 | - | |
51 | - conf.write | |
52 | - end | |
53 | - | |
54 | - #update or create | |
55 | - def update_keys(user, key) | |
56 | - File.open(File.join(@local_dir, 'gitosis/keydir',"#{user}.pub"), 'w') {|f| f.write(key.gsub(/\n/,'')) } | |
57 | - end | |
58 | - | |
59 | - 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 | - end | |
63 | - | |
64 | - #update or create | |
65 | - def update_project(repo_name, name_writers) | |
66 | - # write config file | |
67 | - conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf')) | |
68 | - | |
69 | - conf["group #{repo_name}"]['writable'] = repo_name | |
70 | - conf["group #{repo_name}"]['members'] = name_writers.join(' ') | |
71 | - | |
72 | - conf.write | |
73 | - end | |
74 | -end |
... | ... | @@ -0,0 +1,18 @@ |
1 | +desc "Rebuild each project at gitolite config" | |
2 | +task :gitolite_rebuild => :environment do | |
3 | + puts "Starting Projects" | |
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 with projects" | |
11 | + | |
12 | + puts "Starting Key" | |
13 | + Key.find_each(:batch_size => 100) do |project| | |
14 | + project.update_repository | |
15 | + print '.' | |
16 | + end | |
17 | + puts "Done with keys" | |
18 | +end | ... | ... |
spec/models/project_spec.rb
... | ... | @@ -18,12 +18,12 @@ describe Project do |
18 | 18 | describe "Respond to" do |
19 | 19 | it { should respond_to(:readers) } |
20 | 20 | it { should respond_to(:writers) } |
21 | - it { should respond_to(:gitosis_writers) } | |
21 | + it { should respond_to(:repository_writers) } | |
22 | 22 | it { should respond_to(:admins) } |
23 | 23 | it { should respond_to(:add_access) } |
24 | 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 | 27 | it { should respond_to(:public?) } |
28 | 28 | it { should respond_to(:private?) } |
29 | 29 | it { should respond_to(:url_to_repo) } |
... | ... | @@ -35,9 +35,9 @@ describe Project do |
35 | 35 | it { should respond_to(:commit) } |
36 | 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 | 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 | 41 | end |
42 | 42 | |
43 | 43 | it "should return valid url to repo" do | ... | ... |
spec/monkeypatch.rb
1 | -# Stubbing Project <-> gitosis path | |
1 | +# Stubbing Project <-> git host path | |
2 | 2 | # create project using Factory only |
3 | 3 | class Project |
4 | - def update_gitosis_project | |
4 | + def update_repository | |
5 | 5 | true |
6 | 6 | end |
7 | 7 | |
8 | - def update_gitosis | |
8 | + def update_repository | |
9 | 9 | true |
10 | 10 | end |
11 | 11 | |
... | ... | @@ -15,17 +15,17 @@ class Project |
15 | 15 | end |
16 | 16 | |
17 | 17 | class Key |
18 | - def update_gitosis | |
18 | + def update_repository | |
19 | 19 | true |
20 | 20 | end |
21 | 21 | |
22 | - def gitosis_delete_key | |
22 | + def repository_delete_key | |
23 | 23 | true |
24 | 24 | end |
25 | 25 | end |
26 | 26 | |
27 | 27 | class UsersProject |
28 | - def update_gitosis_project | |
28 | + def update_repository | |
29 | 29 | true |
30 | 30 | end |
31 | 31 | end | ... | ... |