gitolite & gitosis support
This commit is contained in:
parent
c03bc6e291
commit
9e089efe5a
|
@ -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
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"]
|
||||
|
|
5
lib/.directory
Normal file
5
lib/.directory
Normal file
|
@ -0,0 +1,5 @@
|
|||
[Dolphin]
|
||||
AdditionalInfoV2=Details_Size,Details_Date,CustomizedDetails
|
||||
Timestamp=2011,12,4,1,34,13
|
||||
Version=2
|
||||
ViewMode=1
|
5
lib/gitlabhq/.directory
Normal file
5
lib/gitlabhq/.directory
Normal file
|
@ -0,0 +1,5 @@
|
|||
[Dolphin]
|
||||
AdditionalInfoV2=Details_Size,Details_Date,CustomizedDetails
|
||||
Timestamp=2011,12,4,1,34,17
|
||||
Version=2
|
||||
ViewMode=1
|
18
lib/gitlabhq/git_host.rb
Normal file
18
lib/gitlabhq/git_host.rb
Normal file
|
@ -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
|
80
lib/gitlabhq/gitolite.rb
Normal file
80
lib/gitlabhq/gitolite.rb
Normal file
|
@ -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
|
76
lib/gitlabhq/gitosis.rb
Normal file
76
lib/gitlabhq/gitosis.rb
Normal file
|
@ -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
|
|
@ -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
|
Loading…
Reference in a new issue