Class: Kamaze::Project::Tools::Git::Hooks::PreCommit
- Defined in:
- lib/kamaze/project/tools/git/hooks/pre_commit.rb,
lib/kamaze/project/tools/git/hooks/pre_commit.rb
Overview
PreCommit hook
Provide helper methods intended to write hooks relating to pre-commit
Sample of use:
retcode = tools.fetch(:git).hooks[:pre_commit].process_index do |files|
tools.fetch(:rubocop).prepare do |c|
c.patterns = files.reject(&:deleted?).map(&:to_s)
end.run
exit(retcode) unless retcode.zero?
end
Instance Method Summary collapse
- #_process_index(index, options = {}) ⇒ Kamaze::Project::Tools::Git::Status::Index protected
-
#process_index(options = {}) {|Array<Kamaze::Project::Tools::Git::Status::File>| ... } ⇒ Object
Process index (files).
Constructor Details
This class inherits a constructor from Kamaze::Project::Tools::Git::Hooks::BaseHook
Instance Method Details
#_process_index(index, options = {}) ⇒ Kamaze::Project::Tools::Git::Status::Index (protected)
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/kamaze/project/tools/git/hooks/pre_commit.rb', line 68 def _process_index(index, = {}) { empty: Errno::ECANCELED, unsafe: Errno::EOPNOTSUPP }.each do |type, v| with_exit_on_failure do key = "allow_#{type}".to_sym [key] = .keys.include?(key) ? !![key] : false next if [key] self.retcode = v.const_get(:Errno) if index.public_send("#{type}?") end end index end |
#process_index(options = {}) {|Array<Kamaze::Project::Tools::Git::Status::File>| ... } ⇒ Object
Process index (files)
Exits with a status code, raising SystemExit
.
code | constant | reason |
---|---|---|
125 |
Errno::ECANCELED |
Index is empty |
95 |
Errno::EOPNOTSUPP |
Index is unsafe |
0 |
Errno::NOERROR |
Success |
:allow_empty
and :allow_unsafe
options are available,
to continue processing even if empty
or unsafe
.
54 55 56 57 58 59 |
# File 'lib/kamaze/project/tools/git/hooks/pre_commit.rb', line 54 def process_index( = {}) index = _process_index(repository.status.index, ) self.retcode = Errno::NOERROR::Errno yield(index.to_a.freeze) if block_given? end |