Commit 9e089efe5a2defa38cc94347a5051f1cfe91406b
1 parent
c03bc6e2
Exists in
master
and in
4 other branches
gitolite & gitosis support
Showing
14 changed files
with
200 additions
and
98 deletions
Show diff stats
app/controllers/application_controller.rb
| ... | ... | @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base |
| 3 | 3 | protect_from_forgery |
| 4 | 4 | helper_method :abilities, :can? |
| 5 | 5 | |
| 6 | - rescue_from Gitosis::AccessDenied do |exception| | |
| 6 | + rescue_from Gitlabhq::Gitosis::AccessDenied, Gitlabhq::Gitolite::AccessDenied do |exception| | |
| 7 | 7 | render :file => File.join(Rails.root, "public", "gitosis_error"), :layout => false |
| 8 | 8 | end |
| 9 | 9 | ... | ... |
app/controllers/projects_controller.rb
| ... | ... | @@ -42,7 +42,7 @@ class ProjectsController < ApplicationController |
| 42 | 42 | format.js |
| 43 | 43 | end |
| 44 | 44 | end |
| 45 | - rescue Gitosis::AccessDenied | |
| 45 | + rescue Gitlabhq::Gitosis::AccessDenied, Gitlabhq::Gitolite::AccessDenied | |
| 46 | 46 | render :js => "location.href = '#{errors_gitosis_path}'" and return |
| 47 | 47 | rescue StandardError => ex |
| 48 | 48 | @project.errors.add(:base, "Cant save project. Please try again later") | ... | ... |
app/models/key.rb
| ... | ... | @@ -19,7 +19,7 @@ class Key < ActiveRecord::Base |
| 19 | 19 | end |
| 20 | 20 | |
| 21 | 21 | def update_gitosis |
| 22 | - Gitosis.new.configure do |c| | |
| 22 | + GitoProxy.system.new.configure do |c| | |
| 23 | 23 | c.update_keys(identifier, key) |
| 24 | 24 | |
| 25 | 25 | projects.each do |project| |
| ... | ... | @@ -29,7 +29,7 @@ class Key < ActiveRecord::Base |
| 29 | 29 | end |
| 30 | 30 | |
| 31 | 31 | def gitosis_delete_key |
| 32 | - Gitosis.new.configure do |c| | |
| 32 | + GitoProxy.system.new.configure do |c| | |
| 33 | 33 | c.delete_key(identifier) |
| 34 | 34 | |
| 35 | 35 | projects.each do |project| | ... | ... |
app/models/repository.rb
| ... | ... | @@ -22,25 +22,25 @@ class Repository |
| 22 | 22 | end |
| 23 | 23 | |
| 24 | 24 | def url_to_repo |
| 25 | - if !GITOSIS["port"] or GITOSIS["port"] == 22 | |
| 26 | - "#{GITOSIS["git_user"]}@#{GITOSIS["host"]}:#{path}.git" | |
| 25 | + if !GIT_HOST["port"] or GIT_HOST["port"] == 22 | |
| 26 | + "#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{path}.git" | |
| 27 | 27 | else |
| 28 | - "ssh://#{GITOSIS["git_user"]}@#{GITOSIS["host"]}:#{GITOSIS["port"]}/#{path}.git" | |
| 28 | + "ssh://#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{GIT_HOST["port"]}/#{path}.git" | |
| 29 | 29 | end |
| 30 | 30 | end |
| 31 | 31 | |
| 32 | 32 | def path_to_repo |
| 33 | - GITOSIS["base_path"] + path + ".git" | |
| 33 | + GIT_HOST["base_path"] + path + ".git" | |
| 34 | 34 | end |
| 35 | 35 | |
| 36 | 36 | def update_gitosis_project |
| 37 | - Gitosis.new.configure do |c| | |
| 37 | + GitProxy.system.new.configure do |c| | |
| 38 | 38 | c.update_project(path, project.gitosis_writers) |
| 39 | 39 | end |
| 40 | 40 | end |
| 41 | 41 | |
| 42 | 42 | def destroy_gitosis_project |
| 43 | - Gitosis.new.configure do |c| | |
| 43 | + GitProxy.system.new.configure do |c| | |
| 44 | 44 | c.destroy_project(@project) |
| 45 | 45 | end |
| 46 | 46 | end | ... | ... |
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
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"] | ... | ... |
| ... | ... | @@ -0,0 +1,18 @@ |
| 1 | +require File.join(Rails.root, "lib", "gitlabhq", "gitolite") | |
| 2 | +require File.join(Rails.root, "lib", "gitlabhq", "gitosis") | |
| 3 | + | |
| 4 | +module Gitlabhq | |
| 5 | + class GitHost | |
| 6 | + def self.system | |
| 7 | + if GIT_HOST["system"] == "gitolite" | |
| 8 | + Gitlabhq::Gitolite | |
| 9 | + else | |
| 10 | + Gitlabhq::Gitosis | |
| 11 | + end | |
| 12 | + end | |
| 13 | + | |
| 14 | + def self.admin_uri | |
| 15 | + GIT_HOST["admin_uri"] | |
| 16 | + end | |
| 17 | + end | |
| 18 | +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 | ... | ... |
| ... | ... | @@ -0,0 +1,76 @@ |
| 1 | +require 'inifile' | |
| 2 | +require 'timeout' | |
| 3 | +require 'fileutils' | |
| 4 | + | |
| 5 | +module Gitlabhq | |
| 6 | + class Gitosis | |
| 7 | + class AccessDenied < StandardError; end | |
| 8 | + | |
| 9 | + def pull | |
| 10 | + # create tmp dir | |
| 11 | + @local_dir = File.join(Dir.tmpdir,"gitlabhq-gitosis-#{Time.now.to_i}") | |
| 12 | + | |
| 13 | + Dir.mkdir @local_dir | |
| 14 | + | |
| 15 | + `git clone #{GitHost.admin_uri} #{@local_dir}/gitosis` | |
| 16 | + end | |
| 17 | + | |
| 18 | + def push | |
| 19 | + Dir.chdir(File.join(@local_dir, "gitosis")) | |
| 20 | + `git add -A` | |
| 21 | + `git commit -am "Gitlab"` | |
| 22 | + `git push` | |
| 23 | + Dir.chdir(Rails.root) | |
| 24 | + | |
| 25 | + FileUtils.rm_rf(@local_dir) | |
| 26 | + end | |
| 27 | + | |
| 28 | + def configure | |
| 29 | + status = Timeout::timeout(20) do | |
| 30 | + File.open(File.join(Dir.tmpdir,"gitlabhq-gitosis.lock"), "w+") do |f| | |
| 31 | + begin | |
| 32 | + f.flock(File::LOCK_EX) | |
| 33 | + pull | |
| 34 | + yield(self) | |
| 35 | + push | |
| 36 | + ensure | |
| 37 | + f.flock(File::LOCK_UN) | |
| 38 | + end | |
| 39 | + end | |
| 40 | + end | |
| 41 | + rescue Exception => ex | |
| 42 | + raise Gitosis::AccessDenied.new("gitosis timeout") | |
| 43 | + end | |
| 44 | + | |
| 45 | + def destroy_project(project) | |
| 46 | + `sudo -u git rm -rf #{project.path_to_repo}` | |
| 47 | + | |
| 48 | + conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf')) | |
| 49 | + | |
| 50 | + conf.delete_section("group #{project.path}") | |
| 51 | + | |
| 52 | + conf.write | |
| 53 | + end | |
| 54 | + | |
| 55 | + #update or create | |
| 56 | + def update_keys(user, key) | |
| 57 | + File.open(File.join(@local_dir, 'gitosis/keydir',"#{user}.pub"), 'w') {|f| f.write(key.gsub(/\n/,'')) } | |
| 58 | + end | |
| 59 | + | |
| 60 | + def delete_key(user) | |
| 61 | + File.unlink(File.join(@local_dir, 'gitosis/keydir',"#{user}.pub")) | |
| 62 | + `cd #{File.join(@local_dir,'gitosis')} ; git rm keydir/#{user}.pub` | |
| 63 | + end | |
| 64 | + | |
| 65 | + #update or create | |
| 66 | + def update_project(repo_name, name_writers) | |
| 67 | + # write config file | |
| 68 | + conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf')) | |
| 69 | + | |
| 70 | + conf["group #{repo_name}"]['writable'] = repo_name | |
| 71 | + conf["group #{repo_name}"]['members'] = name_writers.join(' ') | |
| 72 | + | |
| 73 | + conf.write | |
| 74 | + end | |
| 75 | + end | |
| 76 | +end | ... | ... |
lib/gitosis.rb
| ... | ... | @@ -1,83 +0,0 @@ |
| 1 | -require 'gitolite' | |
| 2 | - | |
| 3 | -require 'inifile' | |
| 4 | -require 'timeout' | |
| 5 | -require 'fileutils' | |
| 6 | - | |
| 7 | -class Gitosis | |
| 8 | - class AccessDenied < StandardError; end | |
| 9 | - | |
| 10 | - def pull | |
| 11 | - # create tmp dir | |
| 12 | - @local_dir = File.join(Dir.tmpdir,"gitlabhq-gitolite-#{Time.now.to_i}") | |
| 13 | - | |
| 14 | - Dir.mkdir @local_dir | |
| 15 | - | |
| 16 | - `git clone #{GITOSIS['admin_uri']} #{@local_dir}/gitolite` | |
| 17 | - end | |
| 18 | - | |
| 19 | - def push | |
| 20 | - Dir.chdir(File.join(@local_dir, "gitolite")) | |
| 21 | - `git add -A` | |
| 22 | - `git commit -am "Gitlab"` | |
| 23 | - `git push` | |
| 24 | - Dir.chdir(Rails.root) | |
| 25 | - | |
| 26 | - FileUtils.rm_rf(@local_dir) | |
| 27 | - end | |
| 28 | - | |
| 29 | - def configure | |
| 30 | - status = Timeout::timeout(20) do | |
| 31 | - File.open(File.join(Dir.tmpdir,"gitlabhq-gitolite.lock"), "w+") do |f| | |
| 32 | - begin | |
| 33 | - f.flock(File::LOCK_EX) | |
| 34 | - pull | |
| 35 | - yield(self) | |
| 36 | - push | |
| 37 | - ensure | |
| 38 | - f.flock(File::LOCK_UN) | |
| 39 | - end | |
| 40 | - end | |
| 41 | - end | |
| 42 | - #rescue Exception => ex | |
| 43 | - #raise Gitosis::AccessDenied.new("gitolite timeout") | |
| 44 | - end | |
| 45 | - | |
| 46 | - def destroy_project(project) | |
| 47 | - `sudo -u git rm -rf #{project.path_to_repo}` | |
| 48 | - | |
| 49 | - conf = IniFile.new(File.join(@local_dir,'gitolite', 'conf', 'gitolite.conf')) | |
| 50 | - | |
| 51 | - conf.delete_section("group #{project.path}") | |
| 52 | - | |
| 53 | - conf.write | |
| 54 | - end | |
| 55 | - | |
| 56 | - #update or create | |
| 57 | - def update_keys(user, key) | |
| 58 | - File.open(File.join(@local_dir, 'gitolite/keydir',"#{user}.pub"), 'w') {|f| f.write(key.gsub(/\n/,'')) } | |
| 59 | - end | |
| 60 | - | |
| 61 | - def delete_key(user) | |
| 62 | - File.unlink(File.join(@local_dir, 'gitolite/keydir',"#{user}.pub")) | |
| 63 | - `cd #{File.join(@local_dir,'gitolite')} ; git rm keydir/#{user}.pub` | |
| 64 | - end | |
| 65 | - | |
| 66 | - #update or create | |
| 67 | - def update_project(repo_name, name_writers) | |
| 68 | - ga_repo = Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite')) | |
| 69 | - conf = ga_repo.config | |
| 70 | - | |
| 71 | - repo = if conf.has_repo?(repo_name) | |
| 72 | - conf.get_repo(repo_name) | |
| 73 | - else | |
| 74 | - Gitolite::Config::Repo.new(repo_name) | |
| 75 | - end | |
| 76 | - | |
| 77 | - repo.add_permission("RW+", "", name_writers) unless name_writers.blank? | |
| 78 | - | |
| 79 | - conf.add_repo(repo) | |
| 80 | - | |
| 81 | - ga_repo.save | |
| 82 | - end | |
| 83 | -end |