Commit 54a24608a29d113f0c607027cddd8b6947c6a55c

Authored by Dmitriy Zaporozhets
1 parent cfe89832

Remove chdir inside runtime. Improved gitolite shell commands

Gemfile
... ... @@ -127,6 +127,9 @@ group :development do
127 127  
128 128 # Docs generator
129 129 gem "sdoc"
  130 +
  131 + # thin instead webrick
  132 + gem 'thin'
130 133 end
131 134  
132 135 group :development, :test do
... ...
Gemfile.lock
... ... @@ -144,6 +144,7 @@ GEM
144 144 colorize (0.5.8)
145 145 connection_pool (1.0.0)
146 146 crack (0.3.1)
  147 + daemons (1.1.9)
147 148 devise (2.1.2)
148 149 bcrypt-ruby (~> 3.0)
149 150 orm_adapter (~> 0.1)
... ... @@ -436,6 +437,10 @@ GEM
436 437 test_after_commit (0.0.1)
437 438 therubyracer (0.10.2)
438 439 libv8 (~> 3.3.10)
  440 + thin (1.5.0)
  441 + daemons (>= 1.0.9)
  442 + eventmachine (>= 0.12.6)
  443 + rack (>= 1.0.0)
439 444 thor (0.16.0)
440 445 tilt (1.3.3)
441 446 timers (1.0.2)
... ... @@ -542,6 +547,7 @@ DEPENDENCIES
542 547 stamp
543 548 test_after_commit
544 549 therubyracer
  550 + thin
545 551 uglifier (~> 1.3.0)
546 552 unicorn (~> 4.4.0)
547 553 webmock
... ...
lib/gitlab/backend/gitolite_config.rb
... ... @@ -77,9 +77,9 @@ module Gitlab
77 77 log("Gitolite error -> " + " " + ex.message)
78 78 raise Gitolite::AccessDenied, ex.message
79 79  
80   - rescue Exception => ex
81   - log(ex.class.name + " " + ex.message)
82   - raise Gitolite::AccessDenied.new("gitolite timeout")
  80 + #rescue Exception => ex
  81 + #log(ex.class.name + " " + ex.message)
  82 + #raise Gitolite::AccessDenied.new("gitolite timeout")
83 83 end
84 84  
85 85 def log message
... ... @@ -202,25 +202,41 @@ module Gitlab
202 202 end
203 203  
204 204 def push tmp_dir
205   - Dir.chdir(File.join(tmp_dir, "gitolite"))
206   - raise "Git add failed." unless system('git add -A')
207   - system('git commit -m "GitLab"') # git commit returns 0 on success, and 1 if there is nothing to commit
208   - raise "Git commit failed." unless [0,1].include? $?.exitstatus
  205 + output, status = popen('git add -A')
  206 + raise "Git add failed." unless status.zero?
209 207  
210   - stdin, stdout, stderr = Open3.popen3('git push')
211   - push_output = stderr.read
212   - push_status = $?.to_i
  208 + # git commit returns 0 on success, and 1 if there is nothing to commit
  209 + output, status = popen('git commit -m "GitLab"')
  210 + raise "Git add failed." unless [0,1].include?(status)
213 211  
214   - if push_output =~ /remote\: FATAL/
215   - raise BrokenGitolite, push_output
  212 + output, status = popen('git push')
  213 +
  214 + if output =~ /remote\: FATAL/
  215 + raise BrokenGitolite, output
216 216 end
217 217  
218   - if push_status.zero?
219   - Dir.chdir(Rails.root)
  218 + if status.zero? || output =~ /Everything up\-to\-date/
  219 + return true
220 220 else
221 221 raise PushError, "unable to push gitolite-admin repo"
222 222 end
223 223 end
  224 +
  225 + def popen(cmd)
  226 + path = File.join(config_tmp_dir,'gitolite')
  227 + vars = { "PWD" => path }
  228 + options = { :chdir => path }
  229 +
  230 + @cmd_output = ""
  231 + @cmd_status = 0
  232 + Open3.popen3(vars, cmd, options) do |stdin, stdout, stderr, wait_thr|
  233 + @cmd_status = wait_thr.value.exitstatus
  234 + @cmd_output << stdout.read
  235 + @cmd_output << stderr.read
  236 + end
  237 +
  238 + return @cmd_output, @cmd_status
  239 + end
224 240 end
225 241 end
226 242  
... ...