jawshooah-overcommit 0.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/overcommit +8 -0
- data/config/default.yml +275 -0
- data/config/starter.yml +31 -0
- data/lib/overcommit.rb +20 -0
- data/lib/overcommit/cli.rb +205 -0
- data/lib/overcommit/configuration.rb +183 -0
- data/lib/overcommit/configuration_loader.rb +49 -0
- data/lib/overcommit/configuration_validator.rb +40 -0
- data/lib/overcommit/constants.rb +8 -0
- data/lib/overcommit/exceptions.rb +35 -0
- data/lib/overcommit/git_repo.rb +147 -0
- data/lib/overcommit/hook/base.rb +174 -0
- data/lib/overcommit/hook/commit_msg/base.rb +11 -0
- data/lib/overcommit/hook/commit_msg/gerrit_change_id.rb +18 -0
- data/lib/overcommit/hook/commit_msg/hard_tabs.rb +13 -0
- data/lib/overcommit/hook/commit_msg/russian_novel.rb +14 -0
- data/lib/overcommit/hook/commit_msg/single_line_subject.rb +12 -0
- data/lib/overcommit/hook/commit_msg/text_width.rb +38 -0
- data/lib/overcommit/hook/commit_msg/trailing_period.rb +12 -0
- data/lib/overcommit/hook/post_checkout/base.rb +11 -0
- data/lib/overcommit/hook/post_checkout/index_tags.rb +26 -0
- data/lib/overcommit/hook/post_commit/base.rb +11 -0
- data/lib/overcommit/hook/post_commit/git_guilt.rb +9 -0
- data/lib/overcommit/hook/pre_commit/author_email.rb +18 -0
- data/lib/overcommit/hook/pre_commit/author_name.rb +17 -0
- data/lib/overcommit/hook/pre_commit/base.rb +70 -0
- data/lib/overcommit/hook/pre_commit/berksfile_check.rb +20 -0
- data/lib/overcommit/hook/pre_commit/brakeman.rb +12 -0
- data/lib/overcommit/hook/pre_commit/broken_symlinks.rb +15 -0
- data/lib/overcommit/hook/pre_commit/bundle_check.rb +25 -0
- data/lib/overcommit/hook/pre_commit/chamber_security.rb +11 -0
- data/lib/overcommit/hook/pre_commit/coffee_lint.rb +11 -0
- data/lib/overcommit/hook/pre_commit/css_lint.rb +11 -0
- data/lib/overcommit/hook/pre_commit/go_lint.rb +12 -0
- data/lib/overcommit/hook/pre_commit/haml_lint.rb +19 -0
- data/lib/overcommit/hook/pre_commit/hard_tabs.rb +14 -0
- data/lib/overcommit/hook/pre_commit/image_optim.rb +41 -0
- data/lib/overcommit/hook/pre_commit/js_hint.rb +13 -0
- data/lib/overcommit/hook/pre_commit/jscs.rb +22 -0
- data/lib/overcommit/hook/pre_commit/json_syntax.rb +22 -0
- data/lib/overcommit/hook/pre_commit/jsx_hint.rb +13 -0
- data/lib/overcommit/hook/pre_commit/jsxcs.rb +20 -0
- data/lib/overcommit/hook/pre_commit/local_paths_in_gemfile.rb +14 -0
- data/lib/overcommit/hook/pre_commit/merge_conflicts.rb +14 -0
- data/lib/overcommit/hook/pre_commit/pry_binding.rb +14 -0
- data/lib/overcommit/hook/pre_commit/python_flake8.rb +11 -0
- data/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +45 -0
- data/lib/overcommit/hook/pre_commit/reek.rb +22 -0
- data/lib/overcommit/hook/pre_commit/rubocop.rb +19 -0
- data/lib/overcommit/hook/pre_commit/scss_lint.rb +19 -0
- data/lib/overcommit/hook/pre_commit/shell_check.rb +19 -0
- data/lib/overcommit/hook/pre_commit/trailing_whitespace.rb +13 -0
- data/lib/overcommit/hook/pre_commit/travis_lint.rb +11 -0
- data/lib/overcommit/hook/pre_commit/yaml_syntax.rb +22 -0
- data/lib/overcommit/hook_context.rb +17 -0
- data/lib/overcommit/hook_context/base.rb +69 -0
- data/lib/overcommit/hook_context/commit_msg.rb +32 -0
- data/lib/overcommit/hook_context/post_checkout.rb +26 -0
- data/lib/overcommit/hook_context/post_commit.rb +19 -0
- data/lib/overcommit/hook_context/pre_commit.rb +148 -0
- data/lib/overcommit/hook_context/run_all.rb +39 -0
- data/lib/overcommit/hook_loader/base.rb +36 -0
- data/lib/overcommit/hook_loader/built_in_hook_loader.rb +12 -0
- data/lib/overcommit/hook_loader/plugin_hook_loader.rb +61 -0
- data/lib/overcommit/hook_runner.rb +129 -0
- data/lib/overcommit/hook_signer.rb +79 -0
- data/lib/overcommit/installer.rb +148 -0
- data/lib/overcommit/interrupt_handler.rb +87 -0
- data/lib/overcommit/logger.rb +79 -0
- data/lib/overcommit/message_processor.rb +132 -0
- data/lib/overcommit/printer.rb +116 -0
- data/lib/overcommit/subprocess.rb +46 -0
- data/lib/overcommit/utils.rb +163 -0
- data/lib/overcommit/version.rb +4 -0
- data/libexec/gerrit-change-id +174 -0
- data/libexec/index-tags +17 -0
- data/template-dir/hooks/commit-msg +81 -0
- data/template-dir/hooks/overcommit-hook +81 -0
- data/template-dir/hooks/post-checkout +81 -0
- data/template-dir/hooks/pre-commit +81 -0
- metadata +184 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1fdbbf53711cd124c0d6dd824d12d0f0d7ee1e71
|
4
|
+
data.tar.gz: 4e2c9e69e2cd659ab1bee8a5b58fd7962e82a282
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f484a6d5dd6c97c8bae56ddd0eb2f0702895269f16bbc7eb16a49e2083922cdafaf0768c918a9d2f60d1d5ad55dcc41df8b8a3461915b3bd29beea8780726de
|
7
|
+
data.tar.gz: 2304de2cb69bbd8ade60137ec1e32119ed2250cc6e7be9e98b4f2e88705abd564b3e22b07e3e2d898cd4c6ab13ae3c84e29c2fd50b48b3671c522b205030d491
|
data/bin/overcommit
ADDED
data/config/default.yml
ADDED
@@ -0,0 +1,275 @@
|
|
1
|
+
# Default configuration that all Overcommit configurations inherit from.
|
2
|
+
#
|
3
|
+
# This is an opinionated list of which hooks are valuable to run and what their
|
4
|
+
# out-of-the-box settings should be.
|
5
|
+
|
6
|
+
# Where to store hook plugins specific to a repository. These are loaded in
|
7
|
+
# addition to the default hooks Overcommit comes with. The location is relative
|
8
|
+
# to the root of the repository.
|
9
|
+
plugin_directory: '.git-hooks'
|
10
|
+
|
11
|
+
# Whether to check if a hook plugin has changed since Overcommit last ran it.
|
12
|
+
# This is a defense mechanism when working with repositories which can contain
|
13
|
+
# untrusted code (e.g. when you fetch a pull request from a third party).
|
14
|
+
# See https://github.com/causes/overcommit#security for more information.
|
15
|
+
verify_plugin_signatures: true
|
16
|
+
|
17
|
+
# Hooks that run after HEAD changes or a file is explicitly checked out. Useful
|
18
|
+
# for updating source tags (e.g. via ctags) or warning about new migrations,
|
19
|
+
# etc.
|
20
|
+
PostCheckout:
|
21
|
+
ALL:
|
22
|
+
required: false
|
23
|
+
quiet: false
|
24
|
+
IndexTags:
|
25
|
+
enabled: false
|
26
|
+
description: 'Generating tags file from source'
|
27
|
+
|
28
|
+
# Hooks that are run after `git commit` is executed, before the commit message
|
29
|
+
# editor is displayed. These hooks are ideal for syntax checkers, linters, and
|
30
|
+
# other checks that you want to run before you allow a commit object to be
|
31
|
+
# created.
|
32
|
+
PreCommit:
|
33
|
+
ALL:
|
34
|
+
problem_on_unmodified_line: warn
|
35
|
+
requires_files: true
|
36
|
+
required: false
|
37
|
+
quiet: false
|
38
|
+
|
39
|
+
AuthorEmail:
|
40
|
+
description: 'Checking author email'
|
41
|
+
requires_files: false
|
42
|
+
required: true
|
43
|
+
quiet: true
|
44
|
+
pattern: '^[^@]+@.*$'
|
45
|
+
|
46
|
+
AuthorName:
|
47
|
+
description: 'Checking for author name'
|
48
|
+
requires_files: false
|
49
|
+
required: true
|
50
|
+
quiet: true
|
51
|
+
|
52
|
+
BerksfileCheck:
|
53
|
+
description: 'Checking Berksfile lock'
|
54
|
+
required_executable: 'berks'
|
55
|
+
install_command: 'gem install berks'
|
56
|
+
include:
|
57
|
+
- 'Berksfile'
|
58
|
+
- 'Berksfile.lock'
|
59
|
+
|
60
|
+
Brakeman:
|
61
|
+
enabled: false
|
62
|
+
description: 'Checking for security vulnerabilities'
|
63
|
+
required_executable: 'brakeman'
|
64
|
+
install_command: 'gem install brakeman'
|
65
|
+
include:
|
66
|
+
- '**/*.rb'
|
67
|
+
|
68
|
+
BrokenSymlinks:
|
69
|
+
description: 'Checking for broken symlinks'
|
70
|
+
quiet: true
|
71
|
+
|
72
|
+
BundleCheck:
|
73
|
+
description: 'Checking Gemfile dependencies'
|
74
|
+
required_executable: 'bundle'
|
75
|
+
install_command: 'gem install bundler'
|
76
|
+
include:
|
77
|
+
- 'Gemfile'
|
78
|
+
- 'Gemfile.lock'
|
79
|
+
- '*.gemspec'
|
80
|
+
|
81
|
+
ChamberSecurity:
|
82
|
+
enabled: false
|
83
|
+
description: 'Checking that settings have been secured with Chamber'
|
84
|
+
required_executable: 'chamber'
|
85
|
+
install_command: 'gem install chamber'
|
86
|
+
include:
|
87
|
+
- 'config/settings.yml'
|
88
|
+
- 'config/settings/**/*.yml'
|
89
|
+
|
90
|
+
CoffeeLint:
|
91
|
+
description: 'Analyzing with coffeelint'
|
92
|
+
required_executable: 'coffeelint'
|
93
|
+
install_command: 'npm install -g coffeelint'
|
94
|
+
include: '**/*.coffee'
|
95
|
+
|
96
|
+
CssLint:
|
97
|
+
description: 'Analyzing with csslint'
|
98
|
+
required_executable: 'csslint'
|
99
|
+
install_command: 'npm install -g csslint'
|
100
|
+
include: '**/*.css'
|
101
|
+
|
102
|
+
GoLint:
|
103
|
+
description: 'Analyzing with golint'
|
104
|
+
required_executable: 'golint'
|
105
|
+
install_command: 'go get github.com/golang/lint/golint'
|
106
|
+
include: '**/*.go'
|
107
|
+
|
108
|
+
HamlLint:
|
109
|
+
description: 'Analyzing with haml-lint'
|
110
|
+
required_executable: 'haml-lint'
|
111
|
+
install_command: 'gem install haml-lint'
|
112
|
+
include: '**/*.haml'
|
113
|
+
|
114
|
+
HardTabs:
|
115
|
+
description: 'Checking for hard tabs'
|
116
|
+
quiet: true
|
117
|
+
exclude:
|
118
|
+
- '**/*.go'
|
119
|
+
- '**/Makefile'
|
120
|
+
- '.gitmodules'
|
121
|
+
|
122
|
+
ImageOptim:
|
123
|
+
description: 'Checking for optimizable images'
|
124
|
+
include:
|
125
|
+
- '**/*.gif'
|
126
|
+
- '**/*.jpg'
|
127
|
+
- '**/*.jpeg'
|
128
|
+
- '**/*.png'
|
129
|
+
|
130
|
+
Jscs:
|
131
|
+
description: 'Analyzing with JSCS'
|
132
|
+
required_executable: 'jscs'
|
133
|
+
install_command: 'npm install -g jscs'
|
134
|
+
include: '**/*.js'
|
135
|
+
|
136
|
+
Jsxcs:
|
137
|
+
description: 'Analyzing with JSXCS'
|
138
|
+
required_executable: 'jsxcs'
|
139
|
+
install_command: 'npm install -g jsxcs'
|
140
|
+
include: '**/*.jsx'
|
141
|
+
|
142
|
+
JsHint:
|
143
|
+
description: 'Analyzing with JSHint'
|
144
|
+
required_executable: 'jshint'
|
145
|
+
install_command: 'npm install -g jshint'
|
146
|
+
include: '**/*.js'
|
147
|
+
|
148
|
+
JsonSyntax:
|
149
|
+
description: 'Validating JSON syntax'
|
150
|
+
include: '**/*.json'
|
151
|
+
|
152
|
+
JsxHint:
|
153
|
+
description: 'Analyzing with JSXHint'
|
154
|
+
required_executable: 'jsxhint'
|
155
|
+
install_command: 'npm install -g jsxhint'
|
156
|
+
include: '**/*.jsx'
|
157
|
+
|
158
|
+
LocalPathsInGemfile:
|
159
|
+
description: 'Checking for local paths in Gemfile'
|
160
|
+
include: '**/Gemfile'
|
161
|
+
|
162
|
+
MergeConflicts:
|
163
|
+
description: 'Checking for merge conflicts'
|
164
|
+
quiet: true
|
165
|
+
|
166
|
+
PryBinding:
|
167
|
+
description: 'Checking for instances of binding.pry'
|
168
|
+
quiet: true
|
169
|
+
include:
|
170
|
+
- '**/*.rb'
|
171
|
+
- '**/*.rake'
|
172
|
+
|
173
|
+
PythonFlake8:
|
174
|
+
description: 'Analyzing with flake8'
|
175
|
+
required_executable: 'flake8'
|
176
|
+
install_command: 'pip install flake8'
|
177
|
+
include: '**/*.py'
|
178
|
+
|
179
|
+
RailsSchemaUpToDate:
|
180
|
+
description: 'Checking if database schema is up to date'
|
181
|
+
include:
|
182
|
+
- 'db/migrate/*.rb'
|
183
|
+
- 'db/schema.rb'
|
184
|
+
- 'db/structure.sql'
|
185
|
+
|
186
|
+
Reek:
|
187
|
+
enabled: false
|
188
|
+
description: 'Analyzing with Reek'
|
189
|
+
required_executable: 'reek'
|
190
|
+
install_command: 'gem install reek'
|
191
|
+
include:
|
192
|
+
- '**/*.gemspec'
|
193
|
+
- '**/*.rake'
|
194
|
+
- '**/*.rb'
|
195
|
+
- '**/Gemfile'
|
196
|
+
- '**/Rakefile'
|
197
|
+
|
198
|
+
Rubocop:
|
199
|
+
description: 'Analyzing with Rubocop'
|
200
|
+
required_executable: 'rubocop'
|
201
|
+
install_command: 'gem install rubocop'
|
202
|
+
include:
|
203
|
+
- '**/*.gemspec'
|
204
|
+
- '**/*.rake'
|
205
|
+
- '**/*.rb'
|
206
|
+
- '**/Gemfile'
|
207
|
+
- '**/Rakefile'
|
208
|
+
|
209
|
+
ScssLint:
|
210
|
+
description: 'Analyzing with scss-lint'
|
211
|
+
required_executable: 'scss-lint'
|
212
|
+
install_command: 'gem install scss-lint'
|
213
|
+
include: '**/*.scss'
|
214
|
+
|
215
|
+
ShellCheck:
|
216
|
+
description: 'Analyzing with ShellCheck'
|
217
|
+
required_executable: 'shellcheck'
|
218
|
+
include: '**/*.sh'
|
219
|
+
|
220
|
+
TrailingWhitespace:
|
221
|
+
description: 'Checking for trailing whitespace'
|
222
|
+
exclude:
|
223
|
+
- '**/db/structure.sql'
|
224
|
+
|
225
|
+
TravisLint:
|
226
|
+
description: 'Checking Travis CI configuration'
|
227
|
+
required_executable: 'travis'
|
228
|
+
install_command: 'gem install travis'
|
229
|
+
include: '.travis.yml'
|
230
|
+
|
231
|
+
YamlSyntax:
|
232
|
+
description: 'Checking YAML syntax'
|
233
|
+
include: '**/*.yml'
|
234
|
+
|
235
|
+
# Hooks that are run against every commit message after a user has written it.
|
236
|
+
# These hooks are useful for enforcing policies on commit messages written for a
|
237
|
+
# project.
|
238
|
+
CommitMsg:
|
239
|
+
ALL:
|
240
|
+
requires_files: false
|
241
|
+
quiet: false
|
242
|
+
|
243
|
+
GerritChangeId:
|
244
|
+
enabled: false
|
245
|
+
description: 'Ensuring Gerrit Change-Id is present'
|
246
|
+
required: true
|
247
|
+
|
248
|
+
HardTabs:
|
249
|
+
description: 'Checking for hard tabs'
|
250
|
+
|
251
|
+
RussianNovel:
|
252
|
+
description: 'Checking length of commit message'
|
253
|
+
quiet: true
|
254
|
+
|
255
|
+
SingleLineSubject:
|
256
|
+
description: 'Checking subject line'
|
257
|
+
|
258
|
+
TextWidth:
|
259
|
+
description: 'Checking text width'
|
260
|
+
max_subject_width: 60
|
261
|
+
max_body_width: 72
|
262
|
+
|
263
|
+
TrailingPeriod:
|
264
|
+
description: 'Checking for trailing periods in subject'
|
265
|
+
|
266
|
+
PostCommit:
|
267
|
+
ALL:
|
268
|
+
requires_files: false
|
269
|
+
required: false
|
270
|
+
quiet: false
|
271
|
+
|
272
|
+
GitGuilt:
|
273
|
+
description: 'Calculating changes in blame since last commit'
|
274
|
+
required_executable: 'git-guilt'
|
275
|
+
install_command: 'npm install -g git-guilt'
|
data/config/starter.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Use this file to configure the Overcommit hooks you wish to use. This will
|
2
|
+
# extend the default configuration defined in:
|
3
|
+
# https://github.com/causes/overcommit/blob/master/config/default.yml
|
4
|
+
#
|
5
|
+
# At the topmost level of this YAML file is a key representing type of hook
|
6
|
+
# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
|
7
|
+
# customize each hook, such as whether to only run it on certain files (via
|
8
|
+
# `include`), whether to only display output if it fails (via `quiet`), etc.
|
9
|
+
#
|
10
|
+
# For a complete list of hooks, see:
|
11
|
+
# https://github.com/causes/overcommit/tree/master/lib/overcommit/hook
|
12
|
+
#
|
13
|
+
# For a complete list of options that you can use to customize hooks, see:
|
14
|
+
# https://github.com/causes/overcommit#configuration
|
15
|
+
#
|
16
|
+
# Uncomment the following lines to make the configuration take effect.
|
17
|
+
|
18
|
+
#PreCommit:
|
19
|
+
# Rubocop:
|
20
|
+
# on_warn: fail # Treat all warnings as failures
|
21
|
+
#
|
22
|
+
# TrailingWhitespace:
|
23
|
+
# exclude:
|
24
|
+
# - '**/db/structure.sql' # Ignore trailing whitespace in generated files
|
25
|
+
#
|
26
|
+
#PostCheckout:
|
27
|
+
# ALL: # Special hook name that customizes all hooks of this type
|
28
|
+
# quiet: true # Change all post-checkout hooks to only display output on failure
|
29
|
+
#
|
30
|
+
# IndexTags:
|
31
|
+
# enabled: true # Generate a tags file with `ctags` each time HEAD changes
|
data/lib/overcommit.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'overcommit/constants'
|
2
|
+
require 'overcommit/exceptions'
|
3
|
+
require 'overcommit/configuration_validator'
|
4
|
+
require 'overcommit/configuration'
|
5
|
+
require 'overcommit/configuration_loader'
|
6
|
+
require 'overcommit/hook/base'
|
7
|
+
require 'overcommit/hook_context/base'
|
8
|
+
require 'overcommit/hook_context'
|
9
|
+
require 'overcommit/git_repo'
|
10
|
+
require 'overcommit/hook_signer'
|
11
|
+
require 'overcommit/hook_loader/base'
|
12
|
+
require 'overcommit/hook_loader/built_in_hook_loader'
|
13
|
+
require 'overcommit/hook_loader/plugin_hook_loader'
|
14
|
+
require 'overcommit/interrupt_handler'
|
15
|
+
require 'overcommit/printer'
|
16
|
+
require 'overcommit/hook_runner'
|
17
|
+
require 'overcommit/installer'
|
18
|
+
require 'overcommit/logger'
|
19
|
+
require 'overcommit/utils'
|
20
|
+
require 'overcommit/version'
|
@@ -0,0 +1,205 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Overcommit
|
4
|
+
# Responsible for parsing command-line options and executing appropriate
|
5
|
+
# application logic based on those options.
|
6
|
+
class CLI # rubocop:disable ClassLength
|
7
|
+
def initialize(arguments, logger)
|
8
|
+
@arguments = arguments
|
9
|
+
@log = logger
|
10
|
+
@options = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
parse_arguments
|
15
|
+
|
16
|
+
case @options[:action]
|
17
|
+
when :install, :uninstall
|
18
|
+
install_or_uninstall
|
19
|
+
when :template_dir
|
20
|
+
print_template_directory_path
|
21
|
+
when :sign_plugins
|
22
|
+
sign_plugins
|
23
|
+
when :run_all
|
24
|
+
run_all
|
25
|
+
end
|
26
|
+
rescue Overcommit::Exceptions::HookContextLoadError => ex
|
27
|
+
puts ex
|
28
|
+
exit 64 # EX_USAGE
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_reader :log
|
34
|
+
|
35
|
+
def parse_arguments
|
36
|
+
@parser = create_option_parser
|
37
|
+
|
38
|
+
begin
|
39
|
+
@parser.parse!(@arguments)
|
40
|
+
|
41
|
+
# Default action is to install
|
42
|
+
@options[:action] ||= :install
|
43
|
+
|
44
|
+
# Unconsumed arguments are our targets
|
45
|
+
@options[:targets] = @arguments
|
46
|
+
rescue OptionParser::InvalidOption => ex
|
47
|
+
print_help @parser.help, ex
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_option_parser
|
52
|
+
OptionParser.new do |opts|
|
53
|
+
opts.banner = "Usage: #{opts.program_name} [options] [target-repo]"
|
54
|
+
|
55
|
+
add_information_options(opts)
|
56
|
+
add_installation_options(opts)
|
57
|
+
add_other_options(opts)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_information_options(opts)
|
62
|
+
opts.on_tail('-h', '--help', 'Show this message') do
|
63
|
+
print_help opts.help
|
64
|
+
end
|
65
|
+
|
66
|
+
opts.on_tail('-v', '--version', 'Show version') do
|
67
|
+
print_version(opts.program_name)
|
68
|
+
end
|
69
|
+
|
70
|
+
opts.on_tail('-l', '--list-hooks', 'List installed hooks') do
|
71
|
+
print_installed_hooks
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def add_installation_options(opts)
|
76
|
+
opts.on('-u', '--uninstall', 'Remove Overcommit hooks from a repository') do
|
77
|
+
@options[:action] = :uninstall
|
78
|
+
end
|
79
|
+
|
80
|
+
opts.on('-i', '--install', 'Install Overcommit hooks in a repository') do
|
81
|
+
@options[:action] = :install
|
82
|
+
end
|
83
|
+
|
84
|
+
opts.on('-f', '--force', 'Overwrite any previously installed hooks') do
|
85
|
+
@options[:force] = true
|
86
|
+
end
|
87
|
+
|
88
|
+
opts.on('-r', '--run', 'Run pre-commit hook against all git tracked files') do
|
89
|
+
@options[:action] = :run_all
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def add_other_options(opts)
|
94
|
+
opts.on('-s', '--sign hook', 'Update plugin signatures for hook', String) do |hook|
|
95
|
+
@options[:action] = :sign_plugins
|
96
|
+
@options[:hook_to_sign] = hook
|
97
|
+
end
|
98
|
+
|
99
|
+
opts.on('-t', '--template-dir', 'Print location of template directory') do
|
100
|
+
@options[:action] = :template_dir
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def install_or_uninstall
|
105
|
+
if Array(@options[:targets]).empty?
|
106
|
+
@options[:targets] = [Overcommit::Utils.repo_root].compact
|
107
|
+
end
|
108
|
+
|
109
|
+
if @options[:targets].empty?
|
110
|
+
log.warning 'You are not in a git repository.'
|
111
|
+
log.log 'You must either specify the path to a repository or ' \
|
112
|
+
'change your current directory to a repository.'
|
113
|
+
halt 64 # EX_USAGE
|
114
|
+
end
|
115
|
+
|
116
|
+
@options[:targets].each do |target|
|
117
|
+
begin
|
118
|
+
Installer.new(log).run(target, @options)
|
119
|
+
rescue Overcommit::Exceptions::InvalidGitRepo => error
|
120
|
+
log.warning "Invalid repo #{target}: #{error}"
|
121
|
+
halt 69 # EX_UNAVAILABLE
|
122
|
+
rescue Overcommit::Exceptions::PreExistingHooks => error
|
123
|
+
log.warning "Unable to install into #{target}: #{error}"
|
124
|
+
halt 73 # EX_CANTCREAT
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def print_template_directory_path
|
130
|
+
puts File.join(OVERCOMMIT_HOME, 'template-dir')
|
131
|
+
halt
|
132
|
+
end
|
133
|
+
|
134
|
+
def print_help(message, error = nil)
|
135
|
+
log.error "#{error}\n" if error
|
136
|
+
log.log message
|
137
|
+
halt(error ? 64 : 0) # 64 = EX_USAGE
|
138
|
+
end
|
139
|
+
|
140
|
+
def print_version(program_name)
|
141
|
+
log.log "#{program_name} #{Overcommit::VERSION}"
|
142
|
+
halt
|
143
|
+
end
|
144
|
+
|
145
|
+
# Prints the hooks available in the current repo and whether they're
|
146
|
+
# enabled/disabled.
|
147
|
+
def print_installed_hooks
|
148
|
+
config = Overcommit::ConfigurationLoader.load_repo_config
|
149
|
+
|
150
|
+
config.all_hook_configs.each do |hook_type, hook_configs|
|
151
|
+
print_hooks_for_hook_type(config, hook_configs, hook_type)
|
152
|
+
end
|
153
|
+
|
154
|
+
halt
|
155
|
+
end
|
156
|
+
|
157
|
+
def print_hooks_for_hook_type(repo_config, hook_configs, hook_type)
|
158
|
+
log.log "#{hook_type}:"
|
159
|
+
hook_configs.each do |hook_name, config|
|
160
|
+
log.partial " #{hook_name}: "
|
161
|
+
|
162
|
+
if config['enabled']
|
163
|
+
log.success('enabled', true)
|
164
|
+
else
|
165
|
+
log.error('disabled', true)
|
166
|
+
end
|
167
|
+
|
168
|
+
if repo_config.plugin_hook?(hook_type, hook_name)
|
169
|
+
log.warning(' (plugin)')
|
170
|
+
else
|
171
|
+
log.newline
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def sign_plugins
|
177
|
+
config = Overcommit::ConfigurationLoader.load_repo_config
|
178
|
+
context = Overcommit::HookContext.create(@options[:hook_to_sign],
|
179
|
+
config,
|
180
|
+
@arguments)
|
181
|
+
Overcommit::HookLoader::PluginHookLoader.new(config,
|
182
|
+
context,
|
183
|
+
log).update_signatures
|
184
|
+
halt
|
185
|
+
end
|
186
|
+
|
187
|
+
def run_all
|
188
|
+
config = Overcommit::ConfigurationLoader.load_repo_config
|
189
|
+
context = Overcommit::HookContext.create('run-all', config, @arguments)
|
190
|
+
config.apply_environment!(context, ENV)
|
191
|
+
|
192
|
+
printer = Overcommit::Printer.new(log, context)
|
193
|
+
runner = Overcommit::HookRunner.new(config, log, context, printer)
|
194
|
+
|
195
|
+
status = runner.run
|
196
|
+
|
197
|
+
halt(status ? 0 : 65)
|
198
|
+
end
|
199
|
+
|
200
|
+
# Used for ease of stubbing in tests
|
201
|
+
def halt(status = 0)
|
202
|
+
exit status
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|