Class: Overcommit::Hook::PreCommit::BundleCheck

Inherits:
Base
  • Object
show all
Defined in:
lib/overcommit/hook/pre_commit/bundle_check.rb

Overview

Check if local Gemfile.lock matches Gemfile when either changes, unless Gemfile.lock is ignored by git.

Instance Method Summary collapse

Methods inherited from Base

#applicable_files, #command, #description, #enabled?, #in_path?, #initialize, #name, #quiet?, #required?, #run?, #skip?

Constructor Details

This class inherits a constructor from Overcommit::Hook::Base

Instance Method Details

#runObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/overcommit/hook/pre_commit/bundle_check.rb', line 5

def run
  unless in_path?('bundle')
    return :warn, 'bundler not installed -- run `gem install bundler`'
  end

  # Ignore if Gemfile.lock is not tracked by git
  return :good if command("git check-ignore #{LOCK_FILE}").success?

  result = command('bundle check')
  unless result.success?
    return :bad, result.stdout
  end

  result = command("git diff --quiet -- #{LOCK_FILE}")
  unless result.success?
    return :bad, "#{LOCK_FILE} is not up-to-date -- run `bundle check`"
  end

  :good
end