Commit d770714578cffe5423c6a1752367f7f545fa1f22
1 parent
68fa9882
Exists in
master
and in
4 other branches
Use subproccess instead subshell for git calls
Showing
1 changed file
with
18 additions
and
14 deletions
Show diff stats
lib/gitlab/backend/gitolite_config.rb
| @@ -8,10 +8,11 @@ module Gitlab | @@ -8,10 +8,11 @@ module Gitlab | ||
| 8 | class PushError < StandardError; end | 8 | class PushError < StandardError; end |
| 9 | class BrokenGitolite < StandardError; end | 9 | class BrokenGitolite < StandardError; end |
| 10 | 10 | ||
| 11 | - attr_reader :config_tmp_dir, :ga_repo, :conf | 11 | + attr_reader :config_tmp_dir, :tmp_dir, :ga_repo, :conf |
| 12 | 12 | ||
| 13 | - def config_tmp_dir | ||
| 14 | - @config_tmp_dir ||= Rails.root.join('tmp',"gitlabhq-gitolite-#{Time.now.to_i}") | 13 | + def initialize |
| 14 | + @tmp_dir = Rails.root.join("tmp").to_s | ||
| 15 | + @config_tmp_dir = File.join(@tmp_dir,"gitlabhq-gitolite-#{Time.now.to_i}") | ||
| 15 | end | 16 | end |
| 16 | 17 | ||
| 17 | def ga_repo | 18 | def ga_repo |
| @@ -23,7 +24,7 @@ module Gitlab | @@ -23,7 +24,7 @@ module Gitlab | ||
| 23 | 24 | ||
| 24 | def apply | 25 | def apply |
| 25 | Timeout::timeout(30) do | 26 | Timeout::timeout(30) do |
| 26 | - File.open(Rails.root.join('tmp', "gitlabhq-gitolite.lock"), "w+") do |f| | 27 | + File.open(File.join(tmp_dir, "gitlabhq-gitolite.lock"), "w+") do |f| |
| 27 | begin | 28 | begin |
| 28 | # Set exclusive lock | 29 | # Set exclusive lock |
| 29 | # to prevent race condition | 30 | # to prevent race condition |
| @@ -31,7 +32,7 @@ module Gitlab | @@ -31,7 +32,7 @@ module Gitlab | ||
| 31 | 32 | ||
| 32 | # Pull gitolite-admin repo | 33 | # Pull gitolite-admin repo |
| 33 | # in tmp dir before do any changes | 34 | # in tmp dir before do any changes |
| 34 | - pull(config_tmp_dir) | 35 | + pull |
| 35 | 36 | ||
| 36 | # Build ga_repo object and @conf | 37 | # Build ga_repo object and @conf |
| 37 | # to access gitolite-admin configuration | 38 | # to access gitolite-admin configuration |
| @@ -49,7 +50,7 @@ module Gitlab | @@ -49,7 +50,7 @@ module Gitlab | ||
| 49 | 50 | ||
| 50 | # Push gitolite-admin repo | 51 | # Push gitolite-admin repo |
| 51 | # to apply all changes | 52 | # to apply all changes |
| 52 | - push(config_tmp_dir) | 53 | + push |
| 53 | ensure | 54 | ensure |
| 54 | # Remove tmp dir | 55 | # Remove tmp dir |
| 55 | # removing the gitolite folder first is important to avoid | 56 | # removing the gitolite folder first is important to avoid |
| @@ -192,16 +193,20 @@ module Gitlab | @@ -192,16 +193,20 @@ module Gitlab | ||
| 192 | 193 | ||
| 193 | private | 194 | private |
| 194 | 195 | ||
| 195 | - def pull tmp_dir | ||
| 196 | - Dir.mkdir tmp_dir | ||
| 197 | - `git clone #{Gitlab.config.gitolite.admin_uri} #{tmp_dir}/gitolite` | 196 | + def pull |
| 197 | + # Create config tmp dir like "RAILS_ROOT/tmp/gitlabhq-gitolite-132545" | ||
| 198 | + Dir.mkdir config_tmp_dir | ||
| 198 | 199 | ||
| 199 | - unless File.exists?(File.join(tmp_dir, 'gitolite', 'conf', 'gitolite.conf')) | 200 | + # Clone gitolite-admin repo into tmp dir |
| 201 | + popen("git clone #{Gitlab.config.gitolite.admin_uri} #{config_tmp_dir}/gitolite", tmp_dir) | ||
| 202 | + | ||
| 203 | + # Ensure file with config presents after cloning | ||
| 204 | + unless File.exists?(File.join(config_tmp_dir, 'gitolite', 'conf', 'gitolite.conf')) | ||
| 200 | raise PullError, "unable to clone gitolite-admin repo" | 205 | raise PullError, "unable to clone gitolite-admin repo" |
| 201 | end | 206 | end |
| 202 | end | 207 | end |
| 203 | 208 | ||
| 204 | - def push tmp_dir | 209 | + def push |
| 205 | output, status = popen('git add -A') | 210 | output, status = popen('git add -A') |
| 206 | raise "Git add failed." unless status.zero? | 211 | raise "Git add failed." unless status.zero? |
| 207 | 212 | ||
| @@ -222,8 +227,8 @@ module Gitlab | @@ -222,8 +227,8 @@ module Gitlab | ||
| 222 | end | 227 | end |
| 223 | end | 228 | end |
| 224 | 229 | ||
| 225 | - def popen(cmd) | ||
| 226 | - path = File.join(config_tmp_dir,'gitolite') | 230 | + def popen(cmd, path = nil) |
| 231 | + path ||= File.join(config_tmp_dir,'gitolite') | ||
| 227 | vars = { "PWD" => path } | 232 | vars = { "PWD" => path } |
| 228 | options = { :chdir => path } | 233 | options = { :chdir => path } |
| 229 | 234 | ||
| @@ -239,4 +244,3 @@ module Gitlab | @@ -239,4 +244,3 @@ module Gitlab | ||
| 239 | end | 244 | end |
| 240 | end | 245 | end |
| 241 | end | 246 | end |
| 242 | - |