Class: Overcommit::HookSigner

Inherits:
Object
  • Object
show all
Defined in:
lib/overcommit/hook_signer.rb

Overview

Calculates, stores, and retrieves stored signatures of hook plugins.

Constant Summary collapse

IGNORED_CONFIG_KEYS =

We don’t want to include the skip setting as it is set by Overcommit itself

%w[skip]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hook_path, config, context) ⇒ HookSigner

Returns a new instance of HookSigner.

Parameters:



13
14
15
16
17
18
19
# File 'lib/overcommit/hook_signer.rb', line 13

def initialize(hook_path, config, context)
  @hook_path = hook_path
  @config = config
  @context = context

  @hook_name = Overcommit::Utils.camel_case(File.basename(@hook_path, '.rb'))
end

Instance Attribute Details

#hook_nameObject (readonly)

Returns the value of attribute hook_name.



4
5
6
# File 'lib/overcommit/hook_signer.rb', line 4

def hook_name
  @hook_name
end

#hook_pathObject (readonly)

Returns the value of attribute hook_path.



4
5
6
# File 'lib/overcommit/hook_signer.rb', line 4

def hook_path
  @hook_path
end

Instance Method Details

#signature_changed?true, false

Return whether the signature for this hook has changed since it was last calculated.

Returns:

  • (true, false)


25
26
27
# File 'lib/overcommit/hook_signer.rb', line 25

def signature_changed?
  signature != stored_signature
end

#update_signature!Object

Update the current stored signature for this hook.



30
31
32
33
34
35
36
37
38
39
# File 'lib/overcommit/hook_signer.rb', line 30

def update_signature!
  result = Overcommit::Utils.execute(
    %w[git config --local] + [signature_config_key, signature]
  )

  unless result.success?
    raise Overcommit::Exceptions::GitConfigError,
          "Unable to write to local repo git config: #{result.stderr}"
  end
end