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,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::Shared
|
|
4
|
+
# Shared code used by all BowerInstall hooks. Runs `bower install` when a
|
|
5
|
+
# change is detected in the repository's dependencies.
|
|
6
|
+
#
|
|
7
|
+
# @see http://bower.io/
|
|
8
|
+
module BowerInstall
|
|
9
|
+
def run
|
|
10
|
+
result = execute(command)
|
|
11
|
+
return :fail, result.stderr unless result.success?
|
|
12
|
+
:pass
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::Shared
|
|
4
|
+
# Shared code used by all BundleInstall hooks. Runs `bundle install` when a
|
|
5
|
+
# change is detected in the repository's dependencies.
|
|
6
|
+
#
|
|
7
|
+
# @see http://bundler.io/
|
|
8
|
+
module BundleInstall
|
|
9
|
+
def run
|
|
10
|
+
result = execute(command)
|
|
11
|
+
return :fail, result.stdout unless result.success?
|
|
12
|
+
:pass
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::Shared
|
|
4
|
+
# Shared code used by all ComposerInstall hooks. Runs `composer install` when
|
|
5
|
+
# a change is detected in the repository's dependencies.
|
|
6
|
+
#
|
|
7
|
+
# @see https://getcomposer.org/
|
|
8
|
+
module ComposerInstall
|
|
9
|
+
def run
|
|
10
|
+
result = execute(command)
|
|
11
|
+
return :fail, result.stdout unless result.success?
|
|
12
|
+
:pass
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::Shared
|
|
4
|
+
# Shared code used by all IndexTags hooks. It runs ctags in the background so
|
|
5
|
+
# your tag definitions are up-to-date.
|
|
6
|
+
#
|
|
7
|
+
# @see http://ctags.sourceforge.net/
|
|
8
|
+
module IndexTags
|
|
9
|
+
def run
|
|
10
|
+
execute_in_background([Overcommit::Utils.script_path('index-tags')])
|
|
11
|
+
:pass
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::Shared
|
|
4
|
+
# Shared code used by all NpmInstall hooks. Runs `npm install` when a change
|
|
5
|
+
# is detected in the repository's dependencies.
|
|
6
|
+
#
|
|
7
|
+
# @see https://www.npmjs.com/
|
|
8
|
+
module NpmInstall
|
|
9
|
+
def run
|
|
10
|
+
result = execute(command)
|
|
11
|
+
return :fail, result.stderr unless result.success?
|
|
12
|
+
:pass
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::Shared
|
|
4
|
+
# Shared code used by all Pronto hooks. Runs pronto linter.
|
|
5
|
+
module Pronto
|
|
6
|
+
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
|
|
7
|
+
type.include?('E') ? :error : :warning
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def run
|
|
11
|
+
result = execute(command)
|
|
12
|
+
return :pass if result.success?
|
|
13
|
+
|
|
14
|
+
extract_messages(
|
|
15
|
+
result.stdout.split("\n"),
|
|
16
|
+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+) (?<type>[^ ]+)/,
|
|
17
|
+
MESSAGE_TYPE_CATEGORIZER,
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::Shared
|
|
4
|
+
# runs specified rake targets. It fails on the first non-
|
|
5
|
+
# successful exit.
|
|
6
|
+
#
|
|
7
|
+
module RakeTarget
|
|
8
|
+
def run
|
|
9
|
+
targets = config['targets']
|
|
10
|
+
|
|
11
|
+
if Array(targets).empty?
|
|
12
|
+
raise 'RakeTarget: targets parameter is empty. Add at least one task to ' \
|
|
13
|
+
'the targets parameter. Valid: Array of target names or String of ' \
|
|
14
|
+
'target names'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
targets.each do |task|
|
|
18
|
+
result = execute(command + [task])
|
|
19
|
+
unless result.success?
|
|
20
|
+
return :fail, "Rake target #{task}:\n#{result.stdout}"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
:pass
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::Shared
|
|
4
|
+
# Shared code used by all `SubmoduleStatus` hooks to notify the user if any
|
|
5
|
+
# submodules are uninitialized, out of date with the current index, or contain
|
|
6
|
+
# merge conflicts.
|
|
7
|
+
module SubmoduleStatus
|
|
8
|
+
def run
|
|
9
|
+
messages = []
|
|
10
|
+
submodule_statuses.each do |submodule_status|
|
|
11
|
+
path = submodule_status.path
|
|
12
|
+
if submodule_status.uninitialized?
|
|
13
|
+
messages << "Submodule #{path} is uninitialized."
|
|
14
|
+
elsif submodule_status.outdated?
|
|
15
|
+
messages << "Submodule #{path} is out of date with the current index."
|
|
16
|
+
elsif submodule_status.merge_conflict?
|
|
17
|
+
messages << "Submodule #{path} has merge conflicts."
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
return :pass if messages.empty?
|
|
22
|
+
|
|
23
|
+
[:warn, messages.join("\n")]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def submodule_statuses
|
|
29
|
+
Overcommit::GitRepo.submodule_statuses(recursive: config['recursive'])
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::Shared
|
|
4
|
+
# Shared code used by all YarnInstall hooks. Runs `yarn install` when a change
|
|
5
|
+
# is detected in the repository's dependencies.
|
|
6
|
+
#
|
|
7
|
+
# @see https://yarnpkg.com/
|
|
8
|
+
module YarnInstall
|
|
9
|
+
def run
|
|
10
|
+
result = execute(command)
|
|
11
|
+
return :fail, result.stderr unless result.success?
|
|
12
|
+
:pass
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Utility module which manages the creation of {HookContext}s.
|
|
4
|
+
module Overcommit::HookContext
|
|
5
|
+
def self.create(hook_type, config, args, input)
|
|
6
|
+
hook_type_class = Overcommit::Utils.camel_case(hook_type)
|
|
7
|
+
underscored_hook_type = Overcommit::Utils.snake_case(hook_type)
|
|
8
|
+
|
|
9
|
+
require "overcommit/hook_context/#{underscored_hook_type}"
|
|
10
|
+
|
|
11
|
+
Overcommit::HookContext.const_get(hook_type_class).new(config, args, input)
|
|
12
|
+
rescue LoadError, NameError => error
|
|
13
|
+
# Could happen when a symlink was created for a hook type Overcommit does
|
|
14
|
+
# not yet support.
|
|
15
|
+
raise Overcommit::Exceptions::HookContextLoadError,
|
|
16
|
+
"Unable to load '#{hook_type}' hook context: '#{error}'",
|
|
17
|
+
error.backtrace
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::HookContext
|
|
4
|
+
# Contains helpers related to the context with which a hook is being run.
|
|
5
|
+
#
|
|
6
|
+
# It acts as an adapter to the arguments passed to the hook, as well as
|
|
7
|
+
# context-specific information such as staged files, providing a single source
|
|
8
|
+
# of truth for this context.
|
|
9
|
+
#
|
|
10
|
+
# This is also important to house in a separate object so that any
|
|
11
|
+
# calculations can be memoized across all hooks in a single object, which
|
|
12
|
+
# helps with performance.
|
|
13
|
+
#
|
|
14
|
+
# @abstract
|
|
15
|
+
class Base
|
|
16
|
+
# Creates a hook context from the given configuration and input options.
|
|
17
|
+
#
|
|
18
|
+
# @param config [Overcommit::Configuration]
|
|
19
|
+
# @param args [Array<String>]
|
|
20
|
+
# @param input [IO] standard input stream
|
|
21
|
+
def initialize(config, args, input)
|
|
22
|
+
@config = config
|
|
23
|
+
@args = args
|
|
24
|
+
@input = input
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Executes a command as if it were a regular git hook, passing all
|
|
28
|
+
# command-line arguments and the standard input stream.
|
|
29
|
+
#
|
|
30
|
+
# This is intended to be used by ad hoc hooks so developers can link up
|
|
31
|
+
# their existing git hooks with Overcommit.
|
|
32
|
+
def execute_hook(command)
|
|
33
|
+
Overcommit::Utils.execute(command, args: @args, input: input_string)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Returns the camel-cased type of this hook (e.g. PreCommit)
|
|
37
|
+
#
|
|
38
|
+
# @return [String]
|
|
39
|
+
def hook_class_name
|
|
40
|
+
self.class.name.split('::').last
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Returns the snake-cased type of this hook (e.g. pre_commit)
|
|
44
|
+
#
|
|
45
|
+
# @return [String]
|
|
46
|
+
def hook_type_name
|
|
47
|
+
Overcommit::Utils.snake_case(hook_class_name)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Returns the actual name of the hook script being run (e.g. pre-commit).
|
|
51
|
+
#
|
|
52
|
+
# @return [String]
|
|
53
|
+
def hook_script_name
|
|
54
|
+
hook_type_name.tr('_', '-')
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Initializes anything related to the environment.
|
|
58
|
+
#
|
|
59
|
+
# This is called before the hooks are run by the [HookRunner]. Different
|
|
60
|
+
# hook types can perform different setup.
|
|
61
|
+
def setup_environment
|
|
62
|
+
# Implemented by subclass, if applicable
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Resets the environment to an appropriate state.
|
|
66
|
+
#
|
|
67
|
+
# This is called after the hooks have been run by the [HookRunner].
|
|
68
|
+
# Different hook types can perform different cleanup operations, which are
|
|
69
|
+
# intended to "undo" the results of the call to {#setup_environment}.
|
|
70
|
+
def cleanup_environment
|
|
71
|
+
# Implemented by subclass, if applicable
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Returns a list of files that have been modified.
|
|
75
|
+
#
|
|
76
|
+
# By default, this returns an empty list. Subclasses should implement if
|
|
77
|
+
# there is a concept of files changing for the type of hook being run.
|
|
78
|
+
#
|
|
79
|
+
# @return [Array<String>]
|
|
80
|
+
def modified_files
|
|
81
|
+
[]
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Returns the full list of files tracked by git
|
|
85
|
+
#
|
|
86
|
+
# @return [Array<String>]
|
|
87
|
+
def all_files
|
|
88
|
+
Overcommit::GitRepo.all_files
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Returns the contents of the entire standard input stream that were passed
|
|
92
|
+
# to the hook.
|
|
93
|
+
#
|
|
94
|
+
# @return [String]
|
|
95
|
+
def input_string
|
|
96
|
+
@input_string ||= @input.read
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Returns an array of lines passed to the hook via the standard input
|
|
100
|
+
# stream.
|
|
101
|
+
#
|
|
102
|
+
# @return [Array<String>]
|
|
103
|
+
def input_lines
|
|
104
|
+
@input_lines ||= input_string.split("\n")
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Returns a message to display on failure.
|
|
108
|
+
#
|
|
109
|
+
# @return [String]
|
|
110
|
+
def post_fail_message
|
|
111
|
+
nil
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
private
|
|
115
|
+
|
|
116
|
+
def filter_modified_files(modified_files)
|
|
117
|
+
filter_directories(filter_nonexistent(modified_files))
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Filter out non-existent files (unless it's a broken symlink, in which case
|
|
121
|
+
# it's a file that points to a non-existent file). This could happen if a
|
|
122
|
+
# file was renamed as part of an amendment, leading to the old file no
|
|
123
|
+
# longer existing.
|
|
124
|
+
def filter_nonexistent(modified_files)
|
|
125
|
+
modified_files.select do |file|
|
|
126
|
+
File.exist?(file) || Overcommit::Utils.broken_symlink?(file)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Filter out directories. This could happen when changing a symlink to a
|
|
131
|
+
# directory as part of an amendment, since the symlink will still appear as
|
|
132
|
+
# a file, but the actual working tree will have a directory.
|
|
133
|
+
def filter_directories(modified_files)
|
|
134
|
+
modified_files.reject do |file|
|
|
135
|
+
File.directory?(file) && !Overcommit::Utils::FileUtils.symlink?(file)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::HookContext
|
|
4
|
+
# Contains helpers related to contextual information used by commit-msg hooks.
|
|
5
|
+
class CommitMsg < Base
|
|
6
|
+
def empty_message?
|
|
7
|
+
commit_message.strip.empty?
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# User commit message stripped of comments and diff (from verbose output).
|
|
11
|
+
def commit_message
|
|
12
|
+
commit_message_lines.join
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Updates the commit message to the specified text.
|
|
16
|
+
def update_commit_message(message)
|
|
17
|
+
::File.open(commit_message_file, 'w') do |file|
|
|
18
|
+
file.write(message)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def commit_message_lines
|
|
23
|
+
raw_commit_message_lines.
|
|
24
|
+
take_while { |line| !line.start_with?('diff --git') }.
|
|
25
|
+
reject { |line| line.start_with?(comment_character) }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def comment_character
|
|
29
|
+
@comment_character ||= Overcommit::GitConfig.comment_character
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def commit_message_file
|
|
33
|
+
@args[0]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def post_fail_message
|
|
37
|
+
"Failed commit message:\n#{commit_message_lines.join.chomp}\n\n" \
|
|
38
|
+
"Try again with your existing commit message by running:\n" \
|
|
39
|
+
"git commit --edit --file=#{commit_message_file}"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def raw_commit_message_lines
|
|
45
|
+
::IO.readlines(commit_message_file)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::HookContext
|
|
4
|
+
# Contains helpers related to contextual information used by post-checkout
|
|
5
|
+
# hooks.
|
|
6
|
+
class PostCheckout < Base
|
|
7
|
+
# Returns the ref of the HEAD that we transitioned from.
|
|
8
|
+
def previous_head
|
|
9
|
+
@args[0]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Returns the ref of the new current HEAD.
|
|
13
|
+
def new_head
|
|
14
|
+
@args[1]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Returns whether this checkout was the result of changing/updating a
|
|
18
|
+
# branch.
|
|
19
|
+
def branch_checkout?
|
|
20
|
+
@args[2].to_i == 1
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Returns whether this checkout was for a single file.
|
|
24
|
+
def file_checkout?
|
|
25
|
+
!branch_checkout?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Get a list of files that have been added or modified between
|
|
29
|
+
# `previous_head` and `new_head`. Renames and deletions are ignored, since
|
|
30
|
+
# there should be nothing to check.
|
|
31
|
+
def modified_files
|
|
32
|
+
@modified_files ||=
|
|
33
|
+
Overcommit::GitRepo.modified_files(refs: "#{previous_head} #{new_head}")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::HookContext
|
|
4
|
+
# Contains helpers related to contextual information used by post-commit
|
|
5
|
+
# hooks.
|
|
6
|
+
class PostCommit < Base
|
|
7
|
+
# Get a list of files that were added, copied, or modified in the last
|
|
8
|
+
# commit. Renames and deletions are ignored, since there should be nothing
|
|
9
|
+
# to check.
|
|
10
|
+
def modified_files
|
|
11
|
+
subcmd = 'show --format=%n'
|
|
12
|
+
@modified_files ||= Overcommit::GitRepo.modified_files(subcmd: subcmd)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Returns the set of line numbers corresponding to the lines that were
|
|
16
|
+
# changed in a specified file.
|
|
17
|
+
def modified_lines_in_file(file)
|
|
18
|
+
subcmd = 'show --format=%n'
|
|
19
|
+
@modified_lines ||= {}
|
|
20
|
+
@modified_lines[file] ||=
|
|
21
|
+
Overcommit::GitRepo.extract_modified_lines(file, subcmd: subcmd)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Returns whether the commit that triggered this hook is the first commit on
|
|
25
|
+
# the branch.
|
|
26
|
+
#
|
|
27
|
+
# @return [true,false]
|
|
28
|
+
def initial_commit?
|
|
29
|
+
return @initial_commit unless @initial_commit.nil?
|
|
30
|
+
@initial_commit = !Overcommit::Utils.execute(%w[git rev-parse HEAD~]).success?
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|