Skip to content

Commit

Permalink
Update to use Terrapin instead of Cocaine
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Jan 17, 2019
1 parent a9dd76d commit 121feef
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 55 deletions.
20 changes: 4 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,18 @@ PATH
remote: .
specs:
git-fastclone (1.1.2)
cocaine
colorize
terrapin (~> 0.6.0)

GEM
remote: https://rubygems.org/
specs:
activesupport (5.0.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
ast (2.4.0)
climate_control (0.0.3)
activesupport (>= 3.0)
cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
climate_control (0.2.0)
colorize (0.8.1)
concurrent-ruby (1.0.4)
diff-lcs (1.2.5)
i18n (0.7.0)
jaro_winkler (1.5.2)
logger (1.3.0)
minitest (5.10.1)
parallel (1.13.0)
parser (2.6.0.0)
ast (~> 2.4.0)
Expand Down Expand Up @@ -53,9 +42,8 @@ GEM
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.4.0)
ruby-progressbar (1.10.0)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)
terrapin (0.6.0)
climate_control (>= 0.0.3, < 1.0)
unicode-display_width (1.4.1)

PLATFORMS
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Before accepting any pull requests, we need you to sign an [Individual Contribut

Acknowledgements
----------------
[thoughtbot/cocaine][3] - jyurek and collaborators
[thoughtbot/terrapin][3] - jyurek and collaborators

[robolson][4]

Expand Down Expand Up @@ -104,7 +104,7 @@ License

[1]: https://corner.squareup.com/2015/11/fastclone.html
[2]: https://docs.google.com/a/squareup.com/forms/d/13WR8m5uZ2nAkJH41k7GdVBXAAbzDk00vxtEYjd6Imzg/viewform?formkey=dDViT2xzUHAwRkI3X3k5Z0lQM091OGc6MQ&ndplr=1
[3]: https://github.com/thoughtbot/cocaine
[3]: https://github.com/thoughtbot/terrapin
[4]: https://github.com/robolson
[5]: https://github.com/ianchesal
[6]: https://github.com/mtauraso
Expand Down
2 changes: 1 addition & 1 deletion git-fastclone.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ Gem::Specification.new do |gem|
gem.homepage = 'http://square.github.io/git-fastclone/'
gem.license = 'Apache'

gem.add_runtime_dependency 'cocaine'
gem.add_runtime_dependency 'colorize'
gem.add_runtime_dependency 'terrapin', '~> 0.6.0'
end
36 changes: 18 additions & 18 deletions lib/git-fastclone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
require 'optparse'
require 'fileutils'
require 'logger'
require 'cocaine'
require 'terrapin'
require 'timeout'

# Contains helper module UrlHelper and execution class GitFastClone::Runner
Expand Down Expand Up @@ -119,7 +119,7 @@ def run
end

puts "Cloning #{path_from_git_url(url)} to #{File.join(abs_clone_path, path)}"
Cocaine::CommandLine.environment['GIT_ALLOW_PROTOCOL'] =
Terrapin::CommandLine.environment['GIT_ALLOW_PROTOCOL'] =
ENV['GIT_ALLOW_PROTOCOL'] || DEFAULT_GIT_ALLOW_PROTOCOL
clone(url, options[:branch], path)
end
Expand All @@ -141,7 +141,7 @@ def parse_options
logger.formatter = proc do |_severity, _datetime, _progname, msg|
"#{msg}\n"
end
Cocaine::CommandLine.logger = logger
Terrapin::CommandLine.logger = logger
end

opts.on('-c', '--color', 'Display colored output') do
Expand Down Expand Up @@ -191,16 +191,16 @@ def clone(url, rev, src_dir)
initial_time = Time.now

with_git_mirror(url) do |mirror|
Cocaine::CommandLine.new('git clone', '--quiet --reference :mirror :url :path')
.run(mirror: mirror.to_s,
url: url.to_s,
path: File.join(abs_clone_path, src_dir).to_s)
Terrapin::CommandLine.new('git clone', '--quiet --reference :mirror :url :path')
.run(mirror: mirror.to_s,
url: url.to_s,
path: File.join(abs_clone_path, src_dir).to_s)
end

# Only checkout if we're changing branches to a non-default branch
if rev
Dir.chdir(File.join(abs_clone_path, src_dir)) do
Cocaine::CommandLine.new('git checkout', '--quiet :rev').run(rev: rev.to_s)
Terrapin::CommandLine.new('git checkout', '--quiet :rev').run(rev: rev.to_s)
end
end

Expand All @@ -224,8 +224,8 @@ def update_submodules(pwd, url)
threads = []
submodule_url_list = []

Cocaine::CommandLine.new('cd', ':path; git submodule init 2>&1')
.run(path: File.join(abs_clone_path, pwd)).split("\n").each do |line|
Terrapin::CommandLine.new('cd', ':path; git submodule init 2>&1')
.run(path: File.join(abs_clone_path, pwd)).split("\n").each do |line|
submodule_path, submodule_url = parse_update_info(line)
submodule_url_list << submodule_url

Expand All @@ -239,10 +239,10 @@ def update_submodules(pwd, url)
def thread_update_submodule(submodule_url, submodule_path, threads, pwd)
threads << Thread.new do
with_git_mirror(submodule_url) do |mirror|
Cocaine::CommandLine.new('cd', ':dir; git submodule update --quiet --reference :mirror :path')
.run(dir: File.join(abs_clone_path, pwd).to_s,
mirror: mirror.to_s,
path: submodule_path.to_s)
Terrapin::CommandLine.new('cd', ':dir; git submodule update --quiet --reference :mirror :path')
.run(dir: File.join(abs_clone_path, pwd).to_s,
mirror: mirror.to_s,
path: submodule_path.to_s)
end

update_submodules(File.join(pwd, submodule_path), submodule_url)
Expand Down Expand Up @@ -316,14 +316,14 @@ def prefetch(submodule_file)
# that this repo has been updated on this run of fastclone
def store_updated_repo(url, mirror, repo_name, fail_hard)
unless Dir.exist?(mirror)
Cocaine::CommandLine.new('git clone', '--mirror :url :mirror')
.run(url: url.to_s, mirror: mirror.to_s)
Terrapin::CommandLine.new('git clone', '--mirror :url :mirror')
.run(url: url.to_s, mirror: mirror.to_s)
end

Cocaine::CommandLine.new('cd', ':path; git remote update --prune').run(path: mirror)
Terrapin::CommandLine.new('cd', ':path; git remote update --prune').run(path: mirror)

reference_updated[repo_name] = true
rescue Cocaine::ExitStatusError => e
rescue Terrapin::ExitStatusError => e
# To avoid corruption of the cache, if we failed to update or check out we remove
# the cache directory entirely. This may cause the current clone to fail, but if the
# underlying error from git is transient it will not affect future clones.
Expand Down
38 changes: 20 additions & 18 deletions spec/git_fastclone_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
end

# Modified ARGV, watch out
ARGV = ['ssh://[email protected]/git-fastclone.git', 'test_reference_dir'] # rubocop:disable Style/MutableConstant
before do
stub_const('ARGV', ['ssh://[email protected]/git-fastclone.git', 'test_reference_dir'])
end

let(:yielded) { [] }

Expand Down Expand Up @@ -74,14 +76,14 @@

describe '.clone' do
it 'should clone correctly' do
cocaine_commandline_double = double('new_cocaine_commandline')
terrapin_commandline_double = double('new_terrapin_commandline')
allow(subject).to receive(:with_git_mirror) {}
allow(cocaine_commandline_double).to receive(:run) {}
allow(Cocaine::CommandLine).to receive(:new) { cocaine_commandline_double }
allow(terrapin_commandline_double).to receive(:run) {}
allow(Terrapin::CommandLine).to receive(:new) { terrapin_commandline_double }

expect(Time).to receive(:now).twice { 0 }
expect(Cocaine::CommandLine).to receive(:new)
expect(cocaine_commandline_double).to receive(:run)
expect(Terrapin::CommandLine).to receive(:new)
expect(terrapin_commandline_double).to receive(:run)

subject.clone(placeholder_arg, placeholder_arg, '.')
end
Expand Down Expand Up @@ -228,22 +230,22 @@

describe '.store_updated_repo' do
context 'when fail_hard is true' do
it 'should raise a Cocaine error' do
cocaine_commandline_double = double('new_cocaine_commandline')
allow(cocaine_commandline_double).to receive(:run) { raise Cocaine::ExitStatusError }
allow(Cocaine::CommandLine).to receive(:new) { cocaine_commandline_double }
it 'should raise a Terrapin error' do
terrapin_commandline_double = double('new_terrapin_commandline')
allow(terrapin_commandline_double).to receive(:run) { raise Terrapin::ExitStatusError }
allow(Terrapin::CommandLine).to receive(:new) { terrapin_commandline_double }
expect(FileUtils).to receive(:remove_entry_secure).with(placeholder_arg, force: true)
expect do
subject.store_updated_repo(placeholder_arg, placeholder_arg, placeholder_arg, true)
end.to raise_error(Cocaine::ExitStatusError)
end.to raise_error(Terrapin::ExitStatusError)
end
end

context 'when fail_hard is false' do
it 'should not raise a cocaine error' do
cocaine_commandline_double = double('new_cocaine_commandline')
allow(cocaine_commandline_double).to receive(:run) { raise Cocaine::ExitStatusError }
allow(Cocaine::CommandLine).to receive(:new) { cocaine_commandline_double }
it 'should not raise a terrapin error' do
terrapin_commandline_double = double('new_terrapin_commandline')
allow(terrapin_commandline_double).to receive(:run) { raise Terrapin::ExitStatusError }
allow(Terrapin::CommandLine).to receive(:new) { terrapin_commandline_double }
expect(FileUtils).to receive(:remove_entry_secure).with(placeholder_arg, force: true)

expect do
Expand All @@ -255,9 +257,9 @@
let(:placeholder_hash) { {} }

it 'should correctly update the hash' do
cocaine_commandline_double = double('new_cocaine_commandline')
allow(cocaine_commandline_double).to receive(:run) {}
allow(Cocaine::CommandLine).to receive(:new) { cocaine_commandline_double }
terrapin_commandline_double = double('new_terrapin_commandline')
allow(terrapin_commandline_double).to receive(:run) {}
allow(Terrapin::CommandLine).to receive(:new) { terrapin_commandline_double }
allow(Dir).to receive(:chdir) {}

subject.reference_updated = placeholder_hash
Expand Down

0 comments on commit 121feef

Please sign in to comment.