From 54a24608a29d113f0c607027cddd8b6947c6a55c Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 19 Jan 2013 13:56:55 +0200 Subject: [PATCH] Remove chdir inside runtime. Improved gitolite shell commands --- Gemfile | 3 ++ Gemfile.lock | 6 ++++ lib/gitlab/backend/gitolite_config.rb | 44 ++++++++++++++++++--------- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index 87f45e59..96b5bb6a 100644 --- a/Gemfile +++ b/Gemfile @@ -127,6 +127,9 @@ group :development do # Docs generator gem "sdoc" + + # thin instead webrick + gem 'thin' end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 666f0d08..7bf31c95 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -144,6 +144,7 @@ GEM colorize (0.5.8) connection_pool (1.0.0) crack (0.3.1) + daemons (1.1.9) devise (2.1.2) bcrypt-ruby (~> 3.0) orm_adapter (~> 0.1) @@ -436,6 +437,10 @@ GEM test_after_commit (0.0.1) therubyracer (0.10.2) libv8 (~> 3.3.10) + thin (1.5.0) + daemons (>= 1.0.9) + eventmachine (>= 0.12.6) + rack (>= 1.0.0) thor (0.16.0) tilt (1.3.3) timers (1.0.2) @@ -542,6 +547,7 @@ DEPENDENCIES stamp test_after_commit therubyracer + thin uglifier (~> 1.3.0) unicorn (~> 4.4.0) webmock diff --git a/lib/gitlab/backend/gitolite_config.rb b/lib/gitlab/backend/gitolite_config.rb index 720ef8d2..35e87c09 100644 --- a/lib/gitlab/backend/gitolite_config.rb +++ b/lib/gitlab/backend/gitolite_config.rb @@ -77,9 +77,9 @@ module Gitlab log("Gitolite error -> " + " " + ex.message) raise Gitolite::AccessDenied, ex.message - rescue Exception => ex - log(ex.class.name + " " + ex.message) - raise Gitolite::AccessDenied.new("gitolite timeout") + #rescue Exception => ex + #log(ex.class.name + " " + ex.message) + #raise Gitolite::AccessDenied.new("gitolite timeout") end def log message @@ -202,25 +202,41 @@ module Gitlab end def push tmp_dir - Dir.chdir(File.join(tmp_dir, "gitolite")) - raise "Git add failed." unless system('git add -A') - system('git commit -m "GitLab"') # git commit returns 0 on success, and 1 if there is nothing to commit - raise "Git commit failed." unless [0,1].include? $?.exitstatus + output, status = popen('git add -A') + raise "Git add failed." unless status.zero? - stdin, stdout, stderr = Open3.popen3('git push') - push_output = stderr.read - push_status = $?.to_i + # git commit returns 0 on success, and 1 if there is nothing to commit + output, status = popen('git commit -m "GitLab"') + raise "Git add failed." unless [0,1].include?(status) - if push_output =~ /remote\: FATAL/ - raise BrokenGitolite, push_output + output, status = popen('git push') + + if output =~ /remote\: FATAL/ + raise BrokenGitolite, output end - if push_status.zero? - Dir.chdir(Rails.root) + if status.zero? || output =~ /Everything up\-to\-date/ + return true else raise PushError, "unable to push gitolite-admin repo" end end + + def popen(cmd) + path = File.join(config_tmp_dir,'gitolite') + vars = { "PWD" => path } + options = { :chdir => path } + + @cmd_output = "" + @cmd_status = 0 + Open3.popen3(vars, cmd, options) do |stdin, stdout, stderr, wait_thr| + @cmd_status = wait_thr.value.exitstatus + @cmd_output << stdout.read + @cmd_output << stderr.read + end + + return @cmd_output, @cmd_status + end end end