Sha256: 4311addf2e1c8714ecc4d20a5c31c55d62a6e3edec782b9b7c4cb54edf55f036

Contents?: true

Size: 880 Bytes

Versions: 3

Compression:

Stored size: 880 Bytes

Contents

require 'git/duet'
require 'git/duet/command_methods'
require 'git/duet/script_die_error'

class Git::Duet::PreCommitCommand
  include Git::Duet::CommandMethods

  def initialize(quiet = false)
    @quiet = !!quiet
  end

  def execute!
    in_repo_root do
      if !env_cache_exists? || env_cache_stale?
        explode!
      end
    end
  end

  private
  def explode!
    error("Your git duet settings are stale, human!")
    error("Update them with `git duet` or `git solo`.")
    raise Git::Duet::ScriptDieError.new(1)
  end

  def env_cache_exists?
    with_output_quieted do
      exec_check('git config duet.env.mtime')
    end
    true
  rescue
    false
  end

  def env_cache_stale?
    Integer(exec_check('git config duet.env.mtime')) < stale_cutoff
  end

  def stale_cutoff
    Integer(Time.now - Integer(ENV.fetch('GIT_DUET_SECONDS_AGO_STALE', '1200')))
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
git-duet-0.1.3 lib/git/duet/pre_commit_command.rb
git-duet-0.1.2 lib/git/duet/pre_commit_command.rb
git-duet-0.1.1 lib/git/duet/pre_commit_command.rb