Skip to content

Commit

Permalink
Update RuboCop
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Jan 17, 2019
1 parent b123102 commit a9dd76d
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 40 deletions.
5 changes: 2 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
inherit_from: .rubocop_todo.yml

AllCops:
Include:
- Rakefile
TargetRubyVersion: 2.2

Style/FileName:
Naming/FileName:
Exclude:
- 'bin/git-fastclone'
- 'lib/git-fastclone.rb'
Expand Down
25 changes: 24 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-03-29 21:03:41 -0700 using RuboCop version 0.35.1.
# on 2019-01-17 09:38:07 -0800 using RuboCop version 0.63.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
Lint/AmbiguousBlockAssociation:
Exclude:
- 'spec/git_fastclone_runner_spec.rb'

# Offense count: 5
Metrics/AbcSize:
Max: 25

# Offense count: 4
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 214

# Offense count: 1
Metrics/CyclomaticComplexity:
Max: 7

# Offense count: 2
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 158

# Offense count: 1
Metrics/PerceivedComplexity:
Max: 8

# Offense count: 6
# Configuration parameters: .
# SupportedStyles: inline, group
Style/AccessModifierDeclarations:
EnforcedStyle: inline
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

group :development do
Expand All @@ -6,7 +8,7 @@ group :development do
gem 'rubocop'
end

gem 'rspec'
gem 'logger'
gem 'rspec'

gemspec
18 changes: 10 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ GEM
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.12.1)
parser (2.5.0.5)
parallel (1.13.0)
parser (2.6.0.0)
ast (~> 2.4.0)
powerpack (0.1.1)
powerpack (0.1.2)
rainbow (3.0.0)
rake (10.4.2)
rspec (3.4.0)
Expand All @@ -43,18 +44,19 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
rubocop (0.54.0)
rubocop (0.63.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
unicode-display_width (~> 1.4.0)
ruby-progressbar (1.10.0)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)
unicode-display_width (1.3.0)
unicode-display_width (1.4.1)

PLATFORMS
ruby
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# encoding: utf-8
# frozen_string_literal: true

require 'bundler/setup'

task default: %w(spec rubocop)
task default: %w[spec rubocop]

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new
Expand Down
1 change: 1 addition & 0 deletions bin/git-fastclone
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# Copyright 2015 Square Inc.

Expand Down
14 changes: 9 additions & 5 deletions git-fastclone.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Copyright 2015 Square Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,19 +16,21 @@

require 'date'

$:.push File.expand_path("../lib", __FILE__)
$LOAD_PATH.push File.expand_path('lib', __dir__)
require 'git-fastclone/version'

Gem::Specification.new do |gem|
gem.name = 'git-fastclone'
gem.version = GitFastCloneVersion::VERSION
gem.date = Date.today.to_s
gem.summary = %q(git-clone --recursive on steroids!)
gem.description = %q(A git command that uses reference repositories and threading to quickly and recursively clone repositories with many nested submodules)
gem.summary = 'git-clone --recursive on steroids!'
gem.description = 'A git command that uses reference repositories and threading to quickly' \
'and recursively clone repositories with many nested submodules'
gem.authors = ['Michael Tauraso', 'James Chang']
gem.email = ['[email protected]', '[email protected]']
gem.files = Dir['Rakefile', '{bin,lib,man,test,spec}/**/*', 'README*', 'LICENSE*'] & `git ls-files -z`.split("\0")
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.files = Dir['Rakefile', '{bin,lib,man,test,spec}/**/*', 'README*', 'LICENSE*'] &
`git ls-files -z`.split("\0")
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ['lib']
gem.homepage = 'http://square.github.io/git-fastclone/'
Expand Down
26 changes: 14 additions & 12 deletions lib/git-fastclone.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Copyright 2015 Square Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -53,7 +55,7 @@ def reference_repo_submodule_file(url, reference_dir, using_local_repo)

