overcommit-jeygeethanmedia 0.53.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/overcommit +50 -0
- data/config/default.yml +1356 -0
- data/config/starter.yml +33 -0
- data/lib/overcommit.rb +26 -0
- data/lib/overcommit/cli.rb +223 -0
- data/lib/overcommit/command_splitter.rb +146 -0
- data/lib/overcommit/configuration.rb +350 -0
- data/lib/overcommit/configuration_loader.rb +96 -0
- data/lib/overcommit/configuration_validator.rb +186 -0
- data/lib/overcommit/constants.rb +12 -0
- data/lib/overcommit/exceptions.rb +52 -0
- data/lib/overcommit/git_config.rb +22 -0
- data/lib/overcommit/git_repo.rb +286 -0
- data/lib/overcommit/git_version.rb +17 -0
- data/lib/overcommit/hook/base.rb +294 -0
- data/lib/overcommit/hook/commit_msg/base.rb +14 -0
- data/lib/overcommit/hook/commit_msg/capitalized_subject.rb +25 -0
- data/lib/overcommit/hook/commit_msg/empty_message.rb +12 -0
- data/lib/overcommit/hook/commit_msg/gerrit_change_id.rb +22 -0
- data/lib/overcommit/hook/commit_msg/hard_tabs.rb +17 -0
- data/lib/overcommit/hook/commit_msg/message_format.rb +31 -0
- data/lib/overcommit/hook/commit_msg/russian_novel.rb +16 -0
- data/lib/overcommit/hook/commit_msg/single_line_subject.rb +16 -0
- data/lib/overcommit/hook/commit_msg/spell_check.rb +45 -0
- data/lib/overcommit/hook/commit_msg/text_width.rb +56 -0
- data/lib/overcommit/hook/commit_msg/trailing_period.rb +16 -0
- data/lib/overcommit/hook/post_checkout/base.rb +22 -0
- data/lib/overcommit/hook/post_checkout/bower_install.rb +13 -0
- data/lib/overcommit/hook/post_checkout/bundle_install.rb +13 -0
- data/lib/overcommit/hook/post_checkout/composer_install.rb +13 -0
- data/lib/overcommit/hook/post_checkout/index_tags.rb +12 -0
- data/lib/overcommit/hook/post_checkout/npm_install.rb +13 -0
- data/lib/overcommit/hook/post_checkout/submodule_status.rb +12 -0
- data/lib/overcommit/hook/post_checkout/yarn_install.rb +13 -0
- data/lib/overcommit/hook/post_commit/base.rb +12 -0
- data/lib/overcommit/hook/post_commit/bower_install.rb +13 -0
- data/lib/overcommit/hook/post_commit/bundle_install.rb +13 -0
- data/lib/overcommit/hook/post_commit/commitplease.rb +16 -0
- data/lib/overcommit/hook/post_commit/composer_install.rb +13 -0
- data/lib/overcommit/hook/post_commit/git_guilt.rb +43 -0
- data/lib/overcommit/hook/post_commit/index_tags.rb +12 -0
- data/lib/overcommit/hook/post_commit/npm_install.rb +13 -0
- data/lib/overcommit/hook/post_commit/submodule_status.rb +12 -0
- data/lib/overcommit/hook/post_commit/yarn_install.rb +13 -0
- data/lib/overcommit/hook/post_merge/base.rb +12 -0
- data/lib/overcommit/hook/post_merge/bower_install.rb +13 -0
- data/lib/overcommit/hook/post_merge/bundle_install.rb +13 -0
- data/lib/overcommit/hook/post_merge/composer_install.rb +13 -0
- data/lib/overcommit/hook/post_merge/index_tags.rb +12 -0
- data/lib/overcommit/hook/post_merge/npm_install.rb +13 -0
- data/lib/overcommit/hook/post_merge/submodule_status.rb +12 -0
- data/lib/overcommit/hook/post_merge/yarn_install.rb +13 -0
- data/lib/overcommit/hook/post_rewrite/base.rb +12 -0
- data/lib/overcommit/hook/post_rewrite/bower_install.rb +13 -0
- data/lib/overcommit/hook/post_rewrite/bundle_install.rb +13 -0
- data/lib/overcommit/hook/post_rewrite/composer_install.rb +13 -0
- data/lib/overcommit/hook/post_rewrite/index_tags.rb +19 -0
- data/lib/overcommit/hook/post_rewrite/npm_install.rb +13 -0
- data/lib/overcommit/hook/post_rewrite/submodule_status.rb +12 -0
- data/lib/overcommit/hook/post_rewrite/yarn_install.rb +13 -0
- data/lib/overcommit/hook/pre_commit/author_email.rb +26 -0
- data/lib/overcommit/hook/pre_commit/author_name.rb +25 -0
- data/lib/overcommit/hook/pre_commit/base.rb +19 -0
- data/lib/overcommit/hook/pre_commit/berksfile_check.rb +24 -0
- data/lib/overcommit/hook/pre_commit/broken_symlinks.rb +17 -0
- data/lib/overcommit/hook/pre_commit/bundle_audit.rb +24 -0
- data/lib/overcommit/hook/pre_commit/bundle_check.rb +32 -0
- data/lib/overcommit/hook/pre_commit/bundle_outdated.rb +25 -0
- data/lib/overcommit/hook/pre_commit/case_conflicts.rb +27 -0
- data/lib/overcommit/hook/pre_commit/chamber_compare.rb +43 -0
- data/lib/overcommit/hook/pre_commit/chamber_security.rb +15 -0
- data/lib/overcommit/hook/pre_commit/chamber_verification.rb +36 -0
- data/lib/overcommit/hook/pre_commit/code_spell_check.rb +36 -0
- data/lib/overcommit/hook/pre_commit/coffee_lint.rb +35 -0
- data/lib/overcommit/hook/pre_commit/cook_style.rb +35 -0
- data/lib/overcommit/hook/pre_commit/credo.rb +27 -0
- data/lib/overcommit/hook/pre_commit/css_lint.rb +26 -0
- data/lib/overcommit/hook/pre_commit/dogma.rb +33 -0
- data/lib/overcommit/hook/pre_commit/es_lint.rb +38 -0
- data/lib/overcommit/hook/pre_commit/execute_permissions.rb +76 -0
- data/lib/overcommit/hook/pre_commit/fasterer.rb +25 -0
- data/lib/overcommit/hook/pre_commit/file_size.rb +47 -0
- data/lib/overcommit/hook/pre_commit/fix_me.rb +17 -0
- data/lib/overcommit/hook/pre_commit/flay.rb +38 -0
- data/lib/overcommit/hook/pre_commit/foodcritic.rb +149 -0
- data/lib/overcommit/hook/pre_commit/forbidden_branches.rb +26 -0
- data/lib/overcommit/hook/pre_commit/ginkgo_focus.rb +23 -0
- data/lib/overcommit/hook/pre_commit/go_fmt.rb +17 -0
- data/lib/overcommit/hook/pre_commit/go_lint.rb +29 -0
- data/lib/overcommit/hook/pre_commit/go_vet.rb +24 -0
- data/lib/overcommit/hook/pre_commit/golangci_lint.rb +21 -0
- data/lib/overcommit/hook/pre_commit/hadolint.rb +27 -0
- data/lib/overcommit/hook/pre_commit/haml_lint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/hard_tabs.rb +15 -0
- data/lib/overcommit/hook/pre_commit/hlint.rb +34 -0
- data/lib/overcommit/hook/pre_commit/html_hint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/html_tidy.rb +30 -0
- data/lib/overcommit/hook/pre_commit/image_optim.rb +28 -0
- data/lib/overcommit/hook/pre_commit/java_checkstyle.rb +27 -0
- data/lib/overcommit/hook/pre_commit/js_hint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/js_lint.rb +22 -0
- data/lib/overcommit/hook/pre_commit/jscs.rb +27 -0
- data/lib/overcommit/hook/pre_commit/jsl.rb +28 -0
- data/lib/overcommit/hook/pre_commit/json_syntax.rb +21 -0
- data/lib/overcommit/hook/pre_commit/kt_lint.rb +19 -0
- data/lib/overcommit/hook/pre_commit/license_finder.rb +14 -0
- data/lib/overcommit/hook/pre_commit/license_header.rb +48 -0
- data/lib/overcommit/hook/pre_commit/line_endings.rb +77 -0
- data/lib/overcommit/hook/pre_commit/local_paths_in_gemfile.rb +16 -0
- data/lib/overcommit/hook/pre_commit/mdl.rb +29 -0
- data/lib/overcommit/hook/pre_commit/merge_conflicts.rb +16 -0
- data/lib/overcommit/hook/pre_commit/nginx_test.rb +26 -0
- data/lib/overcommit/hook/pre_commit/pep257.rb +23 -0
- data/lib/overcommit/hook/pre_commit/pep8.rb +23 -0
- data/lib/overcommit/hook/pre_commit/php_cs.rb +43 -0
- data/lib/overcommit/hook/pre_commit/php_cs_fixer.rb +57 -0
- data/lib/overcommit/hook/pre_commit/php_lint.rb +44 -0
- data/lib/overcommit/hook/pre_commit/php_stan.rb +30 -0
- data/lib/overcommit/hook/pre_commit/pronto.rb +12 -0
- data/lib/overcommit/hook/pre_commit/puppet_lint.rb +26 -0
- data/lib/overcommit/hook/pre_commit/puppet_metadata_json_lint.rb +29 -0
- data/lib/overcommit/hook/pre_commit/pycodestyle.rb +23 -0
- data/lib/overcommit/hook/pre_commit/pydocstyle.rb +23 -0
- data/lib/overcommit/hook/pre_commit/pyflakes.rb +32 -0
- data/lib/overcommit/hook/pre_commit/pylint.rb +32 -0
- data/lib/overcommit/hook/pre_commit/python_flake8.rb +32 -0
- data/lib/overcommit/hook/pre_commit/rails_best_practices.rb +34 -0
- data/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +58 -0
- data/lib/overcommit/hook/pre_commit/rake_target.rb +12 -0
- data/lib/overcommit/hook/pre_commit/reek.rb +26 -0
- data/lib/overcommit/hook/pre_commit/rst_lint.rb +27 -0
- data/lib/overcommit/hook/pre_commit/rubo_cop.rb +35 -0
- data/lib/overcommit/hook/pre_commit/ruby_lint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/ruby_syntax.rb +27 -0
- data/lib/overcommit/hook/pre_commit/scalariform.rb +22 -0
- data/lib/overcommit/hook/pre_commit/scalastyle.rb +31 -0
- data/lib/overcommit/hook/pre_commit/scss_lint.rb +43 -0
- data/lib/overcommit/hook/pre_commit/semi_standard.rb +23 -0
- data/lib/overcommit/hook/pre_commit/shell_check.rb +23 -0
- data/lib/overcommit/hook/pre_commit/slim_lint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/sqlint.rb +26 -0
- data/lib/overcommit/hook/pre_commit/standard.rb +23 -0
- data/lib/overcommit/hook/pre_commit/stylelint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/swift_lint.rb +19 -0
- data/lib/overcommit/hook/pre_commit/terraform_format.rb +19 -0
- data/lib/overcommit/hook/pre_commit/trailing_whitespace.rb +15 -0
- data/lib/overcommit/hook/pre_commit/travis_lint.rb +15 -0
- data/lib/overcommit/hook/pre_commit/ts_lint.rb +28 -0
- data/lib/overcommit/hook/pre_commit/vint.rb +22 -0
- data/lib/overcommit/hook/pre_commit/w3c_css.rb +67 -0
- data/lib/overcommit/hook/pre_commit/w3c_html.rb +64 -0
- data/lib/overcommit/hook/pre_commit/xml_lint.rb +24 -0
- data/lib/overcommit/hook/pre_commit/xml_syntax.rb +21 -0
- data/lib/overcommit/hook/pre_commit/yaml_lint.rb +18 -0
- data/lib/overcommit/hook/pre_commit/yaml_syntax.rb +20 -0
- data/lib/overcommit/hook/pre_commit/yard_coverage.rb +90 -0
- data/lib/overcommit/hook/pre_commit/yarn_check.rb +37 -0
- data/lib/overcommit/hook/pre_push/base.rb +33 -0
- data/lib/overcommit/hook/pre_push/brakeman.rb +15 -0
- data/lib/overcommit/hook/pre_push/cargo_test.rb +12 -0
- data/lib/overcommit/hook/pre_push/go_test.rb +14 -0
- data/lib/overcommit/hook/pre_push/golangci_lint.rb +16 -0
- data/lib/overcommit/hook/pre_push/minitest.rb +20 -0
- data/lib/overcommit/hook/pre_push/php_unit.rb +16 -0
- data/lib/overcommit/hook/pre_push/pronto.rb +12 -0
- data/lib/overcommit/hook/pre_push/protected_branches.rb +74 -0
- data/lib/overcommit/hook/pre_push/pytest.rb +16 -0
- data/lib/overcommit/hook/pre_push/python_nose.rb +16 -0
- data/lib/overcommit/hook/pre_push/r_spec.rb +16 -0
- data/lib/overcommit/hook/pre_push/rake_target.rb +12 -0
- data/lib/overcommit/hook/pre_push/test_unit.rb +16 -0
- data/lib/overcommit/hook/pre_rebase/base.rb +14 -0
- data/lib/overcommit/hook/pre_rebase/merged_commits.rb +31 -0
- data/lib/overcommit/hook/prepare_commit_msg/base.rb +25 -0
- data/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb +57 -0
- data/lib/overcommit/hook/shared/bower_install.rb +15 -0
- data/lib/overcommit/hook/shared/bundle_install.rb +15 -0
- data/lib/overcommit/hook/shared/composer_install.rb +15 -0
- data/lib/overcommit/hook/shared/index_tags.rb +14 -0
- data/lib/overcommit/hook/shared/npm_install.rb +15 -0
- data/lib/overcommit/hook/shared/pronto.rb +21 -0
- data/lib/overcommit/hook/shared/rake_target.rb +26 -0
- data/lib/overcommit/hook/shared/submodule_status.rb +32 -0
- data/lib/overcommit/hook/shared/yarn_install.rb +15 -0
- data/lib/overcommit/hook_context.rb +19 -0
- data/lib/overcommit/hook_context/base.rb +139 -0
- data/lib/overcommit/hook_context/commit_msg.rb +48 -0
- data/lib/overcommit/hook_context/post_checkout.rb +36 -0
- data/lib/overcommit/hook_context/post_commit.rb +33 -0
- data/lib/overcommit/hook_context/post_merge.rb +37 -0
- data/lib/overcommit/hook_context/post_rewrite.rb +49 -0
- data/lib/overcommit/hook_context/pre_commit.rb +212 -0
- data/lib/overcommit/hook_context/pre_push.rb +89 -0
- data/lib/overcommit/hook_context/pre_rebase.rb +38 -0
- data/lib/overcommit/hook_context/prepare_commit_msg.rb +34 -0
- data/lib/overcommit/hook_context/run_all.rb +48 -0
- data/lib/overcommit/hook_loader/base.rb +48 -0
- data/lib/overcommit/hook_loader/built_in_hook_loader.rb +14 -0
- data/lib/overcommit/hook_loader/plugin_hook_loader.rb +102 -0
- data/lib/overcommit/hook_runner.rb +219 -0
- data/lib/overcommit/hook_signer.rb +123 -0
- data/lib/overcommit/installer.rb +193 -0
- data/lib/overcommit/interrupt_handler.rb +91 -0
- data/lib/overcommit/logger.rb +92 -0
- data/lib/overcommit/message_processor.rb +148 -0
- data/lib/overcommit/os.rb +38 -0
- data/lib/overcommit/printer.rb +145 -0
- data/lib/overcommit/subprocess.rb +98 -0
- data/lib/overcommit/utils.rb +309 -0
- data/lib/overcommit/utils/file_utils.rb +71 -0
- data/lib/overcommit/utils/messages_utils.rb +77 -0
- data/lib/overcommit/version.rb +6 -0
- data/libexec/gerrit-change-id +174 -0
- data/libexec/index-tags +17 -0
- data/template-dir/hooks/commit-msg +116 -0
- data/template-dir/hooks/overcommit-hook +116 -0
- data/template-dir/hooks/post-checkout +116 -0
- data/template-dir/hooks/post-commit +116 -0
- data/template-dir/hooks/post-merge +116 -0
- data/template-dir/hooks/post-rewrite +116 -0
- data/template-dir/hooks/pre-commit +116 -0
- data/template-dir/hooks/pre-push +116 -0
- data/template-dir/hooks/pre-rebase +116 -0
- data/template-dir/hooks/prepare-commit-msg +116 -0
- metadata +303 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Returns the version of the available git binary.
|
|
4
|
+
#
|
|
5
|
+
# This is intended to be used to conveniently execute code based on a specific
|
|
6
|
+
# git version. Simply compare to a version string:
|
|
7
|
+
#
|
|
8
|
+
# @example
|
|
9
|
+
# if GIT_VERSION <= '1.8.5'
|
|
10
|
+
# ...
|
|
11
|
+
# end
|
|
12
|
+
module Overcommit
|
|
13
|
+
GIT_VERSION = begin
|
|
14
|
+
version = `git --version`.chomp[/\d+(\.\d+)+/, 0]
|
|
15
|
+
Overcommit::Utils::Version.new(version)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'forwardable'
|
|
4
|
+
require 'overcommit/message_processor'
|
|
5
|
+
|
|
6
|
+
# Container for top-level hook-related classes and constants.
|
|
7
|
+
module Overcommit::Hook
|
|
8
|
+
# Helper containing metadata about error/warning messages returned by hooks.
|
|
9
|
+
Message = Struct.new(:type, :file, :line, :content) do
|
|
10
|
+
def to_s
|
|
11
|
+
content
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Possible types of messages.
|
|
16
|
+
MESSAGE_TYPES = [:error, :warning].freeze
|
|
17
|
+
|
|
18
|
+
# Functionality common to all hooks.
|
|
19
|
+
class Base # rubocop:disable Metrics/ClassLength
|
|
20
|
+
extend Forwardable
|
|
21
|
+
|
|
22
|
+
def_delegators :@context, :all_files, :modified_files
|
|
23
|
+
attr_reader :config
|
|
24
|
+
|
|
25
|
+
# @param config [Overcommit::Configuration]
|
|
26
|
+
# @param context [Overcommit::HookContext]
|
|
27
|
+
def initialize(config, context)
|
|
28
|
+
@config = config.for_hook(self)
|
|
29
|
+
@context = context
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Runs the hook.
|
|
33
|
+
def run
|
|
34
|
+
raise NotImplementedError, 'Hook must define `run`'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Runs the hook and transforms the status returned based on the hook's
|
|
38
|
+
# configuration.
|
|
39
|
+
#
|
|
40
|
+
# Poorly named because we already have a bunch of hooks in the wild that
|
|
41
|
+
# implement `#run`, and we needed a wrapper step to transform the status
|
|
42
|
+
# based on any custom configuration.
|
|
43
|
+
def run_and_transform
|
|
44
|
+
if output = check_for_requirements
|
|
45
|
+
status = :fail
|
|
46
|
+
else
|
|
47
|
+
result = Overcommit::Utils.with_environment(@config.fetch('env') { {} }) { run }
|
|
48
|
+
status, output = process_hook_return_value(result)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
[transform_status(status), output]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def name
|
|
55
|
+
self.class.name.split('::').last
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def description
|
|
59
|
+
@config['description'] || "Run #{name}"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def required?
|
|
63
|
+
@config['required']
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def parallelize?
|
|
67
|
+
@config['parallelize'] != false
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def processors
|
|
71
|
+
@config.fetch('processors') { 1 }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def quiet?
|
|
75
|
+
@config['quiet']
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def enabled?
|
|
79
|
+
@config['enabled'] != false
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def excluded?
|
|
83
|
+
exclude_branches.any? { |p| File.fnmatch(p, current_branch) }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def skip?
|
|
87
|
+
@config['skip'] ||
|
|
88
|
+
(@config['skip_if'] ? execute(@config['skip_if']).success? : false)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def run?
|
|
92
|
+
enabled? &&
|
|
93
|
+
!excluded? &&
|
|
94
|
+
!(@config['requires_files'] && applicable_files.empty?)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def in_path?(cmd)
|
|
98
|
+
Overcommit::Utils.in_path?(cmd)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Execute a command in a separate process.
|
|
102
|
+
#
|
|
103
|
+
# If `splittable_args` is specified, ensures that those arguments are
|
|
104
|
+
# concatenated onto the end of the `cmd` arguments, but split up so that the
|
|
105
|
+
# operating system's maximum command length is not exceeded. This is useful
|
|
106
|
+
# for splitting up long file lists.
|
|
107
|
+
#
|
|
108
|
+
# @param cmd [Array<String>] command arguments
|
|
109
|
+
# @param options [Hash]
|
|
110
|
+
# @option options [Array<String>] :args arguments that can be split up over
|
|
111
|
+
# multiple invocations (usually a list of files)
|
|
112
|
+
# @option options [String] :input string to pass to process' standard input
|
|
113
|
+
# stream
|
|
114
|
+
# @return [#status,#stdout,#stderr] struct containing result of invocation
|
|
115
|
+
def execute(cmd, options = {})
|
|
116
|
+
Overcommit::Utils.execute(cmd, options)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def execute_in_background(cmd)
|
|
120
|
+
Overcommit::Utils.execute_in_background(cmd)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def required_executable
|
|
124
|
+
@config['required_executable']
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def required_libraries
|
|
128
|
+
Array(@config['required_library'] || @config['required_libraries'])
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Return command to execute for this hook.
|
|
132
|
+
#
|
|
133
|
+
# This is intended to be configurable so hooks can prefix their commands
|
|
134
|
+
# with `bundle exec` or similar. It will appends the command line flags
|
|
135
|
+
# specified by the `flags` option after.
|
|
136
|
+
#
|
|
137
|
+
# Note that any files intended to be passed must be handled by the hook
|
|
138
|
+
# itself.
|
|
139
|
+
#
|
|
140
|
+
# @return [Array<String>]
|
|
141
|
+
def command
|
|
142
|
+
Array(@config['command'] || required_executable) + flags
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Return command line flags to be passed to the command.
|
|
146
|
+
#
|
|
147
|
+
# This excludes the list of files, as that must be handled by the hook
|
|
148
|
+
# itself.
|
|
149
|
+
#
|
|
150
|
+
# The intention here is to provide flexibility for when a tool
|
|
151
|
+
# removes/renames its flags. Rather than wait for Overcommit to update the
|
|
152
|
+
# flags it uses, you can update your configuration to use the new flags
|
|
153
|
+
# right away without being blocked.
|
|
154
|
+
#
|
|
155
|
+
# Also note that any flags containing dynamic content must be passed in the
|
|
156
|
+
# hook's {#run} method.
|
|
157
|
+
#
|
|
158
|
+
# @return [Array<String>]
|
|
159
|
+
def flags
|
|
160
|
+
Array(@config['flags'])
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# Gets a list of staged files that apply to this hook based on its
|
|
164
|
+
# configured `include` and `exclude` lists.
|
|
165
|
+
def applicable_files
|
|
166
|
+
@applicable_files ||= select_applicable(modified_files)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# Gets a list of all files that apply to this hook based on its
|
|
170
|
+
# configured `include` and `exclude` lists.
|
|
171
|
+
def included_files
|
|
172
|
+
@included_files ||= select_applicable(all_files)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
private
|
|
176
|
+
|
|
177
|
+
def select_applicable(list)
|
|
178
|
+
list.select { |file| applicable_file?(file) }.sort
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def applicable_file?(file)
|
|
182
|
+
includes = Array(@config['include']).flatten.map do |glob|
|
|
183
|
+
Overcommit::Utils.convert_glob_to_absolute(glob)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
included = includes.empty? || includes.any? do |glob|
|
|
187
|
+
Overcommit::Utils.matches_path?(glob, file)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
excludes = Array(@config['exclude']).flatten.map do |glob|
|
|
191
|
+
Overcommit::Utils.convert_glob_to_absolute(glob)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
excluded = excludes.any? do |glob|
|
|
195
|
+
Overcommit::Utils.matches_path?(glob, file)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
included && !excluded
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
# Check for any required executables or libraries.
|
|
202
|
+
#
|
|
203
|
+
# Returns output if any requirements are not met.
|
|
204
|
+
def check_for_requirements
|
|
205
|
+
check_for_executable || check_for_libraries
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
# If the hook defines a required executable, check if it's in the path and
|
|
209
|
+
# display the install command if one exists.
|
|
210
|
+
def check_for_executable
|
|
211
|
+
return unless required_executable && !in_path?(required_executable)
|
|
212
|
+
|
|
213
|
+
"'#{required_executable}' is not installed, not in your PATH, " \
|
|
214
|
+
"or does not have execute permissions#{install_command_prompt}"
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def install_command_prompt
|
|
218
|
+
if install_command = @config['install_command']
|
|
219
|
+
"\nInstall it by running: #{install_command}"
|
|
220
|
+
else
|
|
221
|
+
''
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
# If the hook defines required library paths that it wants to load, attempt
|
|
226
|
+
# to load them.
|
|
227
|
+
def check_for_libraries
|
|
228
|
+
output = []
|
|
229
|
+
|
|
230
|
+
required_libraries.each do |library|
|
|
231
|
+
begin
|
|
232
|
+
require library
|
|
233
|
+
rescue LoadError
|
|
234
|
+
install_command = @config['install_command']
|
|
235
|
+
install_command = " -- install via #{install_command}" if install_command
|
|
236
|
+
|
|
237
|
+
output << "Unable to load '#{library}'#{install_command}"
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
return if output.empty?
|
|
242
|
+
|
|
243
|
+
output.join("\n")
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# Converts the hook's return value into a canonical form of a tuple
|
|
247
|
+
# containing status (pass/warn/fail) and output.
|
|
248
|
+
#
|
|
249
|
+
# This is intended to support various shortcuts for writing hooks so that
|
|
250
|
+
# hook authors don't need to work with {Overcommit::Hook::Message} objects
|
|
251
|
+
# for simple pass/fail hooks. It also saves you from needing to manually
|
|
252
|
+
# encode logic like "if there are errors, fail; if there are warnings, warn,
|
|
253
|
+
# otherwise pass." by simply returning an array of
|
|
254
|
+
# {Overcommit::Hook::Message} objects.
|
|
255
|
+
#
|
|
256
|
+
# @param hook_return_value [Symbol, Array<Symbol,String>, Array<Message>]
|
|
257
|
+
# @return [Array<Symbol,String>] tuple of status and output
|
|
258
|
+
def process_hook_return_value(hook_return_value)
|
|
259
|
+
if hook_return_value.is_a?(Array) &&
|
|
260
|
+
(hook_return_value.first.is_a?(Message) || hook_return_value.empty?)
|
|
261
|
+
# Process messages into a status and output
|
|
262
|
+
Overcommit::MessageProcessor.new(
|
|
263
|
+
self,
|
|
264
|
+
@config['problem_on_unmodified_line'],
|
|
265
|
+
).hook_result(hook_return_value)
|
|
266
|
+
else
|
|
267
|
+
# Otherwise return as-is
|
|
268
|
+
hook_return_value
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
# Transforms the hook's status based on custom configuration.
|
|
273
|
+
#
|
|
274
|
+
# This allows users to change failures into warnings, or vice versa.
|
|
275
|
+
def transform_status(status)
|
|
276
|
+
case status
|
|
277
|
+
when :fail
|
|
278
|
+
@config.fetch('on_fail') { :fail }.to_sym
|
|
279
|
+
when :warn
|
|
280
|
+
@config.fetch('on_warn') { :warn }.to_sym
|
|
281
|
+
else
|
|
282
|
+
status
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def exclude_branches
|
|
287
|
+
@config['exclude_branches'] || []
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
def current_branch
|
|
291
|
+
@current_branch ||= Overcommit::GitRepo.current_branch
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'forwardable'
|
|
4
|
+
|
|
5
|
+
module Overcommit::Hook::CommitMsg
|
|
6
|
+
# Functionality common to all commit-msg hooks.
|
|
7
|
+
class Base < Overcommit::Hook::Base
|
|
8
|
+
extend Forwardable
|
|
9
|
+
|
|
10
|
+
def_delegators :@context, :empty_message?, :commit_message,
|
|
11
|
+
:update_commit_message, :commit_message_lines,
|
|
12
|
+
:commit_message_file
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::CommitMsg
|
|
4
|
+
# Ensures commit message subject lines start with a capital letter.
|
|
5
|
+
class CapitalizedSubject < Base
|
|
6
|
+
def run
|
|
7
|
+
return :pass if empty_message?
|
|
8
|
+
|
|
9
|
+
# Git treats the first non-empty line as the subject
|
|
10
|
+
subject = commit_message_lines.find { |line| !line.strip.empty? }.to_s
|
|
11
|
+
first_letter = subject.match(/^[[:punct:]]*(.)/)[1]
|
|
12
|
+
unless special_prefix?(subject) || first_letter =~ /[[:upper:]]/
|
|
13
|
+
return :warn, 'Subject should start with a capital letter'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
:pass
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def special_prefix?(subject)
|
|
22
|
+
subject =~ /^(fixup|squash)!/
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::CommitMsg
|
|
4
|
+
# Checks that the commit message is not empty
|
|
5
|
+
class EmptyMessage < Base
|
|
6
|
+
def run
|
|
7
|
+
return :pass unless empty_message?
|
|
8
|
+
|
|
9
|
+
[:fail, 'Commit message should not be empty']
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::CommitMsg
|
|
4
|
+
# Ensures a Gerrit Change-Id line is included in the commit message.
|
|
5
|
+
#
|
|
6
|
+
# It may seem odd to do this here instead of in a prepare-commit-msg hook, but
|
|
7
|
+
# the reality is that if you want to _ensure_ the Change-Id is included then
|
|
8
|
+
# you need to do it in a commit-msg hook. This is because the user could still
|
|
9
|
+
# edit the message after a prepare-commit-msg hook was run.
|
|
10
|
+
#
|
|
11
|
+
# @see https://code.google.com/p/gerrit/
|
|
12
|
+
class GerritChangeId < Base
|
|
13
|
+
SCRIPT_LOCATION = Overcommit::Utils.script_path('gerrit-change-id')
|
|
14
|
+
|
|
15
|
+
def run
|
|
16
|
+
result = execute(['sh', SCRIPT_LOCATION, commit_message_file])
|
|
17
|
+
return :pass if result.success?
|
|
18
|
+
|
|
19
|
+
[:fail, result.stdout]
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::CommitMsg
|
|
4
|
+
# Checks for hard tabs in commit messages.
|
|
5
|
+
class HardTabs < Base
|
|
6
|
+
def run
|
|
7
|
+
return :pass if empty_message?
|
|
8
|
+
|
|
9
|
+
# Catches hard tabs entered by the user (not auto-generated)
|
|
10
|
+
if commit_message.index(/\t/)
|
|
11
|
+
return :warn, "Don't use hard tabs in commit messages"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
:pass
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::CommitMsg
|
|
4
|
+
# Ensures the commit message follows a specific format.
|
|
5
|
+
class MessageFormat < Base
|
|
6
|
+
def run
|
|
7
|
+
error_msg = validate_pattern(commit_message_lines.join("\n"))
|
|
8
|
+
return :fail, error_msg if error_msg
|
|
9
|
+
|
|
10
|
+
:pass
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def validate_pattern(message)
|
|
16
|
+
pattern = config['pattern']
|
|
17
|
+
return if pattern.empty?
|
|
18
|
+
|
|
19
|
+
expected_pattern_message = config['expected_pattern_message']
|
|
20
|
+
sample_message = config['sample_message']
|
|
21
|
+
|
|
22
|
+
unless message.match?(/#{pattern}/m)
|
|
23
|
+
[
|
|
24
|
+
'Commit message pattern mismatch.',
|
|
25
|
+
"Expected : #{expected_pattern_message}",
|
|
26
|
+
"Sample : #{sample_message}"
|
|
27
|
+
].join("\n")
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::CommitMsg
|
|
4
|
+
# Checks for long commit messages (not good or bad--just fun to point out)
|
|
5
|
+
class RussianNovel < Base
|
|
6
|
+
RUSSIAN_NOVEL_LENGTH = 30
|
|
7
|
+
|
|
8
|
+
def run
|
|
9
|
+
if commit_message_lines.length >= RUSSIAN_NOVEL_LENGTH
|
|
10
|
+
return :warn, 'You seem to have authored a Russian novel; congratulations!'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
:pass
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|