diff --git a/Gemfile b/Gemfile index 86bd5b208..fdbdf0bdf 100644 --- a/Gemfile +++ b/Gemfile @@ -30,6 +30,7 @@ gem 'resque-web', '>= 0.0.6', require: 'resque_web' gem 'json' # used by resque gem 'chunky_png' +gem 'posix-spawn' # used by cocaine gem 'cocaine' gem 'awesome_print', require: false gem 'nokogiri' diff --git a/Gemfile.lock b/Gemfile.lock index 0f19b7677..f5cdc8bc7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -68,7 +68,7 @@ GEM chunky_png (1.2.9) climate_control (0.0.3) activesupport (>= 3.0) - cocaine (0.5.3) + cocaine (0.5.4) climate_control (>= 0.0.3, < 1.0) coderay (1.1.0) coffee-rails (4.0.1) @@ -145,6 +145,7 @@ GEM rack rake (>= 0.8.1) polyglot (0.3.4) + posix-spawn (0.3.8) pry (0.9.12.6) coderay (~> 1.0) method_source (~> 0.8) @@ -312,6 +313,7 @@ DEPENDENCIES mysql2 nokogiri passenger (~> 4.0.41) + posix-spawn pry-byebug pry-rails quiet_assets diff --git a/lib/git_repo.rb b/lib/git_repo.rb index d9a1eefc3..96b5a9481 100644 --- a/lib/git_repo.rb +++ b/lib/git_repo.rb @@ -14,35 +14,37 @@ def inside_copy(repository, sha, branch = "master") Dir.mktmpdir(nil, WORKING_DIR) do |dir| # clone local repo (fast!) - run! "git clone #{cached_repo_path} #{dir}" + Cocaine::CommandLine.new("git clone", "#{cached_repo_path} #{dir}").run Dir.chdir(dir) do raise RefNotFoundError, "repo:#{repository.url} branch:#{branch}, sha:#{sha}" unless system("git rev-list --quiet -n1 #{sha}") - run! "git checkout --quiet #{sha}" + Cocaine::CommandLine.new("git checkout", "--quiet :commit").run(commit: sha) - run! "git submodule --quiet init" + if File.exists?('.gitmodules') + Cocaine::CommandLine.new("git submodule", "--quiet init").run + submodules = Cocaine::CommandLine.new('git config', '--get-regexp "^submodule\\..*\\.url$"').run - submodules = `git config --get-regexp "^submodule\\..*\\.url$"` - - unless submodules.empty? - cached_submodules = nil - inside_repo(repository, sync: false) do - cached_submodules = `git config --get-regexp "^submodule\\..*\\.url$"` - end + unless submodules.empty? + cached_submodules = nil + inside_repo(repository, sync: false) do + cached_submodules = Cocaine::CommandLine.new('git config', '--get-regexp "^submodule\\..*\\.url$"').run + end - # Redirect the submodules to the cached_repo - # If the submodule was added after the initial clone of the cache - # repo then it will not be present in the cached_repo and we fall - # back to cloning it for each build. - submodules.each_line do |config_line| - if cached_submodules.include?(config_line) - submodule_path = config_line.match(/submodule\.(.*?)\.url/)[1] - `git config --replace-all submodule.#{submodule_path}.url "#{cached_repo_path}/#{submodule_path}"` + # Redirect the submodules to the cached_repo + # If the submodule was added after the initial clone of the cache + # repo then it will not be present in the cached_repo and we fall + # back to cloning it for each build. + submodules.each_line do |config_line| + if cached_submodules.include?(config_line) + submodule_path = config_line.match(/submodule\.(.*?)\.url/)[1] + Cocaine::CommandLine.new("git config", + "--replace-all submodule.#{submodule_path}.url '#{cached_repo_path}/#{submodule_path}'").run + end end - end - run! "git submodule --quiet update" + Cocaine::CommandLine.new('git submodule', '--quiet update').run + end end yield dir @@ -84,10 +86,10 @@ def cached_repo_for(repository) def harmonize_remote_url(cached_repo_path, expected_url) Dir.chdir(cached_repo_path) do - remote_url = Cocaine::CommandLine.new("git config --get remote.origin.url").run.chomp + remote_url = Cocaine::CommandLine.new("git config", "--get remote.origin.url").run.chomp if remote_url != expected_url Rails.logger.info "#{remote_url.inspect} does not match #{expected_url.inspect}. Updating it." - Cocaine::CommandLine.new("git remote set-url origin #{expected_url}").run + Cocaine::CommandLine.new("git remote", "set-url origin #{expected_url}").run end end nil @@ -97,13 +99,7 @@ def synchronize_cache_repo(cached_repo_path, branch) Dir.chdir(cached_repo_path) do # update the cached repo synchronize_with_remote('origin', branch) - Cocaine::CommandLine.new("git submodule update", "--init --quiet").run - end - end - - def run!(cmd) - unless system(cmd) - raise "non-0 exit code #{$?} returned from [#{cmd}]" + Cocaine::CommandLine.new("git submodule update", "--init --quiet").run if File.exists?('.gitmodules') end end diff --git a/spec/jobs/build_state_update_job_spec.rb b/spec/jobs/build_state_update_job_spec.rb index 93750f369..fbd41b4bd 100644 --- a/spec/jobs/build_state_update_job_spec.rb +++ b/spec/jobs/build_state_update_job_spec.rb @@ -12,7 +12,6 @@ build.build_parts.create!(:kind => :cucumber, :paths => ["baz"], :queue => :ci) # TODO: This is terrible, need to fold this feedback back into the design. # We are stubbing methods that are not called from the class under test. - allow(GitRepo).to receive(:run!) allow(GitRepo).to receive(:harmonize_remote_url) allow(GitRepo).to receive(:synchronize_with_remote).and_return(true) allow(GitRepo).to receive(:sha_for_branch).and_return(current_repo_master)