Class: Overcommit::HookSigner
- Inherits:
-
Object
- Object
- Overcommit::HookSigner
- 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].freeze
Instance Attribute Summary collapse
-
#hook_name ⇒ Object
readonly
Returns the value of attribute hook_name.
Instance Method Summary collapse
-
#hook_path ⇒ String
Returns the path of the file that should be incorporated into this hooks signature.
-
#initialize(hook_name, config, context) ⇒ HookSigner
constructor
A new instance of HookSigner.
- #signable_file?(file) ⇒ Boolean
-
#signature_changed? ⇒ true, false
Return whether the signature for this hook has changed since it was last calculated.
-
#update_signature! ⇒ Object
Update the current stored signature for this hook.
Constructor Details
#initialize(hook_name, config, context) ⇒ HookSigner
Returns a new instance of HookSigner.
13 14 15 16 17 |
# File 'lib/overcommit/hook_signer.rb', line 13 def initialize(hook_name, config, context) @hook_name = hook_name @config = config @context = context end |
Instance Attribute Details
#hook_name ⇒ Object (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 |
Instance Method Details
#hook_path ⇒ String
Returns the path of the file that should be incorporated into this hooks signature.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/overcommit/hook_signer.rb', line 23 def hook_path @hook_path ||= begin plugin_path = File.join(@config.plugin_directory, @context.hook_type_name, "#{Overcommit::Utils.snake_case(@hook_name)}.rb") if File.exist?(plugin_path) plugin_path else # Otherwise this is an ad hoc hook using an existing hook script hook_config = @config.for_hook(@hook_name, @context.hook_class_name) command = Array(hook_config['command'] || hook_config['required_executable']) unless !@config.verify_signatures? || signable_file?(command.first) raise Overcommit::Exceptions::InvalidHookDefinition, 'Hook must specify a `required_executable` or `command` that ' \ 'is tracked by git (i.e. is a path relative to the root ' \ 'of the repository) so that it can be signed' end File.join(Overcommit::Utils.repo_root, command.first) end end end |
#signable_file?(file) ⇒ Boolean
50 51 52 53 54 |
# File 'lib/overcommit/hook_signer.rb', line 50 def signable_file?(file) sep = Overcommit::OS.windows? ? '\\' : File::SEPARATOR file.start_with?(".#{sep}") && Overcommit::GitRepo.tracked?(file) end |
#signature_changed? ⇒ true, false
Return whether the signature for this hook has changed since it was last calculated.
60 61 62 |
# File 'lib/overcommit/hook_signer.rb', line 60 def signature_changed? signature != stored_signature end |
#update_signature! ⇒ Object
Update the current stored signature for this hook.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/overcommit/hook_signer.rb', line 65 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 |