Skip to content
This repository was archived by the owner on Feb 7, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -312,6 +313,7 @@ DEPENDENCIES
mysql2
nokogiri
passenger (~> 4.0.41)
posix-spawn
pry-byebug
pry-rails
quiet_assets
Expand Down
54 changes: 25 additions & 29 deletions lib/git_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
1 change: 0 additions & 1 deletion spec/jobs/build_state_update_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down