Sha256: 30b51b4a6bf19e873ed570ac11893dd1a1aff421bcd57f76038ed6261722eca0

Contents?: true

Size: 777 Bytes

Versions: 4

Compression:

Stored size: 777 Bytes

Contents

module Overcommit::Hook::PreCommit
  # Check if local Gemfile.lock matches Gemfile when either changes, unless
  # Gemfile.lock is ignored by git.
  #
  # @see http://bundler.io/
  class BundleCheck < Base
    LOCK_FILE = 'Gemfile.lock'

    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)
      unless result.success?
        return :fail, result.stdout
      end

      result = execute(%w[git diff --quiet --] + [LOCK_FILE])
      unless result.success?
        return :fail, "#{LOCK_FILE} is not up-to-date -- run `#{command.join(' ')}`"
      end

      :pass
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
overcommit-0.29.0 lib/overcommit/hook/pre_commit/bundle_check.rb
overcommit-0.28.0 lib/overcommit/hook/pre_commit/bundle_check.rb
overcommit-0.27.0 lib/overcommit/hook/pre_commit/bundle_check.rb
overcommit-0.26.0 lib/overcommit/hook/pre_commit/bundle_check.rb