Sha256: bcaf412538012ff7461c7e696f22a001473e0f49b36889dca48cff4be051a010

Contents?: true

Size: 1004 Bytes

Versions: 6

Compression:

Stored size: 1004 Bytes

Contents

# frozen_string_literal: true

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 = File.basename(ENV['BUNDLE_GEMFILE'] || '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)

      previous_lockfile = File.read(LOCK_FILE) if File.exist?(LOCK_FILE)

      result = execute(command)
      unless result.success?
        return :fail, result.stdout
      end

      new_lockfile = File.read(LOCK_FILE) if File.exist?(LOCK_FILE)
      if previous_lockfile != new_lockfile
        return :fail, "#{LOCK_FILE} is not up-to-date -- run \
        `#{command.join(' ')}` or add the Gemfile and/or Gemfile.lock".squeeze
      end

      :pass
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
overcommit-0.64.1 lib/overcommit/hook/pre_commit/bundle_check.rb
overcommit-0.64.0 lib/overcommit/hook/pre_commit/bundle_check.rb
overcommit-0.63.0 lib/overcommit/hook/pre_commit/bundle_check.rb
overcommit-0.62.0 lib/overcommit/hook/pre_commit/bundle_check.rb
overcommit-0.61.0 lib/overcommit/hook/pre_commit/bundle_check.rb
overcommit-0.60.0 lib/overcommit/hook/pre_commit/bundle_check.rb