From c03bc6e2912b2e63a352e1f7e664b32a95aa9cad Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 4 Dec 2011 01:08:08 +0200 Subject: [PATCH 1/8] 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 df904460..4f1f0860 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 c975a956..59c3b5e2 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 caa26ad2..3afd9c11 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 92d32d8b..6aa32849 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 From 9e089efe5a2defa38cc94347a5051f1cfe91406b Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 4 Dec 2011 01:44:59 +0200 Subject: [PATCH 2/8] gitolite & gitosis support --- app/controllers/application_controller.rb | 2 +- app/controllers/projects_controller.rb | 2 +- app/models/key.rb | 4 +- app/models/repository.rb | 12 +-- app/views/projects/_form.html.haml | 4 +- config/environment.rb | 2 +- config/gitlab.yml | 3 +- .../initializers/gitlabhq/10_load_config.rb | 2 +- lib/.directory | 5 ++ lib/gitlabhq/.directory | 5 ++ lib/gitlabhq/git_host.rb | 18 ++++ lib/gitlabhq/gitolite.rb | 80 ++++++++++++++++++ lib/gitlabhq/gitosis.rb | 76 +++++++++++++++++ lib/gitosis.rb | 83 ------------------- 14 files changed, 200 insertions(+), 98 deletions(-) create mode 100644 lib/.directory create mode 100644 lib/gitlabhq/.directory create mode 100644 lib/gitlabhq/git_host.rb create mode 100644 lib/gitlabhq/gitolite.rb create mode 100644 lib/gitlabhq/gitosis.rb delete mode 100644 lib/gitosis.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b37deafd..380336f3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base protect_from_forgery helper_method :abilities, :can? - rescue_from Gitosis::AccessDenied do |exception| + rescue_from Gitlabhq::Gitosis::AccessDenied, Gitlabhq::Gitolite::AccessDenied do |exception| render :file => File.join(Rails.root, "public", "gitosis_error"), :layout => false end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 717f8595..11b4f0bf 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -42,7 +42,7 @@ class ProjectsController < ApplicationController format.js end end - rescue Gitosis::AccessDenied + rescue Gitlabhq::Gitosis::AccessDenied, Gitlabhq::Gitolite::AccessDenied render :js => "location.href = '#{errors_gitosis_path}'" and return rescue StandardError => ex @project.errors.add(:base, "Cant save project. Please try again later") diff --git a/app/models/key.rb b/app/models/key.rb index 8231c30c..f2f0134c 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -19,7 +19,7 @@ class Key < ActiveRecord::Base end def update_gitosis - Gitosis.new.configure do |c| + GitoProxy.system.new.configure do |c| c.update_keys(identifier, key) projects.each do |project| @@ -29,7 +29,7 @@ class Key < ActiveRecord::Base end def gitosis_delete_key - Gitosis.new.configure do |c| + GitoProxy.system.new.configure do |c| c.delete_key(identifier) projects.each do |project| diff --git a/app/models/repository.rb b/app/models/repository.rb index b87a1fba..a3e2e1e5 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -22,25 +22,25 @@ class Repository end def url_to_repo - if !GITOSIS["port"] or GITOSIS["port"] == 22 - "#{GITOSIS["git_user"]}@#{GITOSIS["host"]}:#{path}.git" + if !GIT_HOST["port"] or GIT_HOST["port"] == 22 + "#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{path}.git" else - "ssh://#{GITOSIS["git_user"]}@#{GITOSIS["host"]}:#{GITOSIS["port"]}/#{path}.git" + "ssh://#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{GIT_HOST["port"]}/#{path}.git" end end def path_to_repo - GITOSIS["base_path"] + path + ".git" + GIT_HOST["base_path"] + path + ".git" end def update_gitosis_project - Gitosis.new.configure do |c| + GitProxy.system.new.configure do |c| c.update_project(path, project.gitosis_writers) end end def destroy_gitosis_project - Gitosis.new.configure do |c| + GitProxy.system.new.configure do |c| c.destroy_project(@project) end end diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index 234dee97..ce2fd069 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -20,13 +20,13 @@ %tr %td .left= f.label :path - %cite.right= "git@#{GITOSIS["host"]}:" + %cite.right= "git@#{GIT_HOST["host"]}:" %td = f.text_field :path, :placeholder => "example_project", :disabled => !@project.new_record? %tr %td .left= f.label :code - %cite.right= "http://#{GITOSIS["host"]}/" + %cite.right= "http://#{GIT_HOST["host"]}/" %td= f.text_field :code, :placeholder => "example" %tr diff --git a/config/environment.rb b/config/environment.rb index 1c2d723e..9b09be05 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -4,4 +4,4 @@ require File.expand_path('../application', __FILE__) # Initialize the rails application Gitlab::Application.initialize! -require File.join(Rails.root, "lib", "gitosis") +require File.join(Rails.root, "lib", "gitlabhq", "git_host") diff --git a/config/gitlab.yml b/config/gitlab.yml index 3afd9c11..c61d382f 100644 --- a/config/gitlab.yml +++ b/config/gitlab.yml @@ -7,7 +7,8 @@ email: host: gitlabhq.com # Gitosis congiguration -gitosis: +git_host: + system: gitolite# or gitosis admin_uri: git@localhost:gitolite-admin base_path: /home/git/repositories/ host: localhost diff --git a/config/initializers/gitlabhq/10_load_config.rb b/config/initializers/gitlabhq/10_load_config.rb index cfda096e..96919595 100644 --- a/config/initializers/gitlabhq/10_load_config.rb +++ b/config/initializers/gitlabhq/10_load_config.rb @@ -1,3 +1,3 @@ -GITOSIS = YAML.load_file("#{Rails.root}/config/gitlab.yml")["gitosis"] +GIT_HOST = YAML.load_file("#{Rails.root}/config/gitlab.yml")["git_host"] EMAIL_OPTS = YAML.load_file("#{Rails.root}/config/gitlab.yml")["email"] GIT_OPTS = YAML.load_file("#{Rails.root}/config/gitlab.yml")["git"] diff --git a/lib/.directory b/lib/.directory new file mode 100644 index 00000000..c0d0b18f --- /dev/null +++ b/lib/.directory @@ -0,0 +1,5 @@ +[Dolphin] +AdditionalInfoV2=Details_Size,Details_Date,CustomizedDetails +Timestamp=2011,12,4,1,34,13 +Version=2 +ViewMode=1 diff --git a/lib/gitlabhq/.directory b/lib/gitlabhq/.directory new file mode 100644 index 00000000..fcaf533b --- /dev/null +++ b/lib/gitlabhq/.directory @@ -0,0 +1,5 @@ +[Dolphin] +AdditionalInfoV2=Details_Size,Details_Date,CustomizedDetails +Timestamp=2011,12,4,1,34,17 +Version=2 +ViewMode=1 diff --git a/lib/gitlabhq/git_host.rb b/lib/gitlabhq/git_host.rb new file mode 100644 index 00000000..48f5a150 --- /dev/null +++ b/lib/gitlabhq/git_host.rb @@ -0,0 +1,18 @@ +require File.join(Rails.root, "lib", "gitlabhq", "gitolite") +require File.join(Rails.root, "lib", "gitlabhq", "gitosis") + +module Gitlabhq + class GitHost + def self.system + if GIT_HOST["system"] == "gitolite" + Gitlabhq::Gitolite + else + Gitlabhq::Gitosis + end + end + + def self.admin_uri + GIT_HOST["admin_uri"] + end + end +end diff --git a/lib/gitlabhq/gitolite.rb b/lib/gitlabhq/gitolite.rb new file mode 100644 index 00000000..de8241fe --- /dev/null +++ b/lib/gitlabhq/gitolite.rb @@ -0,0 +1,80 @@ +require 'gitolite' +require 'timeout' +require 'fileutils' + +module Gitlabhq + class Gitolite + class AccessDenied < StandardError; end + + def pull + # create tmp dir + @local_dir = File.join(Dir.tmpdir,"gitlabhq-gitolite-#{Time.now.to_i}") + Dir.mkdir @local_dir + + `git clone #{GitHost.admin_uri} #{@local_dir}/gitolite` + end + + def push + Dir.chdir(File.join(@local_dir, "gitolite")) + `git add -A` + `git commit -am "Gitlab"` + `git push` + Dir.chdir(Rails.root) + + FileUtils.rm_rf(@local_dir) + end + + def configure + status = Timeout::timeout(20) do + File.open(File.join(Dir.tmpdir,"gitlabhq-gitolite.lock"), "w+") do |f| + begin + f.flock(File::LOCK_EX) + pull + yield(self) + push + ensure + f.flock(File::LOCK_UN) + end + end + end + rescue Exception => ex + raise Gitolite::AccessDenied.new("gitolite timeout") + end + + def destroy_project(project) + `sudo -u git rm -rf #{project.path_to_repo}` + + ga_repo = ::Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite')) + conf = ga_repo.config + conf.rm_repo(project.path) + ga_repo.save + end + + #update or create + def update_keys(user, key) + 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, '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) + ga_repo = ::Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite')) + conf = ga_repo.config + + repo = if conf.has_repo?(repo_name) + conf.get_repo(repo_name) + else + ::Gitolite::Config::Repo.new(repo_name) + end + + repo.add_permission("RW+", "", name_writers) unless name_writers.blank? + conf.add_repo(repo) + + ga_repo.save + end + end +end diff --git a/lib/gitlabhq/gitosis.rb b/lib/gitlabhq/gitosis.rb new file mode 100644 index 00000000..a3dbcc80 --- /dev/null +++ b/lib/gitlabhq/gitosis.rb @@ -0,0 +1,76 @@ +require 'inifile' +require 'timeout' +require 'fileutils' + +module Gitlabhq + class Gitosis + class AccessDenied < StandardError; end + + def pull + # create tmp dir + @local_dir = File.join(Dir.tmpdir,"gitlabhq-gitosis-#{Time.now.to_i}") + + Dir.mkdir @local_dir + + `git clone #{GitHost.admin_uri} #{@local_dir}/gitosis` + end + + def push + Dir.chdir(File.join(@local_dir, "gitosis")) + `git add -A` + `git commit -am "Gitlab"` + `git push` + Dir.chdir(Rails.root) + + FileUtils.rm_rf(@local_dir) + end + + def configure + status = Timeout::timeout(20) do + File.open(File.join(Dir.tmpdir,"gitlabhq-gitosis.lock"), "w+") do |f| + begin + f.flock(File::LOCK_EX) + pull + yield(self) + push + ensure + f.flock(File::LOCK_UN) + end + end + end + rescue Exception => ex + raise Gitosis::AccessDenied.new("gitosis 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.delete_section("group #{project.path}") + + conf.write + end + + #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/,'')) } + 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` + end + + #update or create + def update_project(repo_name, name_writers) + # write config file + conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf')) + + conf["group #{repo_name}"]['writable'] = repo_name + conf["group #{repo_name}"]['members'] = name_writers.join(' ') + + conf.write + end + end +end diff --git a/lib/gitosis.rb b/lib/gitosis.rb deleted file mode 100644 index 6aa32849..00000000 --- a/lib/gitosis.rb +++ /dev/null @@ -1,83 +0,0 @@ -require 'gitolite' - -require 'inifile' -require 'timeout' -require 'fileutils' - -class Gitosis - class AccessDenied < StandardError; end - - def pull - # create tmp dir - @local_dir = File.join(Dir.tmpdir,"gitlabhq-gitolite-#{Time.now.to_i}") - - Dir.mkdir @local_dir - - `git clone #{GITOSIS['admin_uri']} #{@local_dir}/gitolite` - end - - def push - Dir.chdir(File.join(@local_dir, "gitolite")) - `git add -A` - `git commit -am "Gitlab"` - `git push` - Dir.chdir(Rails.root) - - FileUtils.rm_rf(@local_dir) - end - - def configure - status = Timeout::timeout(20) do - File.open(File.join(Dir.tmpdir,"gitlabhq-gitolite.lock"), "w+") do |f| - begin - f.flock(File::LOCK_EX) - pull - yield(self) - push - ensure - f.flock(File::LOCK_UN) - end - end - end - #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,'gitolite', 'conf', 'gitolite.conf')) - - conf.delete_section("group #{project.path}") - - conf.write - end - - #update or create - def update_keys(user, key) - 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, '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) - ga_repo = Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite')) - conf = ga_repo.config - - repo = if conf.has_repo?(repo_name) - conf.get_repo(repo_name) - else - Gitolite::Config::Repo.new(repo_name) - end - - repo.add_permission("RW+", "", name_writers) unless name_writers.blank? - - conf.add_repo(repo) - - ga_repo.save - end -end From a41d57691d47dce8db788d6cf97031bf1321a792 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 4 Dec 2011 01:52:19 +0200 Subject: [PATCH 3/8] updated README --- README.md | 23 ++++++++++++++++++++--- config/gitlab.yml | 5 ++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 766d18cc..12a0aba7 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,8 @@ git clone git://github.com/gitlabhq/gitlabhq.git cd gitlabhq/ # install this library first -sudo easy_install pygments +sudo pip install pygments +sudo apt-get install python-dev # give your user access to remove git repo # Ex. @@ -56,10 +57,9 @@ Install gitosis, edit `config/gitlab.yml` and start server bundle exec rails s -e production ``` -## Install Gitosis +### Create git user ```bash -sudo aptitude install gitosis sudo adduser \ --system \ @@ -70,6 +70,22 @@ sudo adduser \ --home /home/git \ git + +# Add your user to git group +usermod -a -G git gitlabhq_user_name + +``` + +## Install Gitolite + +### !!! IMPORTANT !!! Gitolite umask should be 0007 so users from git group has read/write access to repo + +## Install Gitosis + +```bash +sudo aptitude install gitosis + + ssh-keygen -t rsa 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 cd /tmp && git clone git@localhost:gitosis-admin.git rm -rf gitosis-admin.git && cd + ``` ## Install ruby 1.9.2 diff --git a/config/gitlab.yml b/config/gitlab.yml index c61d382f..5e85af78 100644 --- a/config/gitlab.yml +++ b/config/gitlab.yml @@ -6,7 +6,10 @@ email: from: notify@gitlabhq.com host: gitlabhq.com -# Gitosis congiguration +# Git Hosting congiguration +# You can use both gitolite & gitosis +# But gitosis wiil be deprecated & +# some new features wont work with it git_host: system: gitolite# or gitosis admin_uri: git@localhost:gitolite-admin From 03e51c30583908882204d2bfc8c647a7c5bc35ef Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 4 Dec 2011 22:19:49 +0200 Subject: [PATCH 4/8] fixtures added --- app/models/repository.rb | 6 +++-- db/fixtures/development/001_admin.rb | 32 ++++++++++++++------------ db/fixtures/development/002_project.rb | 5 ++++ db/fixtures/development/003_users.rb | 11 +++++++++ db/fixtures/development/004_teams.rb | 21 +++++++++++++++++ 5 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 db/fixtures/development/002_project.rb create mode 100644 db/fixtures/development/003_users.rb create mode 100644 db/fixtures/development/004_teams.rb diff --git a/app/models/repository.rb b/app/models/repository.rb index a3e2e1e5..1a1c90a6 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1,3 +1,5 @@ +require File.join(Rails.root, "lib", "gitlabhq", "git_host") + class Repository attr_accessor :project @@ -34,13 +36,13 @@ class Repository end def update_gitosis_project - GitProxy.system.new.configure do |c| + Gitlabhq::GitHost.system.new.configure do |c| c.update_project(path, project.gitosis_writers) end end def destroy_gitosis_project - GitProxy.system.new.configure do |c| + Gitlabhq::GitHost.system.new.configure do |c| c.destroy_project(@project) end end diff --git a/db/fixtures/development/001_admin.rb b/db/fixtures/development/001_admin.rb index cfff6bf8..c857f6bc 100644 --- a/db/fixtures/development/001_admin.rb +++ b/db/fixtures/development/001_admin.rb @@ -1,19 +1,21 @@ -admin = User.create( - :email => "admin@local.host", - :name => "Administrator", - :password => "5iveL!fe", - :password_confirmation => "5iveL!fe" -) +unless User.count > 0 + admin = User.create( + :email => "admin@local.host", + :name => "Administrator", + :password => "5iveL!fe", + :password_confirmation => "5iveL!fe" + ) -admin.projects_limit = 10000 -admin.admin = true -admin.save! + admin.projects_limit = 10000 + admin.admin = true + admin.save! -if admin.valid? -puts %q[ -Administrator account created: + if admin.valid? + puts %q[ + Administrator account created: -login.........admin@local.host -password......5iveL!fe -] + login.........admin@local.host + password......5iveL!fe + ] + end end diff --git a/db/fixtures/development/002_project.rb b/db/fixtures/development/002_project.rb new file mode 100644 index 00000000..8eb99f2c --- /dev/null +++ b/db/fixtures/development/002_project.rb @@ -0,0 +1,5 @@ +Project.seed(:id, [ + { :id => 1, :name => "Gitlab HQ", :path => "gitlabhq", :code => "gitlabhq", :owner_id => 1 }, + { :id => 2, :name => "Diaspora", :path => "diaspora", :code => "diaspora", :owner_id => 1 }, + { :id => 3, :name => "Ruby on Rails", :path => "ruby_on_rails", :code => "ruby_on_rails", :owner_id => 1 } +]) diff --git a/db/fixtures/development/003_users.rb b/db/fixtures/development/003_users.rb new file mode 100644 index 00000000..309eb90b --- /dev/null +++ b/db/fixtures/development/003_users.rb @@ -0,0 +1,11 @@ +User.seed(:id, [ + { :id => 2, :name => Faker::Internet.user_name, :email => Faker::Internet.email}, + { :id => 3, :name => Faker::Internet.user_name, :email => Faker::Internet.email}, + { :id => 4, :name => Faker::Internet.user_name, :email => Faker::Internet.email}, + { :id => 5, :name => Faker::Internet.user_name, :email => Faker::Internet.email}, + { :id => 6, :name => Faker::Internet.user_name, :email => Faker::Internet.email}, + { :id => 7, :name => Faker::Internet.user_name, :email => Faker::Internet.email}, + { :id => 8, :name => Faker::Internet.user_name, :email => Faker::Internet.email}, + { :id => 9, :name => Faker::Internet.user_name, :email => Faker::Internet.email} +]) + diff --git a/db/fixtures/development/004_teams.rb b/db/fixtures/development/004_teams.rb new file mode 100644 index 00000000..69742e41 --- /dev/null +++ b/db/fixtures/development/004_teams.rb @@ -0,0 +1,21 @@ +UsersProject.seed(:id, [ + { :id => 1, :project_id => 1, :user_id => 1}, + { :id => 2, :project_id => 1, :user_id => 2}, + { :id => 3, :project_id => 1, :user_id => 3}, + { :id => 4, :project_id => 1, :user_id => 4}, + { :id => 5, :project_id => 1, :user_id => 5}, + + { :id => 6, :project_id => 2, :user_id => 1}, + { :id => 7, :project_id => 2, :user_id => 2}, + { :id => 8, :project_id => 2, :user_id => 3}, + { :id => 9, :project_id => 2, :user_id => 4}, + { :id => 11, :project_id => 2, :user_id => 5}, + + { :id => 12, :project_id => 3, :user_id => 1}, + { :id => 13, :project_id => 3, :user_id => 2}, + { :id => 14, :project_id => 3, :user_id => 3}, + { :id => 15, :project_id => 3, :user_id => 4}, + { :id => 16, :project_id => 3, :user_id => 5} +]) + + From 8f4a0bd1743875289d5870b7d19ecb6c80016b6c Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 4 Dec 2011 22:34:39 +0200 Subject: [PATCH 5/8] fix filters & seeds --- app/controllers/projects_controller.rb | 2 +- app/controllers/refs_controller.rb | 7 +++--- app/models/project.rb | 2 +- db/fixtures/development/004_teams.rb | 30 +++++++++++++------------- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 11b4f0bf..a0899151 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -8,7 +8,7 @@ class ProjectsController < ApplicationController before_filter :add_project_abilities before_filter :authorize_read_project!, :except => [:index, :new, :create] before_filter :authorize_admin_project!, :only => [:edit, :update, :destroy] - before_filter :require_non_empty_project, :only => [:blob, :tree] + before_filter :require_non_empty_project, :only => [:blob, :tree, :graph] before_filter :load_refs, :only => :tree # load @branch, @tag & @ref def index diff --git a/app/controllers/refs_controller.rb b/app/controllers/refs_controller.rb index fab732e2..66924b8d 100644 --- a/app/controllers/refs_controller.rb +++ b/app/controllers/refs_controller.rb @@ -1,14 +1,15 @@ class RefsController < ApplicationController before_filter :project - before_filter :ref - before_filter :define_tree_vars, :only => [:tree, :blob] - layout "project" # Authorize before_filter :add_project_abilities before_filter :authorize_read_project! before_filter :require_non_empty_project + before_filter :ref + before_filter :define_tree_vars, :only => [:tree, :blob] + layout "project" + def switch new_path = if params[:destination] == "tree" tree_project_ref_path(@project, params[:ref]) diff --git a/app/models/project.rb b/app/models/project.rb index ae63efb6..e3fb9c94 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -180,7 +180,7 @@ class Project < ActiveRecord::Base end def repo_name - if path == "gitosis-admin" + if path == "gitosis-admin" && path == "gitolite-admin" errors.add(:path, " like 'gitosis-admin' is not allowed") end end diff --git a/db/fixtures/development/004_teams.rb b/db/fixtures/development/004_teams.rb index 69742e41..2ba8e18f 100644 --- a/db/fixtures/development/004_teams.rb +++ b/db/fixtures/development/004_teams.rb @@ -1,21 +1,21 @@ UsersProject.seed(:id, [ - { :id => 1, :project_id => 1, :user_id => 1}, - { :id => 2, :project_id => 1, :user_id => 2}, - { :id => 3, :project_id => 1, :user_id => 3}, - { :id => 4, :project_id => 1, :user_id => 4}, - { :id => 5, :project_id => 1, :user_id => 5}, + { :id => 1, :project_id => 1, :user_id => 1, :read => true, :write => true, :admin => true }, + { :id => 2, :project_id => 1, :user_id => 2, :read => true, :write => false, :admin => false }, + { :id => 3, :project_id => 1, :user_id => 3, :read => true, :write => false, :admin => false }, + { :id => 4, :project_id => 1, :user_id => 4, :read => true, :write => false, :admin => false }, + { :id => 5, :project_id => 1, :user_id => 5, :read => true, :write => false, :admin => false }, - { :id => 6, :project_id => 2, :user_id => 1}, - { :id => 7, :project_id => 2, :user_id => 2}, - { :id => 8, :project_id => 2, :user_id => 3}, - { :id => 9, :project_id => 2, :user_id => 4}, - { :id => 11, :project_id => 2, :user_id => 5}, + { :id => 6, :project_id => 2, :user_id => 1, :read => true, :write => true, :admin => true }, + { :id => 7, :project_id => 2, :user_id => 2, :read => true, :write => false, :admin => false }, + { :id => 8, :project_id => 2, :user_id => 3, :read => true, :write => false, :admin => false }, + { :id => 9, :project_id => 2, :user_id => 4, :read => true, :write => false, :admin => false }, + { :id => 11, :project_id => 2, :user_id => 5, :read => true, :write => false, :admin => false }, - { :id => 12, :project_id => 3, :user_id => 1}, - { :id => 13, :project_id => 3, :user_id => 2}, - { :id => 14, :project_id => 3, :user_id => 3}, - { :id => 15, :project_id => 3, :user_id => 4}, - { :id => 16, :project_id => 3, :user_id => 5} + { :id => 12, :project_id => 3, :user_id => 1, :read => true, :write => true, :admin => true }, + { :id => 13, :project_id => 3, :user_id => 2, :read => true, :write => false, :admin => false }, + { :id => 14, :project_id => 3, :user_id => 3, :read => true, :write => false, :admin => false }, + { :id => 15, :project_id => 3, :user_id => 4, :read => true, :write => false, :admin => false }, + { :id => 16, :project_id => 3, :user_id => 5, :read => true, :write => false, :admin => false } ]) From 8134fe0efe287f6512b7684d4c654b2d43f3df9d Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 5 Dec 2011 09:23:53 +0200 Subject: [PATCH 6/8] git host fixed --- app/controllers/application_controller.rb | 2 +- app/controllers/projects_controller.rb | 2 +- app/controllers/refs_controller.rb | 2 ++ app/models/key.rb | 4 ++-- app/models/project.rb | 4 ++++ config/gitlab.yml | 2 +- lib/gitlabhq/git_host.rb | 6 +++--- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 380336f3..1f971302 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -70,7 +70,7 @@ class ApplicationController < ActionController::Base end def require_non_empty_project - redirect_to @project unless @project.repo_exists? + redirect_to @project unless @project.repo_exists? && @project.has_commits? end def respond_with_notes diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a0899151..4b8c196b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -65,7 +65,7 @@ class ProjectsController < ApplicationController end def show - return render "projects/empty" unless @project.repo_exists? + return render "projects/empty" unless @project.repo_exists? && @project.has_commits? limit = (params[:limit] || 20).to_i @activities = @project.cached_updates(limit) end diff --git a/app/controllers/refs_controller.rb b/app/controllers/refs_controller.rb index 66924b8d..d2be5ad5 100644 --- a/app/controllers/refs_controller.rb +++ b/app/controllers/refs_controller.rb @@ -52,6 +52,8 @@ class RefsController < ApplicationController @commit = project.commit(@ref) @tree = Tree.new(@commit.tree, project, @ref, params[:path]) @tree = TreeDecorator.new(@tree) + rescue + return render_404 end def ref diff --git a/app/models/key.rb b/app/models/key.rb index f2f0134c..572f002b 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -19,7 +19,7 @@ class Key < ActiveRecord::Base end def update_gitosis - GitoProxy.system.new.configure do |c| + Gitlabhq::GitHost.system.new.configure do |c| c.update_keys(identifier, key) projects.each do |project| @@ -29,7 +29,7 @@ class Key < ActiveRecord::Base end def gitosis_delete_key - GitoProxy.system.new.configure do |c| + Gitlabhq::GitHost.system.new.configure do |c| c.delete_key(identifier) projects.each do |project| diff --git a/app/models/project.rb b/app/models/project.rb index e3fb9c94..f4841653 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -95,6 +95,10 @@ class Project < ActiveRecord::Base notes.where(:noteable_id => commit.id, :noteable_type => "Commit") end + def has_commits? + !!commit + end + def add_access(user, *access) opts = { :user => user } access.each { |name| opts.merge!(name => true) } diff --git a/config/gitlab.yml b/config/gitlab.yml index 5e85af78..e861031e 100644 --- a/config/gitlab.yml +++ b/config/gitlab.yml @@ -11,7 +11,7 @@ email: # But gitosis wiil be deprecated & # some new features wont work with it git_host: - system: gitolite# or gitosis + system: gitolite admin_uri: git@localhost:gitolite-admin base_path: /home/git/repositories/ host: localhost diff --git a/lib/gitlabhq/git_host.rb b/lib/gitlabhq/git_host.rb index 48f5a150..714d92f5 100644 --- a/lib/gitlabhq/git_host.rb +++ b/lib/gitlabhq/git_host.rb @@ -4,10 +4,10 @@ require File.join(Rails.root, "lib", "gitlabhq", "gitosis") module Gitlabhq class GitHost def self.system - if GIT_HOST["system"] == "gitolite" - Gitlabhq::Gitolite - else + if GIT_HOST["system"] == "gitosis" Gitlabhq::Gitosis + else + Gitlabhq::Gitolite end end From bdc658095c6bc7e7a2a49447b404156f3f947fe1 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 5 Dec 2011 09:43:53 +0200 Subject: [PATCH 7/8] refcatoring. cleaning after gitosis --- app/controllers/application_controller.rb | 4 +- app/controllers/errors_controller.rb | 4 +- app/controllers/projects_controller.rb | 4 +- app/models/key.rb | 12 ++-- app/models/project.rb | 14 ++--- app/models/repository.rb | 12 ++-- app/models/users_project.rb | 6 +- config/routes.rb | 2 +- lib/gitlabhq/git_host.rb | 15 +++-- lib/gitlabhq/gitosis.rb | 76 ----------------------- lib/tasks/gitolite_rebuild.rake | 11 ++++ spec/models/project_spec.rb | 10 +-- spec/monkeypatch.rb | 12 ++-- 13 files changed, 58 insertions(+), 124 deletions(-) delete mode 100644 lib/gitlabhq/gitosis.rb create mode 100644 lib/tasks/gitolite_rebuild.rake diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1f971302..dd0c3c3e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,8 +3,8 @@ class ApplicationController < ActionController::Base protect_from_forgery helper_method :abilities, :can? - rescue_from Gitlabhq::Gitosis::AccessDenied, Gitlabhq::Gitolite::AccessDenied do |exception| - render :file => File.join(Rails.root, "public", "gitosis_error"), :layout => false + rescue_from Gitlabhq::Gitolite::AccessDenied do |exception| + render :file => File.join(Rails.root, "public", "githost_error"), :layout => false end layout :layout_by_resource diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb index c37f10a3..3ef7aa46 100644 --- a/app/controllers/errors_controller.rb +++ b/app/controllers/errors_controller.rb @@ -1,5 +1,5 @@ class ErrorsController < ApplicationController - def gitosis - render :file => File.join(Rails.root, "public", "gitosis_error"), :layout => false + def githost + render :file => File.join(Rails.root, "public", "githost_error"), :layout => false end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 4b8c196b..69a539c8 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -42,8 +42,8 @@ class ProjectsController < ApplicationController format.js end end - rescue Gitlabhq::Gitosis::AccessDenied, Gitlabhq::Gitolite::AccessDenied - render :js => "location.href = '#{errors_gitosis_path}'" and return + rescue Gitlabhq::Gitolite::AccessDenied + render :js => "location.href = '#{errors_githost_path}'" and return rescue StandardError => ex @project.errors.add(:base, "Cant save project. Please try again later") respond_to do |format| diff --git a/app/models/key.rb b/app/models/key.rb index 572f002b..e265842c 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -11,29 +11,29 @@ class Key < ActiveRecord::Base :length => { :within => 0..5000 } before_save :set_identifier - after_save :update_gitosis - after_destroy :gitosis_delete_key + after_save :update_repository + after_destroy :repository_delete_key def set_identifier self.identifier = "#{user.identifier}_#{Time.now.to_i}" end - def update_gitosis + def update_repository Gitlabhq::GitHost.system.new.configure do |c| c.update_keys(identifier, key) projects.each do |project| - c.update_project(project.path, project.gitosis_writers) + c.update_project(project.path, project.repository_writers) end end end - def gitosis_delete_key + def repository_delete_key Gitlabhq::GitHost.system.new.configure do |c| c.delete_key(identifier) projects.each do |project| - c.update_project(project.path, project.gitosis_writers) + c.update_project(project.path, project.repository_writers) end end end diff --git a/app/models/project.rb b/app/models/project.rb index f4841653..d78513d4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -40,8 +40,8 @@ class Project < ActiveRecord::Base validate :check_limit validate :repo_name - after_destroy :destroy_gitosis_project - after_save :update_gitosis_project + after_destroy :destroy_repository + after_save :update_repository attr_protected :private_flag, :owner_id @@ -54,8 +54,8 @@ class Project < ActiveRecord::Base delegate :repo, :url_to_repo, :path_to_repo, - :update_gitosis_project, - :destroy_gitosis_project, + :update_repository, + :destroy_repository, :tags, :repo_exists?, :commit, @@ -113,7 +113,7 @@ class Project < ActiveRecord::Base @writers ||= users_projects.includes(:user).where(:write => true).map(&:user) end - def gitosis_writers + def repository_writers keys = Key.joins({:user => :users_projects}).where("users_projects.project_id = ? AND users_projects.write = ?", id, true) keys.map(&:identifier) end @@ -184,8 +184,8 @@ class Project < ActiveRecord::Base end def repo_name - if path == "gitosis-admin" && path == "gitolite-admin" - errors.add(:path, " like 'gitosis-admin' is not allowed") + if path == "gitolite-admin" + errors.add(:path, " like 'gitolite-admin' is not allowed") end end diff --git a/app/models/repository.rb b/app/models/repository.rb index 1a1c90a6..71407195 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -24,24 +24,20 @@ class Repository end def url_to_repo - if !GIT_HOST["port"] or GIT_HOST["port"] == 22 - "#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{path}.git" - else - "ssh://#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{GIT_HOST["port"]}/#{path}.git" - end + Gitlabhq::GitHost.url_to_repo(path) end def path_to_repo GIT_HOST["base_path"] + path + ".git" end - def update_gitosis_project + def update_repository Gitlabhq::GitHost.system.new.configure do |c| - c.update_project(path, project.gitosis_writers) + c.update_project(path, project.repository_writers) end end - def destroy_gitosis_project + def destroy_repository Gitlabhq::GitHost.system.new.configure do |c| c.destroy_project(@project) end diff --git a/app/models/users_project.rb b/app/models/users_project.rb index 96e2d16a..9a114087 100644 --- a/app/models/users_project.rb +++ b/app/models/users_project.rb @@ -4,7 +4,7 @@ class UsersProject < ActiveRecord::Base attr_protected :project_id, :project - after_commit :update_gitosis_project + after_commit :update_repository validates_uniqueness_of :user_id, :scope => [:project_id] validates_presence_of :user_id @@ -13,9 +13,9 @@ class UsersProject < ActiveRecord::Base delegate :name, :email, :to => :user, :prefix => true - def update_gitosis_project + def update_repository Gitosis.new.configure do |c| - c.update_project(project.path, project.gitosis_writers) + c.update_project(project.path, project.repository) end end diff --git a/config/routes.rb b/config/routes.rb index c74cf226..ad8b0b31 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,7 +14,7 @@ Gitlab::Application.routes.draw do root :to => "users#index" end - get "errors/gitosis" + get "errors/githost" get "profile/password", :to => "profile#password" put "profile/password", :to => "profile#password_update" put "profile/reset_private_token", :to => "profile#reset_private_token" diff --git a/lib/gitlabhq/git_host.rb b/lib/gitlabhq/git_host.rb index 714d92f5..9a6eecb3 100644 --- a/lib/gitlabhq/git_host.rb +++ b/lib/gitlabhq/git_host.rb @@ -1,18 +1,21 @@ require File.join(Rails.root, "lib", "gitlabhq", "gitolite") -require File.join(Rails.root, "lib", "gitlabhq", "gitosis") module Gitlabhq class GitHost def self.system - if GIT_HOST["system"] == "gitosis" - Gitlabhq::Gitosis - else - Gitlabhq::Gitolite - end + Gitlabhq::Gitolite end def self.admin_uri GIT_HOST["admin_uri"] end + + def self.url_to_repo(path) + if !GIT_HOST["port"] or GIT_HOST["port"] == 22 + "#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{path}.git" + else + "ssh://#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{GIT_HOST["port"]}/#{path}.git" + end + end end end diff --git a/lib/gitlabhq/gitosis.rb b/lib/gitlabhq/gitosis.rb deleted file mode 100644 index a3dbcc80..00000000 --- a/lib/gitlabhq/gitosis.rb +++ /dev/null @@ -1,76 +0,0 @@ -require 'inifile' -require 'timeout' -require 'fileutils' - -module Gitlabhq - class Gitosis - class AccessDenied < StandardError; end - - def pull - # create tmp dir - @local_dir = File.join(Dir.tmpdir,"gitlabhq-gitosis-#{Time.now.to_i}") - - Dir.mkdir @local_dir - - `git clone #{GitHost.admin_uri} #{@local_dir}/gitosis` - end - - def push - Dir.chdir(File.join(@local_dir, "gitosis")) - `git add -A` - `git commit -am "Gitlab"` - `git push` - Dir.chdir(Rails.root) - - FileUtils.rm_rf(@local_dir) - end - - def configure - status = Timeout::timeout(20) do - File.open(File.join(Dir.tmpdir,"gitlabhq-gitosis.lock"), "w+") do |f| - begin - f.flock(File::LOCK_EX) - pull - yield(self) - push - ensure - f.flock(File::LOCK_UN) - end - end - end - rescue Exception => ex - raise Gitosis::AccessDenied.new("gitosis 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.delete_section("group #{project.path}") - - conf.write - end - - #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/,'')) } - 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` - end - - #update or create - def update_project(repo_name, name_writers) - # write config file - conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf')) - - conf["group #{repo_name}"]['writable'] = repo_name - conf["group #{repo_name}"]['members'] = name_writers.join(' ') - - conf.write - end - end -end diff --git a/lib/tasks/gitolite_rebuild.rake b/lib/tasks/gitolite_rebuild.rake new file mode 100644 index 00000000..5cf49619 --- /dev/null +++ b/lib/tasks/gitolite_rebuild.rake @@ -0,0 +1,11 @@ +desc "Rebuild each project at gitolite config" +task :gitolite_rebuild => :environment do + puts "Starting..." + Project.find_each(:batch_size => 100) do |project| + puts + puts "=== #{project.name}" + project.update_repository + puts + end + puts "Done" +end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index cde1884a..eda20a0c 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -18,12 +18,12 @@ describe Project do describe "Respond to" do it { should respond_to(:readers) } it { should respond_to(:writers) } - it { should respond_to(:gitosis_writers) } + it { should respond_to(:repository_writers) } it { should respond_to(:admins) } it { should respond_to(:add_access) } it { should respond_to(:reset_access) } - it { should respond_to(:update_gitosis_project) } - it { should respond_to(:destroy_gitosis_project) } + it { should respond_to(:update_repository) } + it { should respond_to(:destroy_repository) } it { should respond_to(:public?) } it { should respond_to(:private?) } it { should respond_to(:url_to_repo) } @@ -35,9 +35,9 @@ describe Project do it { should respond_to(:commit) } end - it "should not allow 'gitosis-admin' as repo name" do + it "should not allow 'gitolite-admin' as repo name" do should allow_value("blah").for(:path) - should_not allow_value("gitosis-admin").for(:path) + should_not allow_value("gitolite-admin").for(:path) end it "should return valid url to repo" do diff --git a/spec/monkeypatch.rb b/spec/monkeypatch.rb index 2e491496..75099e05 100644 --- a/spec/monkeypatch.rb +++ b/spec/monkeypatch.rb @@ -1,11 +1,11 @@ -# Stubbing Project <-> gitosis path +# Stubbing Project <-> git host path # create project using Factory only class Project - def update_gitosis_project + def update_repository true end - def update_gitosis + def update_repository true end @@ -15,17 +15,17 @@ class Project end class Key - def update_gitosis + def update_repository true end - def gitosis_delete_key + def repository_delete_key true end end class UsersProject - def update_gitosis_project + def update_repository true end end From 2d81f4880e7f27c0359d5d5b54822db2441ce6ea Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 5 Dec 2011 19:27:41 +0200 Subject: [PATCH 8/8] keys migrate --- lib/tasks/gitolite_rebuild.rake | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/tasks/gitolite_rebuild.rake b/lib/tasks/gitolite_rebuild.rake index 5cf49619..558d4660 100644 --- a/lib/tasks/gitolite_rebuild.rake +++ b/lib/tasks/gitolite_rebuild.rake @@ -1,11 +1,18 @@ desc "Rebuild each project at gitolite config" task :gitolite_rebuild => :environment do - puts "Starting..." + puts "Starting Projects" Project.find_each(:batch_size => 100) do |project| puts puts "=== #{project.name}" project.update_repository puts end - puts "Done" + puts "Done with projects" + + puts "Starting Key" + Key.find_each(:batch_size => 100) do |project| + project.update_repository + print '.' + end + puts "Done with keys" end