diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2011-12-04 01:44:59 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2011-12-04 01:44:59 +0200 |
commit | 9e089efe5a2defa38cc94347a5051f1cfe91406b (patch) | |
tree | 8ea64f85e9064ab074e2c4e4af3a273ca91178b9 /lib | |
parent | c03bc6e2912b2e63a352e1f7e664b32a95aa9cad (diff) | |
download | gitlab-ce-9e089efe5a2defa38cc94347a5051f1cfe91406b.tar.gz |
gitolite & gitosis support
Diffstat (limited to 'lib')
-rw-r--r-- | lib/.directory | 5 | ||||
-rw-r--r-- | lib/gitlabhq/.directory | 5 | ||||
-rw-r--r-- | lib/gitlabhq/git_host.rb | 18 | ||||
-rw-r--r-- | lib/gitlabhq/gitolite.rb | 80 | ||||
-rw-r--r-- | lib/gitlabhq/gitosis.rb | 76 | ||||
-rw-r--r-- | lib/gitosis.rb | 83 |
6 files changed, 184 insertions, 83 deletions
diff --git a/lib/.directory b/lib/.directory new file mode 100644 index 00000000000..c0d0b18ff56 --- /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 00000000000..fcaf533bacc --- /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 00000000000..48f5a150740 --- /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 00000000000..de8241fe13a --- /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 00000000000..a3dbcc80b22 --- /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 6aa32849fc3..00000000000 --- 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 |