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/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/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b37deafd..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 Gitosis::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 @@ -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/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 717f8595..69a539c8 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 @@ -42,8 +42,8 @@ class ProjectsController < ApplicationController format.js end end - rescue Gitosis::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| @@ -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 fab732e2..d2be5ad5 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]) @@ -51,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 8231c30c..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 - Gitosis.new.configure do |c| + 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 - Gitosis.new.configure do |c| + 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 ae63efb6..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, @@ -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) } @@ -109,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 @@ -180,8 +184,8 @@ class Project < ActiveRecord::Base end def repo_name - if path == "gitosis-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 b87a1fba..71407195 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 @@ -22,25 +24,21 @@ class Repository end def url_to_repo - if !GITOSIS["port"] or GITOSIS["port"] == 22 - "#{GITOSIS["git_user"]}@#{GITOSIS["host"]}:#{path}.git" - else - "ssh://#{GITOSIS["git_user"]}@#{GITOSIS["host"]}:#{GITOSIS["port"]}/#{path}.git" - end + Gitlabhq::GitHost.url_to_repo(path) 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| - c.update_project(path, project.gitosis_writers) + def update_repository + Gitlabhq::GitHost.system.new.configure do |c| + c.update_project(path, project.repository_writers) end end - def destroy_gitosis_project - Gitosis.new.configure do |c| + def destroy_repository + Gitlabhq::GitHost.system.new.configure do |c| c.destroy_project(@project) end 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/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 caa26ad2..e861031e 100644 --- a/config/gitlab.yml +++ b/config/gitlab.yml @@ -6,9 +6,13 @@ email: from: notify@gitlabhq.com host: gitlabhq.com -# Gitosis congiguration -gitosis: - admin_uri: git@localhost:gitosis-admin.git +# 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 + admin_uri: git@localhost:gitolite-admin base_path: /home/git/repositories/ host: localhost git_user: git 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/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/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..2ba8e18f --- /dev/null +++ b/db/fixtures/development/004_teams.rb @@ -0,0 +1,21 @@ +UsersProject.seed(:id, [ + { :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, :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, :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 } +]) + + 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..9a6eecb3 --- /dev/null +++ b/lib/gitlabhq/git_host.rb @@ -0,0 +1,21 @@ +require File.join(Rails.root, "lib", "gitlabhq", "gitolite") + +module Gitlabhq + class GitHost + def self.system + 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/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/gitosis.rb b/lib/gitosis.rb deleted file mode 100644 index 92d32d8b..00000000 --- a/lib/gitosis.rb +++ /dev/null @@ -1,74 +0,0 @@ -require 'inifile' -require 'timeout' -require 'fileutils' - -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 #{GITOSIS['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 diff --git a/lib/tasks/gitolite_rebuild.rake b/lib/tasks/gitolite_rebuild.rake new file mode 100644 index 00000000..558d4660 --- /dev/null +++ b/lib/tasks/gitolite_rebuild.rake @@ -0,0 +1,18 @@ +desc "Rebuild each project at gitolite config" +task :gitolite_rebuild => :environment do + puts "Starting Projects" + Project.find_each(:batch_size => 100) do |project| + puts + puts "=== #{project.name}" + project.update_repository + puts + end + 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 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