def reference_repo_lock_file(url, reference_dir, using_local_repo)
lock_file_name = "#{reference_repo_dir(url, reference_dir, using_local_repo)}:lock"
File.open(lock_file_name, File::RDWR | File::CREAT, 0644)
File.open(lock_file_name, File::RDWR | File::CREAT, 0o644)
end
module_function :reference_repo_lock_file
end
Expand Down Expand Up @@ -172,8 +174,9 @@ def parse_inputs

if Dir.exist?(path)
msg = "Clone destination #{File.join(abs_clone_path, path)} already exists!"
fail msg.red if color
fail msg
raise msg.red if color

raise msg
end

self.reference_dir = ENV['REFERENCE_REPO_DIR'] || DEFAULT_REFERENCE_REPO_DIR
Expand All @@ -189,9 +192,9 @@ def clone(url, rev, src_dir)

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)
.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
Expand Down Expand Up @@ -222,7 +225,7 @@ def update_submodules(pwd, url)
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|
.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 @@ -237,9 +240,9 @@ 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)
.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 @@ -314,13 +317,12 @@ def prefetch(submodule_file)
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)
.run(url: url.to_s, mirror: mirror.to_s)
end

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

reference_updated[repo_name] = true

rescue Cocaine::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
Expand Down
2 changes: 2 additions & 0 deletions lib/git-fastclone/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Version string for git-fastclone
module GitFastCloneVersion
VERSION = '1.1.2'.freeze
Expand Down
18 changes: 10 additions & 8 deletions spec/git_fastclone_runner_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Copyright 2015 Square Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -31,7 +33,7 @@
end

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

let(:yielded) { [] }

Expand Down Expand Up @@ -104,7 +106,7 @@
describe '.thread_update_submodule' do
it 'should update correctly' do
pending('need to figure out how to test this')
fail
raise
end
end

Expand All @@ -127,7 +129,7 @@

expect do
subject.with_reference_repo_lock(test_url_valid) do
fail placeholder_arg
raise placeholder_arg
end
end.to raise_error(placeholder_arg)
end
Expand Down Expand Up @@ -184,7 +186,7 @@
end
end

let(:placeholder_hash) { Hash.new }
let(:placeholder_hash) { {} }

context 'when already have a hash' do
it 'should not store' do
Expand Down Expand Up @@ -218,7 +220,7 @@
it 'should go through the submodule file properly' do
expect(Thread).to receive(:new).exactly(3).times

allow(File).to receive(:readlines) { %w(1 2 3) }
allow(File).to receive(:readlines) { %w[1 2 3] }
subject.prefetch_submodules = true
subject.prefetch(placeholder_arg)
end
Expand All @@ -228,7 +230,7 @@
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) { fail Cocaine::ExitStatusError }
allow(cocaine_commandline_double).to receive(:run) { raise Cocaine::ExitStatusError }
allow(Cocaine::CommandLine).to receive(:new) { cocaine_commandline_double }
expect(FileUtils).to receive(:remove_entry_secure).with(placeholder_arg, force: true)
expect do
Expand All @@ -240,7 +242,7 @@
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) { fail Cocaine::ExitStatusError }
allow(cocaine_commandline_double).to receive(:run) { raise Cocaine::ExitStatusError }
allow(Cocaine::CommandLine).to receive(:new) { cocaine_commandline_double }
expect(FileUtils).to receive(:remove_entry_secure).with(placeholder_arg, force: true)

Expand All @@ -250,7 +252,7 @@
end
end

let(:placeholder_hash) { Hash.new }
let(:placeholder_hash) { {} }

it 'should correctly update the hash' do
cocaine_commandline_double = double('new_cocaine_commandline')
Expand Down
2 changes: 2 additions & 0 deletions spec/git_fastclone_url_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Copyright 2015 Square Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

require 'rspec/core'
require 'rspec/mocks'

0 comments on commit a9dd76d

Please sign in to comment.