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,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Check if local yarn.lock matches package.json when either changes, unless
|
|
5
|
+
# yarn.lock is ignored by git.
|
|
6
|
+
#
|
|
7
|
+
# @see https://yarnpkg.com/en/docs/cli/check
|
|
8
|
+
class YarnCheck < Base
|
|
9
|
+
LOCK_FILE = 'yarn.lock'
|
|
10
|
+
|
|
11
|
+
# A lot of the errors returned by `yarn check` are outside the developer's control
|
|
12
|
+
# (are caused by bad package specification, in the hands of the upstream maintainer)
|
|
13
|
+
# So limit reporting to errors the developer can do something about
|
|
14
|
+
ACTIONABLE_ERRORS = [
|
|
15
|
+
'Lockfile does not contain pattern',
|
|
16
|
+
].freeze
|
|
17
|
+
|
|
18
|
+
def run
|
|
19
|
+
# Ignore if yarn.lock is not tracked by git
|
|
20
|
+
ignored_files = execute(%w[git ls-files -o -i --exclude-standard]).stdout.split("\n")
|
|
21
|
+
return :pass if ignored_files.include?(LOCK_FILE)
|
|
22
|
+
|
|
23
|
+
previous_lockfile = File.exist?(LOCK_FILE) ? File.read(LOCK_FILE) : nil
|
|
24
|
+
result = execute(command)
|
|
25
|
+
new_lockfile = File.exist?(LOCK_FILE) ? File.read(LOCK_FILE) : nil
|
|
26
|
+
|
|
27
|
+
# `yarn check` also throws many warnings, which should be ignored here
|
|
28
|
+
errors_regex = Regexp.new("^error (.*)(#{ACTIONABLE_ERRORS.join('|')})(.*)$")
|
|
29
|
+
errors = errors_regex.match(result.stderr)
|
|
30
|
+
unless errors.nil? && previous_lockfile == new_lockfile
|
|
31
|
+
return :fail, "#{LOCK_FILE} is not up-to-date -- run `yarn install`"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
:pass
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'forwardable'
|
|
4
|
+
require 'overcommit/utils/messages_utils'
|
|
5
|
+
|
|
6
|
+
module Overcommit::Hook::PrePush
|
|
7
|
+
# Functionality common to all pre-push hooks.
|
|
8
|
+
class Base < Overcommit::Hook::Base
|
|
9
|
+
extend Forwardable
|
|
10
|
+
|
|
11
|
+
def_delegators :@context, :remote_name, :remote_url, :pushed_refs
|
|
12
|
+
|
|
13
|
+
def run?
|
|
14
|
+
super &&
|
|
15
|
+
!exclude_remotes.include?(remote_name) &&
|
|
16
|
+
(include_remote_ref_deletions? || !@context.remote_ref_deletion?)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def extract_messages(*args)
|
|
22
|
+
Overcommit::Utils::MessagesUtils.extract_messages(*args)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def exclude_remotes
|
|
26
|
+
@config['exclude_remotes'] || []
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def include_remote_ref_deletions?
|
|
30
|
+
@config['include_remote_ref_deletions']
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PrePush
|
|
4
|
+
# Runs `brakeman` whenever Ruby/Rails files change.
|
|
5
|
+
#
|
|
6
|
+
# @see http://brakemanscanner.org/
|
|
7
|
+
class Brakeman < Base
|
|
8
|
+
def run
|
|
9
|
+
result = execute(command)
|
|
10
|
+
return :pass if result.success?
|
|
11
|
+
|
|
12
|
+
[:fail, result.stdout]
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PrePush
|
|
4
|
+
# Runs `cargo test` before push if Rust files changed
|
|
5
|
+
class CargoTest < Base
|
|
6
|
+
def run
|
|
7
|
+
result = execute(command)
|
|
8
|
+
return :pass if result.success?
|
|
9
|
+
[:fail, result.stdout]
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PrePush
|
|
4
|
+
# Runs `go test ./...` command on prepush
|
|
5
|
+
class GoTest < Base
|
|
6
|
+
def run
|
|
7
|
+
result = execute(command)
|
|
8
|
+
return :pass if result.success?
|
|
9
|
+
|
|
10
|
+
output = result.stdout + result.stderr
|
|
11
|
+
[:fail, output]
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PrePush
|
|
4
|
+
# Runs golangci-lint
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/golangci/golangci-lint
|
|
7
|
+
class GolangciLint < Base
|
|
8
|
+
def run
|
|
9
|
+
result = execute(command)
|
|
10
|
+
return :pass if result.success?
|
|
11
|
+
|
|
12
|
+
output = result.stdout + result.stderr
|
|
13
|
+
[:fail, output]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PrePush
|
|
4
|
+
# Runs `minitest` test suite before push
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/seattlerb/minitest
|
|
7
|
+
class Minitest < Base
|
|
8
|
+
def run
|
|
9
|
+
result = execute(command)
|
|
10
|
+
return :pass if result.success?
|
|
11
|
+
|
|
12
|
+
output = result.stdout + result.stderr
|
|
13
|
+
[:fail, output]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def command
|
|
17
|
+
super + included_files.map { |file| "-r#{file}" }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PrePush
|
|
4
|
+
# Runs `phpunit` test suite before push
|
|
5
|
+
#
|
|
6
|
+
# @see https://phpunit.de/
|
|
7
|
+
class PhpUnit < Base
|
|
8
|
+
def run
|
|
9
|
+
result = execute(command)
|
|
10
|
+
return :pass if result.success?
|
|
11
|
+
|
|
12
|
+
output = result.stdout + result.stderr
|
|
13
|
+
[:fail, output]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PrePush
|
|
4
|
+
# Prevents updates to specified branches.
|
|
5
|
+
# Accepts a 'destructive_only' option globally or per branch
|
|
6
|
+
# to only prevent destructive updates.
|
|
7
|
+
class ProtectedBranches < Base
|
|
8
|
+
def run
|
|
9
|
+
return :pass unless illegal_pushes.any?
|
|
10
|
+
|
|
11
|
+
messages = illegal_pushes.map do |pushed_ref|
|
|
12
|
+
"Deleting or force-pushing to #{pushed_ref.remote_ref} is not allowed."
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
[:fail, messages.join("\n")]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def illegal_pushes
|
|
21
|
+
@illegal_pushes ||= pushed_refs.select do |pushed_ref|
|
|
22
|
+
protected?(pushed_ref)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def protected?(ref)
|
|
27
|
+
find_pattern(ref.remote_ref)&.destructive?(ref)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def find_pattern(remote_ref)
|
|
31
|
+
ref_name = remote_ref[%r{refs/heads/(.*)}, 1]
|
|
32
|
+
return if ref_name.nil?
|
|
33
|
+
|
|
34
|
+
patterns.find do |pattern|
|
|
35
|
+
File.fnmatch(pattern.to_s, ref_name)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def patterns
|
|
40
|
+
@patterns ||= fetch_patterns
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def fetch_patterns
|
|
44
|
+
branch_configurations.map do |pattern|
|
|
45
|
+
if pattern.is_a?(Hash)
|
|
46
|
+
Pattern.new(pattern.keys.first, pattern['destructive_only'])
|
|
47
|
+
else
|
|
48
|
+
Pattern.new(pattern, global_destructive_only?)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def branch_configurations
|
|
54
|
+
config['branches'].to_a + config['branch_patterns'].to_a
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def global_destructive_only?
|
|
58
|
+
config['destructive_only'].nil? || config['destructive_only']
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
Pattern = Struct.new('Pattern', :name, :destructive_only) do
|
|
62
|
+
alias_method :to_s, :name
|
|
63
|
+
alias_method :destructive_only?, :destructive_only
|
|
64
|
+
|
|
65
|
+
def destructive?(ref)
|
|
66
|
+
if destructive_only?
|
|
67
|
+
ref.destructive?
|
|
68
|
+
else
|
|
69
|
+
true
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PrePush
|
|
4
|
+
# Runs `pytest` test suite before push
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/pytest-dev/pytest
|
|
7
|
+
class Pytest < Base
|
|
8
|
+
def run
|
|
9
|
+
result = execute(command)
|
|
10
|
+
return :pass if result.success?
|
|
11
|
+
|
|
12
|
+
output = result.stdout + result.stderr
|
|
13
|
+
[:fail, output]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PrePush
|
|
4
|
+
# Runs `nose` test suite before push
|
|
5
|
+
#
|
|
6
|
+
# @see https://nose.readthedocs.io/en/latest/
|
|
7
|
+
class PythonNose < Base
|
|
8
|
+
def run
|
|
9
|
+
result = execute(command)
|
|
10
|
+
return :pass if result.success?
|
|
11
|
+
|
|
12
|
+
output = result.stdout + result.stderr
|
|
13
|
+
[:fail, output]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PrePush
|
|
4
|
+
# Runs `rspec` test suite before push
|
|
5
|
+
#
|
|
6
|
+
# @see http://rspec.info/
|
|
7
|
+
class RSpec < Base
|
|
8
|
+
def run
|
|
9
|
+
result = execute(command)
|
|
10
|
+
return :pass if result.success?
|
|
11
|
+
|
|
12
|
+
output = result.stdout + result.stderr
|
|
13
|
+
[:fail, output]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'overcommit/hook/shared/rake_target'
|
|
4
|
+
|
|
5
|
+
module Overcommit::Hook::PrePush
|
|
6
|
+
# Runs rake targets
|
|
7
|
+
#
|
|
8
|
+
# @see Overcommit::Hook::Shared::RakeTarget
|
|
9
|
+
class RakeTarget < Base
|
|
10
|
+
include Overcommit::Hook::Shared::RakeTarget
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PrePush
|
|
4
|
+
# Runs `test-unit` test suite before push
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/test-unit/test-unit
|
|
7
|
+
class TestUnit < Base
|
|
8
|
+
def run
|
|
9
|
+
result = execute(command)
|
|
10
|
+
return :pass if result.success?
|
|
11
|
+
|
|
12
|
+
output = result.stdout + result.stderr
|
|
13
|
+
[:fail, output]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'forwardable'
|
|
4
|
+
|
|
5
|
+
module Overcommit::Hook::PreRebase
|
|
6
|
+
# Functionality common to all pre-rebase hooks.
|
|
7
|
+
class Base < Overcommit::Hook::Base
|
|
8
|
+
extend Forwardable
|
|
9
|
+
|
|
10
|
+
def_delegators :@context,
|
|
11
|
+
:upstream_branch, :rebased_branch, :detached_head?,
|
|
12
|
+
:fast_forward?, :rebased_commits
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreRebase
|
|
4
|
+
# Prevents rebasing commits that have already been merged into one of
|
|
5
|
+
# a specified set of branches.
|
|
6
|
+
class MergedCommits < Base
|
|
7
|
+
def run
|
|
8
|
+
# Allow rebasing a detached HEAD since no refs are changed.
|
|
9
|
+
return :pass if detached_head? || illegal_commits.empty?
|
|
10
|
+
|
|
11
|
+
message = 'Cannot rebase commits that have already been merged into ' \
|
|
12
|
+
"one of #{branches.join(', ')}"
|
|
13
|
+
|
|
14
|
+
[:fail, message]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def branches
|
|
20
|
+
@branches ||= config['branches']
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def illegal_commits
|
|
24
|
+
@illegal_commits ||= rebased_commits.select do |commit_sha1|
|
|
25
|
+
branches_containing_commit =
|
|
26
|
+
Overcommit::GitRepo.branches_containing_commit(commit_sha1)
|
|
27
|
+
(branches_containing_commit & branches).any?
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'forwardable'
|
|
4
|
+
|
|
5
|
+
module Overcommit::Hook::PrepareCommitMsg
|
|
6
|
+
# Functionality common to all prepare-commit-msg hooks.
|
|
7
|
+
class Base < Overcommit::Hook::Base
|
|
8
|
+
extend Forwardable
|
|
9
|
+
|
|
10
|
+
def_delegators :@context,
|
|
11
|
+
:commit_message_filename, :commit_message_source, :commit, :lock
|
|
12
|
+
|
|
13
|
+
def modify_commit_message
|
|
14
|
+
raise 'This expects a block!' unless block_given?
|
|
15
|
+
# NOTE: this assumes all the hooks of the same type share the context's
|
|
16
|
+
# memory. If that's not the case, this won't work.
|
|
17
|
+
lock.synchronize do
|
|
18
|
+
contents = File.read(commit_message_filename)
|
|
19
|
+
File.open(commit_message_filename, 'w') do |f|
|
|
20
|
+
f << (yield contents)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PrepareCommitMsg
|
|
4
|
+
# Prepends the commit message with a message based on the branch name.
|
|
5
|
+
# It's possible to reference parts of the branch name through the captures in
|
|
6
|
+
# the `branch_pattern` regex.
|
|
7
|
+
class ReplaceBranch < Base
|
|
8
|
+
def run
|
|
9
|
+
return :pass if skipped_commit_types.include? commit_message_source
|
|
10
|
+
|
|
11
|
+
Overcommit::Utils.log.debug(
|
|
12
|
+
"Checking if '#{Overcommit::GitRepo.current_branch}' matches #{branch_pattern}"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
return :warn unless branch_pattern.match?(Overcommit::GitRepo.current_branch)
|
|
16
|
+
|
|
17
|
+
Overcommit::Utils.log.debug("Writing #{commit_message_filename} with #{new_template}")
|
|
18
|
+
|
|
19
|
+
modify_commit_message do |old_contents|
|
|
20
|
+
"#{new_template} #{old_contents}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
:pass
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def new_template
|
|
27
|
+
@new_template ||= Overcommit::GitRepo.current_branch.gsub(branch_pattern, replacement_text)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def branch_pattern
|
|
31
|
+
@branch_pattern ||=
|
|
32
|
+
begin
|
|
33
|
+
pattern = config['branch_pattern']
|
|
34
|
+
Regexp.new((pattern || '').empty? ? '\A.*\w+[-_](\d+).*\z' : pattern)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def replacement_text
|
|
39
|
+
@replacement_text ||=
|
|
40
|
+
begin
|
|
41
|
+
if File.exist?(replacement_text_config)
|
|
42
|
+
File.read(replacement_text_config)
|
|
43
|
+
else
|
|
44
|
+
replacement_text_config
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def replacement_text_config
|
|
50
|
+
@replacement_text_config ||= config['replacement_text']
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def skipped_commit_types
|
|
54
|
+
@skipped_commit_types ||= config['skipped_commit_types'].map(&:to_sym)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|