Permalink
Browse files

Add to run bundle outdated in pre commit

  • Loading branch information...
morizyun authored and sds committed May 12, 2016
1 parent a46dcf2 commit 83b6033938d04556c4a26cfd52aa6b5244b3cbf7
View
@@ -468,6 +468,7 @@ issue](https://github.com/brigade/overcommit/issues/238) for more details.
* [Brakeman](lib/overcommit/hook/pre_commit/brakeman.rb)
* [`*`BrokenSymlinks](lib/overcommit/hook/pre_commit/broken_symlinks.rb)
* [BundleCheck](lib/overcommit/hook/pre_commit/bundle_check.rb)
* [BundleOutdated](lib/overcommit/hook/pre_commit/bundle_outdated.rb)
* [`*`CaseConflicts](lib/overcommit/hook/pre_commit/case_conflicts.rb)
* [ChamberSecurity](lib/overcommit/hook/pre_commit/chamber_security.rb)
* [CoffeeLint](lib/overcommit/hook/pre_commit/coffee_lint.rb)
View
@@ -175,6 +175,13 @@ PreCommit:
- 'Gemfile.lock'
- '*.gemspec'
BundleOutdated:
enabled: false
description: 'List installed gems with newer versions available'
required_executable: 'bundle'
flags: ['outdated', '--strict', '--parseable']
install_command: 'gem install bundler'
CaseConflicts:
enabled: true
description: 'Check for case-insensitivity conflicts'
@@ -0,0 +1,24 @@
module Overcommit::Hook::PreCommit
# Check if local Gemfile.lock matches Gemfile when either changes, unless
# Gemfile.lock is ignored by git.
# Check outdated rubyGems
#
# @see http://bundler.io/bundle_outdated.html
class BundleOutdated < Base
LOCK_FILE = 'Gemfile.lock'.freeze
def run
# Ignore if Gemfile.lock is not tracked by git
ignored_files = execute(%w[git ls-files -o -i --exclude-standard]).stdout.split("\n")
return :pass if ignored_files.include?(LOCK_FILE)
result = execute(command)
warn_msgs = result.stdout.split("\n").
reject { |str| str.strip.empty? }.
reject { |str| (str.strip =~ /^(\[|\()?warning|deprecation/i) }
warnings = warn_msgs.map { |msg| Overcommit::Hook::Message.new(:warning, nil, nil, msg) }
warnings.empty? ? :pass : warnings
end
end
end
@@ -0,0 +1,70 @@
require 'spec_helper'
describe Overcommit::Hook::PreCommit::BundleOutdated do
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
let(:context) { double('context') }
subject { described_class.new(config, context) }
context 'when Gemfile.lock is ignored' do
around do |example|
repo do
touch 'Gemfile.lock'
echo('Gemfile.lock', '.gitignore')
`git add .gitignore`
`git commit -m "Ignore Gemfile.lock"`
example.run
end
end
it { should pass }
end
context 'when Gemfile.lock is not ignored' do
around do |example|
repo do
example.run
end
end
before do
subject.stub(:execute).with(%w[git ls-files -o -i --exclude-standard]).
and_return(double(stdout: ''))
subject.stub(:execute).with(%w[bundle outdated --strict --parseable]).
and_return(result)
end
context 'and it reports some outdated gems' do
let(:result) do
double(stdout: <<-EOF
Warning: the running version of Bundler is older than the version that created the lockfile. We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
airbrake (newest 5.3.0, installed 5.2.3, requested ~> 5.0)
aws-sdk (newest 2.3.3, installed 2.3.1, requested ~> 2)
font-awesome-rails (newest 4.6.2.0, installed 4.6.1.0)
mechanize (newest 2.7.4, installed 2.1.1)
minimum-omniauth-scaffold (newest 0.4.3, installed 0.4.1)
airbrake-ruby (newest 1.3.0, installed 1.2.4)
aws-sdk-core (newest 2.3.3, installed 2.3.1)
aws-sdk-resources (newest 2.3.3, installed 2.3.1)
config (newest 1.1.1, installed 1.1.0)
ruby_parser (newest 3.8.2, installed 3.8.1)
EOF
)
end
it { should warn }
end
context 'and it reports bundle up to date' do
let(:result) do
double(stdout: <<-EOF
Warning: the running version of Bundler is older than the version that created the lockfile. We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
EOF
)
end
it { should pass }
end
end
end

0 comments on commit 83b6033

Please sign in to comment.