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 | 8 | class PushError < StandardError; end |
| 9 | 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 | 16 | end |
| 16 | 17 | |
| 17 | 18 | def ga_repo |
| ... | ... | @@ -23,7 +24,7 @@ module Gitlab |
| 23 | 24 | |
| 24 | 25 | def apply |
| 25 | 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 | 28 | begin |
| 28 | 29 | # Set exclusive lock |
| 29 | 30 | # to prevent race condition |
| ... | ... | @@ -31,7 +32,7 @@ module Gitlab |
| 31 | 32 | |
| 32 | 33 | # Pull gitolite-admin repo |
| 33 | 34 | # in tmp dir before do any changes |
| 34 | - pull(config_tmp_dir) | |
| 35 | + pull | |
| 35 | 36 | |
| 36 | 37 | # Build ga_repo object and @conf |
| 37 | 38 | # to access gitolite-admin configuration |
| ... | ... | @@ -49,7 +50,7 @@ module Gitlab |
| 49 | 50 | |
| 50 | 51 | # Push gitolite-admin repo |
| 51 | 52 | # to apply all changes |
| 52 | - push(config_tmp_dir) | |
| 53 | + push | |
| 53 | 54 | ensure |
| 54 | 55 | # Remove tmp dir |
| 55 | 56 | # removing the gitolite folder first is important to avoid |
| ... | ... | @@ -192,16 +193,20 @@ module Gitlab |
| 192 | 193 | |
| 193 | 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 | 205 | raise PullError, "unable to clone gitolite-admin repo" |
| 201 | 206 | end |
| 202 | 207 | end |
| 203 | 208 | |
| 204 | - def push tmp_dir | |
| 209 | + def push | |
| 205 | 210 | output, status = popen('git add -A') |
| 206 | 211 | raise "Git add failed." unless status.zero? |
| 207 | 212 | |
| ... | ... | @@ -222,8 +227,8 @@ module Gitlab |
| 222 | 227 | end |
| 223 | 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 | 232 | vars = { "PWD" => path } |
| 228 | 233 | options = { :chdir => path } |
| 229 | 234 | |
| ... | ... | @@ -239,4 +244,3 @@ module Gitlab |
| 239 | 244 | end |
| 240 | 245 | end |
| 241 | 246 | end |
| 242 | - | ... | ... |