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.
Files changed (226) hide show
  1. checksums.yaml +7 -0
  2. data/bin/overcommit +50 -0
  3. data/config/default.yml +1356 -0
  4. data/config/starter.yml +33 -0
  5. data/lib/overcommit.rb +26 -0
  6. data/lib/overcommit/cli.rb +223 -0
  7. data/lib/overcommit/command_splitter.rb +146 -0
  8. data/lib/overcommit/configuration.rb +350 -0
  9. data/lib/overcommit/configuration_loader.rb +96 -0
  10. data/lib/overcommit/configuration_validator.rb +186 -0
  11. data/lib/overcommit/constants.rb +12 -0
  12. data/lib/overcommit/exceptions.rb +52 -0
  13. data/lib/overcommit/git_config.rb +22 -0
  14. data/lib/overcommit/git_repo.rb +286 -0
  15. data/lib/overcommit/git_version.rb +17 -0
  16. data/lib/overcommit/hook/base.rb +294 -0
  17. data/lib/overcommit/hook/commit_msg/base.rb +14 -0
  18. data/lib/overcommit/hook/commit_msg/capitalized_subject.rb +25 -0
  19. data/lib/overcommit/hook/commit_msg/empty_message.rb +12 -0
  20. data/lib/overcommit/hook/commit_msg/gerrit_change_id.rb +22 -0
  21. data/lib/overcommit/hook/commit_msg/hard_tabs.rb +17 -0
  22. data/lib/overcommit/hook/commit_msg/message_format.rb +31 -0
  23. data/lib/overcommit/hook/commit_msg/russian_novel.rb +16 -0
  24. data/lib/overcommit/hook/commit_msg/single_line_subject.rb +16 -0
  25. data/lib/overcommit/hook/commit_msg/spell_check.rb +45 -0
  26. data/lib/overcommit/hook/commit_msg/text_width.rb +56 -0
  27. data/lib/overcommit/hook/commit_msg/trailing_period.rb +16 -0
  28. data/lib/overcommit/hook/post_checkout/base.rb +22 -0
  29. data/lib/overcommit/hook/post_checkout/bower_install.rb +13 -0
  30. data/lib/overcommit/hook/post_checkout/bundle_install.rb +13 -0
  31. data/lib/overcommit/hook/post_checkout/composer_install.rb +13 -0
  32. data/lib/overcommit/hook/post_checkout/index_tags.rb +12 -0
  33. data/lib/overcommit/hook/post_checkout/npm_install.rb +13 -0
  34. data/lib/overcommit/hook/post_checkout/submodule_status.rb +12 -0
  35. data/lib/overcommit/hook/post_checkout/yarn_install.rb +13 -0
  36. data/lib/overcommit/hook/post_commit/base.rb +12 -0
  37. data/lib/overcommit/hook/post_commit/bower_install.rb +13 -0
  38. data/lib/overcommit/hook/post_commit/bundle_install.rb +13 -0
  39. data/lib/overcommit/hook/post_commit/commitplease.rb +16 -0
  40. data/lib/overcommit/hook/post_commit/composer_install.rb +13 -0
  41. data/lib/overcommit/hook/post_commit/git_guilt.rb +43 -0
  42. data/lib/overcommit/hook/post_commit/index_tags.rb +12 -0
  43. data/lib/overcommit/hook/post_commit/npm_install.rb +13 -0
  44. data/lib/overcommit/hook/post_commit/submodule_status.rb +12 -0
  45. data/lib/overcommit/hook/post_commit/yarn_install.rb +13 -0
  46. data/lib/overcommit/hook/post_merge/base.rb +12 -0
  47. data/lib/overcommit/hook/post_merge/bower_install.rb +13 -0
  48. data/lib/overcommit/hook/post_merge/bundle_install.rb +13 -0
  49. data/lib/overcommit/hook/post_merge/composer_install.rb +13 -0
  50. data/lib/overcommit/hook/post_merge/index_tags.rb +12 -0
  51. data/lib/overcommit/hook/post_merge/npm_install.rb +13 -0
  52. data/lib/overcommit/hook/post_merge/submodule_status.rb +12 -0
  53. data/lib/overcommit/hook/post_merge/yarn_install.rb +13 -0
  54. data/lib/overcommit/hook/post_rewrite/base.rb +12 -0
  55. data/lib/overcommit/hook/post_rewrite/bower_install.rb +13 -0
  56. data/lib/overcommit/hook/post_rewrite/bundle_install.rb +13 -0
  57. data/lib/overcommit/hook/post_rewrite/composer_install.rb +13 -0
  58. data/lib/overcommit/hook/post_rewrite/index_tags.rb +19 -0
  59. data/lib/overcommit/hook/post_rewrite/npm_install.rb +13 -0
  60. data/lib/overcommit/hook/post_rewrite/submodule_status.rb +12 -0
  61. data/lib/overcommit/hook/post_rewrite/yarn_install.rb +13 -0
  62. data/lib/overcommit/hook/pre_commit/author_email.rb +26 -0
  63. data/lib/overcommit/hook/pre_commit/author_name.rb +25 -0
  64. data/lib/overcommit/hook/pre_commit/base.rb +19 -0
  65. data/lib/overcommit/hook/pre_commit/berksfile_check.rb +24 -0
  66. data/lib/overcommit/hook/pre_commit/broken_symlinks.rb +17 -0
  67. data/lib/overcommit/hook/pre_commit/bundle_audit.rb +24 -0
  68. data/lib/overcommit/hook/pre_commit/bundle_check.rb +32 -0
  69. data/lib/overcommit/hook/pre_commit/bundle_outdated.rb +25 -0
  70. data/lib/overcommit/hook/pre_commit/case_conflicts.rb +27 -0
  71. data/lib/overcommit/hook/pre_commit/chamber_compare.rb +43 -0
  72. data/lib/overcommit/hook/pre_commit/chamber_security.rb +15 -0
  73. data/lib/overcommit/hook/pre_commit/chamber_verification.rb +36 -0
  74. data/lib/overcommit/hook/pre_commit/code_spell_check.rb +36 -0
  75. data/lib/overcommit/hook/pre_commit/coffee_lint.rb +35 -0
  76. data/lib/overcommit/hook/pre_commit/cook_style.rb +35 -0
  77. data/lib/overcommit/hook/pre_commit/credo.rb +27 -0
  78. data/lib/overcommit/hook/pre_commit/css_lint.rb +26 -0
  79. data/lib/overcommit/hook/pre_commit/dogma.rb +33 -0
  80. data/lib/overcommit/hook/pre_commit/es_lint.rb +38 -0
  81. data/lib/overcommit/hook/pre_commit/execute_permissions.rb +76 -0
  82. data/lib/overcommit/hook/pre_commit/fasterer.rb +25 -0
  83. data/lib/overcommit/hook/pre_commit/file_size.rb +47 -0
  84. data/lib/overcommit/hook/pre_commit/fix_me.rb +17 -0
  85. data/lib/overcommit/hook/pre_commit/flay.rb +38 -0
  86. data/lib/overcommit/hook/pre_commit/foodcritic.rb +149 -0
  87. data/lib/overcommit/hook/pre_commit/forbidden_branches.rb +26 -0
  88. data/lib/overcommit/hook/pre_commit/ginkgo_focus.rb +23 -0
  89. data/lib/overcommit/hook/pre_commit/go_fmt.rb +17 -0
  90. data/lib/overcommit/hook/pre_commit/go_lint.rb +29 -0
  91. data/lib/overcommit/hook/pre_commit/go_vet.rb +24 -0
  92. data/lib/overcommit/hook/pre_commit/golangci_lint.rb +21 -0
  93. data/lib/overcommit/hook/pre_commit/hadolint.rb +27 -0
  94. data/lib/overcommit/hook/pre_commit/haml_lint.rb +23 -0
  95. data/lib/overcommit/hook/pre_commit/hard_tabs.rb +15 -0
  96. data/lib/overcommit/hook/pre_commit/hlint.rb +34 -0
  97. data/lib/overcommit/hook/pre_commit/html_hint.rb +23 -0
  98. data/lib/overcommit/hook/pre_commit/html_tidy.rb +30 -0
  99. data/lib/overcommit/hook/pre_commit/image_optim.rb +28 -0
  100. data/lib/overcommit/hook/pre_commit/java_checkstyle.rb +27 -0
  101. data/lib/overcommit/hook/pre_commit/js_hint.rb +23 -0
  102. data/lib/overcommit/hook/pre_commit/js_lint.rb +22 -0
  103. data/lib/overcommit/hook/pre_commit/jscs.rb +27 -0
  104. data/lib/overcommit/hook/pre_commit/jsl.rb +28 -0
  105. data/lib/overcommit/hook/pre_commit/json_syntax.rb +21 -0
  106. data/lib/overcommit/hook/pre_commit/kt_lint.rb +19 -0
  107. data/lib/overcommit/hook/pre_commit/license_finder.rb +14 -0
  108. data/lib/overcommit/hook/pre_commit/license_header.rb +48 -0
  109. data/lib/overcommit/hook/pre_commit/line_endings.rb +77 -0
  110. data/lib/overcommit/hook/pre_commit/local_paths_in_gemfile.rb +16 -0
  111. data/lib/overcommit/hook/pre_commit/mdl.rb +29 -0
  112. data/lib/overcommit/hook/pre_commit/merge_conflicts.rb +16 -0
  113. data/lib/overcommit/hook/pre_commit/nginx_test.rb +26 -0
  114. data/lib/overcommit/hook/pre_commit/pep257.rb +23 -0
  115. data/lib/overcommit/hook/pre_commit/pep8.rb +23 -0
  116. data/lib/overcommit/hook/pre_commit/php_cs.rb +43 -0
  117. data/lib/overcommit/hook/pre_commit/php_cs_fixer.rb +57 -0
  118. data/lib/overcommit/hook/pre_commit/php_lint.rb +44 -0
  119. data/lib/overcommit/hook/pre_commit/php_stan.rb +30 -0
  120. data/lib/overcommit/hook/pre_commit/pronto.rb +12 -0
  121. data/lib/overcommit/hook/pre_commit/puppet_lint.rb +26 -0
  122. data/lib/overcommit/hook/pre_commit/puppet_metadata_json_lint.rb +29 -0
  123. data/lib/overcommit/hook/pre_commit/pycodestyle.rb +23 -0
  124. data/lib/overcommit/hook/pre_commit/pydocstyle.rb +23 -0
  125. data/lib/overcommit/hook/pre_commit/pyflakes.rb +32 -0
  126. data/lib/overcommit/hook/pre_commit/pylint.rb +32 -0
  127. data/lib/overcommit/hook/pre_commit/python_flake8.rb +32 -0
  128. data/lib/overcommit/hook/pre_commit/rails_best_practices.rb +34 -0
  129. data/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +58 -0
  130. data/lib/overcommit/hook/pre_commit/rake_target.rb +12 -0
  131. data/lib/overcommit/hook/pre_commit/reek.rb +26 -0
  132. data/lib/overcommit/hook/pre_commit/rst_lint.rb +27 -0
  133. data/lib/overcommit/hook/pre_commit/rubo_cop.rb +35 -0
  134. data/lib/overcommit/hook/pre_commit/ruby_lint.rb +23 -0
  135. data/lib/overcommit/hook/pre_commit/ruby_syntax.rb +27 -0
  136. data/lib/overcommit/hook/pre_commit/scalariform.rb +22 -0
  137. data/lib/overcommit/hook/pre_commit/scalastyle.rb +31 -0
  138. data/lib/overcommit/hook/pre_commit/scss_lint.rb +43 -0
  139. data/lib/overcommit/hook/pre_commit/semi_standard.rb +23 -0
  140. data/lib/overcommit/hook/pre_commit/shell_check.rb +23 -0
  141. data/lib/overcommit/hook/pre_commit/slim_lint.rb +23 -0
  142. data/lib/overcommit/hook/pre_commit/sqlint.rb +26 -0
  143. data/lib/overcommit/hook/pre_commit/standard.rb +23 -0
  144. data/lib/overcommit/hook/pre_commit/stylelint.rb +23 -0
  145. data/lib/overcommit/hook/pre_commit/swift_lint.rb +19 -0
  146. data/lib/overcommit/hook/pre_commit/terraform_format.rb +19 -0
  147. data/lib/overcommit/hook/pre_commit/trailing_whitespace.rb +15 -0
  148. data/lib/overcommit/hook/pre_commit/travis_lint.rb +15 -0
  149. data/lib/overcommit/hook/pre_commit/ts_lint.rb +28 -0
  150. data/lib/overcommit/hook/pre_commit/vint.rb +22 -0
  151. data/lib/overcommit/hook/pre_commit/w3c_css.rb +67 -0
  152. data/lib/overcommit/hook/pre_commit/w3c_html.rb +64 -0
  153. data/lib/overcommit/hook/pre_commit/xml_lint.rb +24 -0
  154. data/lib/overcommit/hook/pre_commit/xml_syntax.rb +21 -0
  155. data/lib/overcommit/hook/pre_commit/yaml_lint.rb +18 -0
  156. data/lib/overcommit/hook/pre_commit/yaml_syntax.rb +20 -0
  157. data/lib/overcommit/hook/pre_commit/yard_coverage.rb +90 -0
  158. data/lib/overcommit/hook/pre_commit/yarn_check.rb +37 -0
  159. data/lib/overcommit/hook/pre_push/base.rb +33 -0
  160. data/lib/overcommit/hook/pre_push/brakeman.rb +15 -0
  161. data/lib/overcommit/hook/pre_push/cargo_test.rb +12 -0
  162. data/lib/overcommit/hook/pre_push/go_test.rb +14 -0
  163. data/lib/overcommit/hook/pre_push/golangci_lint.rb +16 -0
  164. data/lib/overcommit/hook/pre_push/minitest.rb +20 -0
  165. data/lib/overcommit/hook/pre_push/php_unit.rb +16 -0
  166. data/lib/overcommit/hook/pre_push/pronto.rb +12 -0
  167. data/lib/overcommit/hook/pre_push/protected_branches.rb +74 -0
  168. data/lib/overcommit/hook/pre_push/pytest.rb +16 -0
  169. data/lib/overcommit/hook/pre_push/python_nose.rb +16 -0
  170. data/lib/overcommit/hook/pre_push/r_spec.rb +16 -0
  171. data/lib/overcommit/hook/pre_push/rake_target.rb +12 -0
  172. data/lib/overcommit/hook/pre_push/test_unit.rb +16 -0
  173. data/lib/overcommit/hook/pre_rebase/base.rb +14 -0
  174. data/lib/overcommit/hook/pre_rebase/merged_commits.rb +31 -0
  175. data/lib/overcommit/hook/prepare_commit_msg/base.rb +25 -0
  176. data/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb +57 -0
  177. data/lib/overcommit/hook/shared/bower_install.rb +15 -0
  178. data/lib/overcommit/hook/shared/bundle_install.rb +15 -0
  179. data/lib/overcommit/hook/shared/composer_install.rb +15 -0
  180. data/lib/overcommit/hook/shared/index_tags.rb +14 -0
  181. data/lib/overcommit/hook/shared/npm_install.rb +15 -0
  182. data/lib/overcommit/hook/shared/pronto.rb +21 -0
  183. data/lib/overcommit/hook/shared/rake_target.rb +26 -0
  184. data/lib/overcommit/hook/shared/submodule_status.rb +32 -0
  185. data/lib/overcommit/hook/shared/yarn_install.rb +15 -0
  186. data/lib/overcommit/hook_context.rb +19 -0
  187. data/lib/overcommit/hook_context/base.rb +139 -0
  188. data/lib/overcommit/hook_context/commit_msg.rb +48 -0
  189. data/lib/overcommit/hook_context/post_checkout.rb +36 -0
  190. data/lib/overcommit/hook_context/post_commit.rb +33 -0
  191. data/lib/overcommit/hook_context/post_merge.rb +37 -0
  192. data/lib/overcommit/hook_context/post_rewrite.rb +49 -0
  193. data/lib/overcommit/hook_context/pre_commit.rb +212 -0
  194. data/lib/overcommit/hook_context/pre_push.rb +89 -0
  195. data/lib/overcommit/hook_context/pre_rebase.rb +38 -0
  196. data/lib/overcommit/hook_context/prepare_commit_msg.rb +34 -0
  197. data/lib/overcommit/hook_context/run_all.rb +48 -0
  198. data/lib/overcommit/hook_loader/base.rb +48 -0
  199. data/lib/overcommit/hook_loader/built_in_hook_loader.rb +14 -0
  200. data/lib/overcommit/hook_loader/plugin_hook_loader.rb +102 -0
  201. data/lib/overcommit/hook_runner.rb +219 -0
  202. data/lib/overcommit/hook_signer.rb +123 -0
  203. data/lib/overcommit/installer.rb +193 -0
  204. data/lib/overcommit/interrupt_handler.rb +91 -0
  205. data/lib/overcommit/logger.rb +92 -0
  206. data/lib/overcommit/message_processor.rb +148 -0
  207. data/lib/overcommit/os.rb +38 -0
  208. data/lib/overcommit/printer.rb +145 -0
  209. data/lib/overcommit/subprocess.rb +98 -0
  210. data/lib/overcommit/utils.rb +309 -0
  211. data/lib/overcommit/utils/file_utils.rb +71 -0
  212. data/lib/overcommit/utils/messages_utils.rb +77 -0
  213. data/lib/overcommit/version.rb +6 -0
  214. data/libexec/gerrit-change-id +174 -0
  215. data/libexec/index-tags +17 -0
  216. data/template-dir/hooks/commit-msg +116 -0
  217. data/template-dir/hooks/overcommit-hook +116 -0
  218. data/template-dir/hooks/post-checkout +116 -0
  219. data/template-dir/hooks/post-commit +116 -0
  220. data/template-dir/hooks/post-merge +116 -0
  221. data/template-dir/hooks/post-rewrite +116 -0
  222. data/template-dir/hooks/pre-commit +116 -0
  223. data/template-dir/hooks/pre-push +116 -0
  224. data/template-dir/hooks/pre-rebase +116 -0
  225. data/template-dir/hooks/prepare-commit-msg +116 -0
  226. metadata +303 -0
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'overcommit/os'
4
+ require 'overcommit/subprocess'
5
+
6
+ module Overcommit::Utils
7
+ # Utility functions for file IO.
8
+ module FileUtils
9
+ class << self
10
+ # When the host OS is Windows, uses the `mklink` command to create an
11
+ # NTFS symbolic link from `new_name` to `old_name`. Otherwise delegates
12
+ # to `File.symlink`
13
+ def symlink(old_name, new_name)
14
+ return File.symlink(old_name, new_name) unless Overcommit::OS.windows?
15
+
16
+ result = win32_mklink_cmd(old_name, new_name)
17
+ result.status
18
+ end
19
+
20
+ # When the host OS is Windows, uses the `dir` command to check whether
21
+ # `file_name` is an NTFS symbolic link. Otherwise delegates to
22
+ # `File.symlink`.
23
+ def symlink?(file_name)
24
+ return File.symlink?(file_name) unless Overcommit::OS.windows?
25
+
26
+ result = win32_dir_cmd(file_name)
27
+ win32_symlink?(result.stdout)
28
+ end
29
+
30
+ # When the host OS is Windows, uses the `dir` command to check whether
31
+ # `link_name` is an NTFS symbolic link. If so, it parses the target from
32
+ # the command output. Otherwise raises an `ArgumentError`. Delegates to
33
+ # `File.readlink` if the host OS is not Windows.
34
+ def readlink(link_name)
35
+ return File.readlink(link_name) unless Overcommit::OS.windows?
36
+
37
+ result = win32_dir_cmd(link_name)
38
+
39
+ unless win32_symlink?(result.stdout)
40
+ raise ArgumentError, "#{link_name} is not a symlink"
41
+ end
42
+
43
+ # Extract symlink target from output, which looks like:
44
+ # 11/13/2012 12:53 AM <SYMLINK> mysymlink [C:\Windows\Temp\somefile.txt]
45
+ result.stdout[/\[(.+)\]/, 1]
46
+ end
47
+
48
+ private
49
+
50
+ def win32_dir_cmd(file_name)
51
+ Overcommit::Subprocess.spawn(
52
+ %W[dir #{win32_fix_pathsep(file_name)}]
53
+ )
54
+ end
55
+
56
+ def win32_mklink_cmd(old_name, new_name)
57
+ Overcommit::Subprocess.spawn(
58
+ %W[mklink #{win32_fix_pathsep(new_name)} #{win32_fix_pathsep(old_name)}]
59
+ )
60
+ end
61
+
62
+ def win32_fix_pathsep(path)
63
+ path.tr(File::SEPARATOR, Overcommit::OS::SEPARATOR)
64
+ end
65
+
66
+ def win32_symlink?(dir_output)
67
+ !(dir_output =~ /<SYMLINK>/).nil?
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Utils
4
+ # Utility to process messages
5
+ module MessagesUtils
6
+ class << self
7
+ # Extract file, line number, and type of message from an error/warning
8
+ # messages in output.
9
+ #
10
+ # Assumes each element of `output` is a separate error/warning with all
11
+ # information necessary to identify it.
12
+ #
13
+ # @param output_messages [Array<String>] unprocessed error/warning messages
14
+ # @param regex [Regexp] regular expression defining `file`, `line` and
15
+ # `type` capture groups used to extract file locations and error/warning
16
+ # type from each line of output
17
+ # @param type_categorizer [Proc] function executed against the `type`
18
+ # capture group to convert it to a `:warning` or `:error` symbol. Assumes
19
+ # `:error` if `nil`.
20
+ # @raise [Overcommit::Exceptions::MessageProcessingError] line of output did
21
+ # not match regex
22
+ # @return [Array<Message>]
23
+ def extract_messages(output_messages, regex, type_categorizer = nil)
24
+ output_messages.map.with_index do |message, index|
25
+ unless match = message.match(regex)
26
+ raise Overcommit::Exceptions::MessageProcessingError,
27
+ 'Unexpected output: unable to determine line number or type ' \
28
+ "of error/warning for output:\n" \
29
+ "#{output_messages[index..-1].join("\n")}"
30
+ end
31
+
32
+ file = extract_file(match, message)
33
+ line = extract_line(match, message) if match.names.include?('line') && match[:line]
34
+ type = extract_type(match, message, type_categorizer)
35
+
36
+ Overcommit::Hook::Message.new(type, file, line, message)
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def extract_file(match, message)
43
+ return unless match.names.include?('file')
44
+
45
+ if match[:file].to_s.empty?
46
+ raise Overcommit::Exceptions::MessageProcessingError,
47
+ "Unexpected output: no file found in '#{message}'"
48
+ end
49
+
50
+ match[:file]
51
+ end
52
+
53
+ def extract_line(match, message)
54
+ return unless match.names.include?('line')
55
+ Integer(match[:line])
56
+ rescue ArgumentError, TypeError
57
+ raise Overcommit::Exceptions::MessageProcessingError,
58
+ "Unexpected output: invalid line number found in '#{message}'"
59
+ end
60
+
61
+ def extract_type(match, message, type_categorizer)
62
+ if type_categorizer
63
+ type_match = match.names.include?('type') ? match[:type] : nil
64
+ type = type_categorizer.call(type_match)
65
+ unless Overcommit::Hook::MESSAGE_TYPES.include?(type)
66
+ raise Overcommit::Exceptions::MessageProcessingError,
67
+ "Invalid message type '#{type}' for '#{message}': must " \
68
+ "be one of #{Overcommit::Hook::MESSAGE_TYPES.inspect}"
69
+ end
70
+ type
71
+ else
72
+ :error # Assume error since no categorizer was defined
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the gem version.
4
+ module Overcommit
5
+ VERSION = '0.53.1'
6
+ end
@@ -0,0 +1,174 @@
1
+ #!/bin/sh
2
+ # From Gerrit Code Review 2.5.1
3
+ #
4
+ # Part of Gerrit Code Review (http://code.google.com/p/gerrit/)
5
+ #
6
+ # Copyright (C) 2009 The Android Open Source Project
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ CHANGE_ID_AFTER="Bug|Issue|Story"
22
+ MSG="$1"
23
+
24
+ # Check for, and add if missing, a unique Change-Id
25
+ #
26
+ add_ChangeId() {
27
+ clean_message=`sed -e '
28
+ /^diff --git a\/.*/{
29
+ s///
30
+ q
31
+ }
32
+ /^Signed-off-by:/d
33
+ /^#/d
34
+ ' "$MSG" | git stripspace`
35
+ if test -z "$clean_message"
36
+ then
37
+ return
38
+ fi
39
+
40
+ # Does Change-Id: already exist? if so, exit (no change).
41
+ if grep -i '^Change-Id:' "$MSG" >/dev/null
42
+ then
43
+ return
44
+ fi
45
+
46
+ id=`_gen_ChangeId`
47
+ T="$MSG.tmp.$$"
48
+ AWK=awk
49
+ if [ -x /usr/xpg4/bin/awk ]; then
50
+ # Solaris AWK is just too broken
51
+ AWK=/usr/xpg4/bin/awk
52
+ fi
53
+
54
+ # How this works:
55
+ # - parse the commit message as (textLine+ blankLine*)*
56
+ # - assume textLine+ to be a footer until proven otherwise
57
+ # - exception: the first block is not footer (as it is the title)
58
+ # - read textLine+ into a variable
59
+ # - then count blankLines
60
+ # - once the next textLine appears, print textLine+ blankLine* as these
61
+ # aren't footer
62
+ # - in END, the last textLine+ block is available for footer parsing
63
+ $AWK '
64
+ BEGIN {
65
+ # while we start with the assumption that textLine+
66
+ # is a footer, the first block is not.
67
+ isFooter = 0
68
+ footerComment = 0
69
+ blankLines = 0
70
+ }
71
+
72
+ # Skip lines starting with "#" without any spaces before it.
73
+ /^#/ { next }
74
+
75
+ # Skip the line starting with the diff command and everything after it,
76
+ # up to the end of the file, assuming it is only patch data.
77
+ # If more than one line before the diff was empty, strip all but one.
78
+ /^diff --git a/ {
79
+ blankLines = 0
80
+ while (getline) { }
81
+ next
82
+ }
83
+
84
+ # Count blank lines outside footer comments
85
+ /^$/ && (footerComment == 0) {
86
+ blankLines++
87
+ next
88
+ }
89
+
90
+ # Catch footer comment
91
+ /^\[[a-zA-Z0-9-]+:/ && (isFooter == 1) {
92
+ footerComment = 1
93
+ }
94
+
95
+ /]$/ && (footerComment == 1) {
96
+ footerComment = 2
97
+ }
98
+
99
+ # We have a non-blank line after blank lines. Handle this.
100
+ (blankLines > 0) {
101
+ print lines
102
+ for (i = 0; i < blankLines; i++) {
103
+ print ""
104
+ }
105
+
106
+ lines = ""
107
+ blankLines = 0
108
+ isFooter = 1
109
+ footerComment = 0
110
+ }
111
+
112
+ # Detect that the current block is not the footer
113
+ (footerComment == 0) && (!/^\[?[a-zA-Z0-9-]+:/ || /^[a-zA-Z0-9-]+:\/\//) {
114
+ isFooter = 0
115
+ }
116
+
117
+ {
118
+ # We need this information about the current last comment line
119
+ if (footerComment == 2) {
120
+ footerComment = 0
121
+ }
122
+ if (lines != "") {
123
+ lines = lines "\n";
124
+ }
125
+ lines = lines $0
126
+ }
127
+
128
+ # Footer handling:
129
+ # If the last block is considered a footer, splice in the Change-Id at the
130
+ # right place.
131
+ # Look for the right place to inject Change-Id by considering
132
+ # CHANGE_ID_AFTER. Keys listed in it (case insensitive) come first,
133
+ # then Change-Id, then everything else (eg. Signed-off-by:).
134
+ #
135
+ # Otherwise just print the last block, a new line and the Change-Id as a
136
+ # block of its own.
137
+ END {
138
+ unprinted = 1
139
+ if (isFooter == 0) {
140
+ print lines "\n"
141
+ lines = ""
142
+ }
143
+ changeIdAfter = "^(" tolower("'"$CHANGE_ID_AFTER"'") "):"
144
+ numlines = split(lines, footer, "\n")
145
+ for (line = 1; line <= numlines; line++) {
146
+ if (unprinted && match(tolower(footer[line]), changeIdAfter) != 1) {
147
+ unprinted = 0
148
+ print "Change-Id: I'"$id"'"
149
+ }
150
+ print footer[line]
151
+ }
152
+ if (unprinted) {
153
+ print "Change-Id: I'"$id"'"
154
+ }
155
+ }' "$MSG" > $T && mv $T "$MSG" || rm -f $T
156
+ }
157
+ _gen_ChangeIdInput() {
158
+ echo "tree `git write-tree`"
159
+ if parent=`git rev-parse "HEAD^0" 2>/dev/null`
160
+ then
161
+ echo "parent $parent"
162
+ fi
163
+ echo "author `git var GIT_AUTHOR_IDENT`"
164
+ echo "committer `git var GIT_COMMITTER_IDENT`"
165
+ echo
166
+ printf '%s' "$clean_message"
167
+ }
168
+ _gen_ChangeId() {
169
+ _gen_ChangeIdInput |
170
+ git hash-object -t commit --stdin
171
+ }
172
+
173
+
174
+ add_ChangeId
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+ # Indexes all tags for this repository for easy navigation with Vim, storing the
3
+ # file in <repo>/.git/tags. If you're using Fugitive.vim, you'll automatically
4
+ # have access to the tags file; otherwise you'll have to modify your `tags`
5
+ # option in your vimrc to search the generated file.
6
+
7
+ set -e
8
+
9
+ trap "rm -f $GIT_DIR/tags.$$" EXIT
10
+ err_file=$GIT_DIR/ctags.err
11
+ if ctags --tag-relative -Rf$GIT_DIR/tags.$$ --exclude=.git "$@" 2>${err_file}; then
12
+ mv $GIT_DIR/tags.$$ $GIT_DIR/tags
13
+ [ -e ${err_file} ] && rm -f ${err_file}
14
+ else
15
+ # Ignore STDERR unless `ctags` returned a non-zero exit code
16
+ cat ${err_file}
17
+ fi
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Entrypoint for Overcommit hook integration. Installing Overcommit will result
5
+ # in all of your git hooks being copied from this file, allowing the framework
6
+ # to manage your hooks for you.
7
+
8
+ # Prevent a Ruby stack trace from appearing when we interrupt the hook.
9
+ # Note that this will be overridden when Overcommit is loaded, since the
10
+ # InterruptHandler will redefine the trap at that time.
11
+ Signal.trap('INT') do
12
+ puts 'Hook run interrupted'
13
+ exit 130
14
+ end
15
+
16
+ # Allow hooks to be disabled via environment variable so git commands can be run
17
+ # in scripts without Overcommit running hooks
18
+ if ENV['OVERCOMMIT_DISABLE'].to_i != 0 || ENV['OVERCOMMIT_DISABLED'].to_i != 0
19
+ exit
20
+ end
21
+
22
+ hook_type = File.basename($0)
23
+ if hook_type == 'overcommit-hook'
24
+ puts "Don't run `overcommit-hook` directly; it is intended to be symlinked " \
25
+ "by each hook in a repository's .git/hooks directory."
26
+ exit 64 # EX_USAGE
27
+ end
28
+
29
+ # Check if Overcommit should invoke a Bundler context for loading gems
30
+ require 'yaml'
31
+ # rubocop:disable Style/RescueModifier
32
+ if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
33
+ ENV['BUNDLE_GEMFILE'] = gemfile
34
+ require 'bundler'
35
+
36
+ begin
37
+ Bundler.setup
38
+ rescue Bundler::BundlerError => ex
39
+ puts "Problem loading '#{gemfile}': #{ex.message}"
40
+ puts "Try running:\nbundle install --gemfile=#{gemfile}" if ex.is_a?(Bundler::GemNotFound)
41
+ exit 78 # EX_CONFIG
42
+ end
43
+ end
44
+ # rubocop:enable Style/RescueModifier
45
+
46
+ begin
47
+ require 'overcommit'
48
+ rescue LoadError
49
+ if gemfile
50
+ puts 'You have specified the `gemfile` option in your Overcommit ' \
51
+ 'configuration but have not added the `overcommit` gem to ' \
52
+ "#{gemfile}."
53
+ else
54
+ puts 'This repository contains hooks installed by Overcommit, but the ' \
55
+ "`overcommit` gem is not installed.\n" \
56
+ 'Install it with `gem install overcommit`.'
57
+ end
58
+
59
+ exit 64 # EX_USAGE
60
+ end
61
+
62
+ begin
63
+ logger = Overcommit::Logger.new(STDOUT)
64
+ Overcommit::Utils.log = logger
65
+
66
+ # Ensure master hook is up-to-date
67
+ installer = Overcommit::Installer.new(logger)
68
+ if installer.run(Overcommit::Utils.repo_root, action: :update)
69
+ exec($0, *ARGV) # Execute the updated hook with all original arguments
70
+ end
71
+
72
+ config = Overcommit::ConfigurationLoader.new(logger).load_repo_config
73
+
74
+ context = Overcommit::HookContext.create(hook_type, config, ARGV, STDIN)
75
+ config.apply_environment!(context, ENV)
76
+
77
+ printer = Overcommit::Printer.new(config, logger, context)
78
+ runner = Overcommit::HookRunner.new(config, logger, context, printer)
79
+
80
+ status = runner.run
81
+
82
+ exit(status ? 0 : 65) # 65 = EX_DATAERR
83
+ rescue Overcommit::Exceptions::ConfigurationError => error
84
+ puts error
85
+ exit 78 # EX_CONFIG
86
+ rescue Overcommit::Exceptions::HookContextLoadError => error
87
+ puts error
88
+ puts 'Are you running an old version of Overcommit?'
89
+ exit 69 # EX_UNAVAILABLE
90
+ rescue Overcommit::Exceptions::HookLoadError,
91
+ Overcommit::Exceptions::InvalidHookDefinition => error
92
+ puts error.message
93
+ puts error.backtrace
94
+ exit 78 # EX_CONFIG
95
+ rescue Overcommit::Exceptions::HookSetupFailed,
96
+ Overcommit::Exceptions::HookCleanupFailed => error
97
+ puts error.message
98
+ exit 74 # EX_IOERR
99
+ rescue Overcommit::Exceptions::HookCancelled
100
+ puts 'You cancelled the hook run'
101
+ exit 130 # Ctrl-C cancel
102
+ rescue Overcommit::Exceptions::InvalidGitRepo => error
103
+ puts error
104
+ exit 64 # EX_USAGE
105
+ rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error
106
+ puts error
107
+ puts "For more information, see #{Overcommit::REPO_URL}#security"
108
+ exit 1
109
+ rescue Overcommit::Exceptions::InvalidHookSignature
110
+ exit 1
111
+ rescue StandardError => error
112
+ puts error.message
113
+ puts error.backtrace
114
+ puts "Report this bug at #{Overcommit::BUG_REPORT_URL}"
115
+ exit 70 # EX_SOFTWARE
116
+ end