overcommit 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/overcommit +3 -4
- data/config/default.yml +139 -0
- data/lib/overcommit.rb +7 -5
- data/lib/overcommit/cli.rb +59 -64
- data/lib/overcommit/configuration.rb +108 -34
- data/lib/overcommit/configuration_loader.rb +47 -0
- data/lib/overcommit/constants.rb +7 -0
- data/lib/overcommit/exceptions.rb +16 -0
- data/lib/overcommit/hook/base.rb +91 -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/{plugins → hook}/commit_msg/hard_tabs.rb +5 -6
- 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 +20 -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/bundle_check.rb +29 -0
- data/lib/overcommit/hook/post_checkout/index_tags.rb +24 -0
- data/lib/overcommit/hook/pre_commit/author_email.rb +17 -0
- data/lib/overcommit/hook/pre_commit/author_name.rb +17 -0
- data/lib/overcommit/hook/pre_commit/base.rb +10 -0
- data/lib/overcommit/hook/pre_commit/bundle_check.rb +30 -0
- data/lib/overcommit/hook/pre_commit/coffee_lint.rb +14 -0
- data/lib/overcommit/hook/pre_commit/css_lint.rb +16 -0
- data/lib/overcommit/hook/pre_commit/haml_lint.rb +26 -0
- data/lib/overcommit/hook/pre_commit/hard_tabs.rb +16 -0
- data/lib/overcommit/hook/pre_commit/image_optim.rb +41 -0
- data/lib/overcommit/hook/pre_commit/js_hint.rb +15 -0
- data/lib/overcommit/hook/pre_commit/jscs.rb +31 -0
- data/lib/overcommit/hook/pre_commit/python_flake8.rb +14 -0
- data/lib/overcommit/hook/pre_commit/rubocop.rb +26 -0
- data/lib/overcommit/hook/pre_commit/scss_lint.rb +26 -0
- data/lib/overcommit/hook/pre_commit/trailing_whitespace.rb +15 -0
- data/lib/overcommit/hook/pre_commit/yaml_syntax.rb +22 -0
- data/lib/overcommit/hook_context.rb +16 -0
- data/lib/overcommit/hook_context/base.rb +68 -0
- data/lib/overcommit/hook_context/commit_msg.rb +32 -0
- data/lib/overcommit/hook_context/post_checkout.rb +24 -0
- data/lib/overcommit/hook_context/pre_commit.rb +96 -0
- data/lib/overcommit/hook_runner.rb +150 -0
- data/lib/overcommit/installer.rb +61 -68
- data/lib/overcommit/logger.rb +16 -13
- data/lib/overcommit/utils.rb +63 -38
- data/lib/overcommit/version.rb +1 -1
- data/{bin/scripts → libexec}/gerrit-change-id +0 -0
- data/{bin/scripts → libexec}/index-tags +1 -3
- data/template-dir/hooks/commit-msg +83 -0
- data/template-dir/hooks/overcommit-hook +83 -0
- data/template-dir/hooks/post-checkout +83 -0
- data/template-dir/hooks/pre-commit +83 -0
- metadata +76 -57
- data/bin/hooks/commit-msg +0 -8
- data/bin/hooks/post-checkout +0 -9
- data/bin/hooks/post-merge +0 -23
- data/bin/hooks/pre-commit +0 -8
- data/bin/hooks/prepare-commit-msg +0 -159
- data/bin/run-hook +0 -8
- data/bin/scripts/check-gemfile +0 -9
- data/bin/scripts/csslint-rhino.js +0 -9080
- data/bin/scripts/jshint.js +0 -5921
- data/bin/scripts/jshint_runner.js +0 -42
- data/lib/overcommit/errors.rb +0 -3
- data/lib/overcommit/git_hook.rb +0 -89
- data/lib/overcommit/hook_specific_check.rb +0 -110
- data/lib/overcommit/hooks/commit_msg.rb +0 -7
- data/lib/overcommit/hooks/pre_commit.rb +0 -9
- data/lib/overcommit/plugins/commit_msg/change_id.rb +0 -15
- data/lib/overcommit/plugins/commit_msg/release_note.rb +0 -25
- data/lib/overcommit/plugins/commit_msg/russian_novel.rb +0 -16
- data/lib/overcommit/plugins/commit_msg/single_line_subject.rb +0 -13
- data/lib/overcommit/plugins/commit_msg/text_width.rb +0 -20
- data/lib/overcommit/plugins/commit_msg/trailing_period.rb +0 -13
- data/lib/overcommit/plugins/pre_commit/author_name.rb +0 -16
- data/lib/overcommit/plugins/pre_commit/causes_email.rb +0 -15
- data/lib/overcommit/plugins/pre_commit/coffee_lint.rb +0 -16
- data/lib/overcommit/plugins/pre_commit/css_linter.rb +0 -17
- data/lib/overcommit/plugins/pre_commit/haml_style.rb +0 -34
- data/lib/overcommit/plugins/pre_commit/haml_syntax.rb +0 -24
- data/lib/overcommit/plugins/pre_commit/image_optimization.rb +0 -50
- data/lib/overcommit/plugins/pre_commit/js_console_log.rb +0 -16
- data/lib/overcommit/plugins/pre_commit/js_syntax.rb +0 -30
- data/lib/overcommit/plugins/pre_commit/python_flake8.rb +0 -15
- data/lib/overcommit/plugins/pre_commit/ruby_style.rb +0 -67
- data/lib/overcommit/plugins/pre_commit/ruby_syntax.rb +0 -19
- data/lib/overcommit/plugins/pre_commit/scss_lint.rb +0 -66
- data/lib/overcommit/plugins/pre_commit/test_history.rb +0 -58
- data/lib/overcommit/plugins/pre_commit/whitespace.rb +0 -21
- data/lib/overcommit/plugins/pre_commit/yaml_syntax.rb +0 -22
- data/lib/overcommit/reporter.rb +0 -90
- data/lib/overcommit/staged_file.rb +0 -86
@@ -1,42 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @author kamil@causes.com
|
3
|
-
*
|
4
|
-
* This is a script to run jshint against files passed in via
|
5
|
-
* command line arguments
|
6
|
-
**/
|
7
|
-
|
8
|
-
if (typeof JSHINT === "undefined") {
|
9
|
-
print("jshint not available. Make sure it was included properly.");
|
10
|
-
quit();
|
11
|
-
}
|
12
|
-
|
13
|
-
// Options:
|
14
|
-
// https://gist.github.com/1489652
|
15
|
-
|
16
|
-
var i, j, file, source, result, error,
|
17
|
-
options = {
|
18
|
-
boss: true,
|
19
|
-
curly: true,
|
20
|
-
eqeqeq: true,
|
21
|
-
forin: true,
|
22
|
-
newcap: true
|
23
|
-
};
|
24
|
-
|
25
|
-
for (i = 0; i < arguments.length; i++) {
|
26
|
-
|
27
|
-
file = arguments[i];
|
28
|
-
source = readFile(file);
|
29
|
-
result = JSHINT(source, options);
|
30
|
-
|
31
|
-
if (!result) {
|
32
|
-
for (j = 0; j < JSHINT.errors.length; j++) {
|
33
|
-
error = JSHINT.errors[j];
|
34
|
-
|
35
|
-
print(file + ": line " + error.line + ", col " + error.character + ", " +
|
36
|
-
error.reason);
|
37
|
-
print("\t" + error.evidence);
|
38
|
-
}
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
|
data/lib/overcommit/errors.rb
DELETED
data/lib/overcommit/git_hook.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
module Overcommit
|
2
|
-
module GitHook
|
3
|
-
class BaseHook
|
4
|
-
def initialize
|
5
|
-
Overcommit.config.desired_plugins.each do |plugin|
|
6
|
-
require plugin
|
7
|
-
end
|
8
|
-
rescue LoadError, NameError => ex
|
9
|
-
log.error "Couldn't load plugin: #{ex}"
|
10
|
-
exit 0
|
11
|
-
end
|
12
|
-
|
13
|
-
def run(*args)
|
14
|
-
# Support 'bare' installation where we don't have any hooks yet.
|
15
|
-
# Silently pass.
|
16
|
-
exit unless (checks = registered_checks) && checks.any?
|
17
|
-
|
18
|
-
exit if requires_modified_files? && Utils.modified_files.empty?
|
19
|
-
|
20
|
-
reporter = Reporter.new(Overcommit::Utils.hook_name, checks)
|
21
|
-
|
22
|
-
reporter.print_header
|
23
|
-
|
24
|
-
checks.each do |check_class|
|
25
|
-
check = check_class.new(*args)
|
26
|
-
next if check.skip?
|
27
|
-
|
28
|
-
# Ignore a check if it only applies to a specific file type and there
|
29
|
-
# are no staged files of that type in the tree
|
30
|
-
next if check_class.filetypes && check.staged.empty?
|
31
|
-
|
32
|
-
reporter.with_status(check) do
|
33
|
-
run_and_filter_check(check)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
reporter.print_result
|
38
|
-
end
|
39
|
-
|
40
|
-
def skip_checks
|
41
|
-
@skip_checks ||= ENV.fetch('SKIP_CHECKS', '').split(/[:, ]/)
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def log
|
47
|
-
Logger.instance
|
48
|
-
end
|
49
|
-
|
50
|
-
# Return all loaded plugins, skipping those that are skippable and have
|
51
|
-
# been asked to be skipped by the environment variable SKIP_CHECKS.
|
52
|
-
#
|
53
|
-
# Note that required checks are not skipped even if
|
54
|
-
# `ENV['SKIP_CHECKS'] == 'all'`
|
55
|
-
def registered_checks
|
56
|
-
@registered_checks ||= begin
|
57
|
-
skip_all = skip_checks.include? 'all'
|
58
|
-
HookRegistry.checks.reject do |check|
|
59
|
-
hook_name = Utils.underscorize(check.name).split('/').last
|
60
|
-
|
61
|
-
check.skippable? && (skip_all || skip_checks.include?(hook_name))
|
62
|
-
end.sort_by(&:name)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# If true, only run this check when there are modified files.
|
67
|
-
def requires_modified_files?
|
68
|
-
false
|
69
|
-
end
|
70
|
-
|
71
|
-
# Filters temporary staged file names from the output of the check and
|
72
|
-
# replaces them with their original filenames.
|
73
|
-
def run_and_filter_check(check)
|
74
|
-
status, output = check.run_check
|
75
|
-
|
76
|
-
# Some checks output a list of lines. Join those lines together with newlines.
|
77
|
-
output = Array[output].flatten.join("\n")
|
78
|
-
|
79
|
-
unless output.empty?
|
80
|
-
check.staged.each do |staged_file|
|
81
|
-
output = staged_file.filter_string(output)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
[status, output]
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
module Overcommit
|
2
|
-
module GitHook
|
3
|
-
module HookRegistry
|
4
|
-
@checks = []
|
5
|
-
class << self
|
6
|
-
attr_reader :checks
|
7
|
-
|
8
|
-
def included(base)
|
9
|
-
@checks << base
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class HookSpecificCheck
|
15
|
-
class << self
|
16
|
-
attr_accessor :filetypes, :stealth, :required
|
17
|
-
|
18
|
-
def stealth!
|
19
|
-
self.stealth = true
|
20
|
-
end
|
21
|
-
|
22
|
-
def required!
|
23
|
-
self.required = true
|
24
|
-
end
|
25
|
-
|
26
|
-
# Can the check be skipped by environment variables? This can always be
|
27
|
-
# overriden with `--no-verify`.
|
28
|
-
def skippable?
|
29
|
-
!required
|
30
|
-
end
|
31
|
-
|
32
|
-
def friendly_name
|
33
|
-
Overcommit::Utils.underscorize name.to_s.split('::').last
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def initialize(*args)
|
38
|
-
@arguments = args
|
39
|
-
end
|
40
|
-
|
41
|
-
def name
|
42
|
-
self.class.friendly_name
|
43
|
-
end
|
44
|
-
|
45
|
-
def skip?
|
46
|
-
false
|
47
|
-
end
|
48
|
-
|
49
|
-
def stealth?
|
50
|
-
self.class.stealth
|
51
|
-
end
|
52
|
-
|
53
|
-
def staged
|
54
|
-
@staged ||= modified_files.map do |filename|
|
55
|
-
filetypes = Array(self.class.filetypes).map { |type| ".#{type}" }
|
56
|
-
if filetypes.empty? || filename.end_with?(*filetypes)
|
57
|
-
StagedFile.new(filename)
|
58
|
-
end
|
59
|
-
end.compact
|
60
|
-
end
|
61
|
-
|
62
|
-
def run_check
|
63
|
-
[:bad, 'No checks defined!']
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
def modified_files
|
69
|
-
Overcommit::Utils.modified_files
|
70
|
-
end
|
71
|
-
|
72
|
-
def in_path?(cmd)
|
73
|
-
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
74
|
-
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
75
|
-
exts.each do |ext|
|
76
|
-
exe = File.join(path, "#{cmd}#{ext}")
|
77
|
-
return true if File.executable? exe
|
78
|
-
end
|
79
|
-
end
|
80
|
-
false
|
81
|
-
end
|
82
|
-
|
83
|
-
def commit_message_file
|
84
|
-
unless @arguments[0] && ::File.exist?(@arguments[0])
|
85
|
-
fail 'Not running in the context of a commit message'
|
86
|
-
end
|
87
|
-
|
88
|
-
@arguments[0]
|
89
|
-
end
|
90
|
-
|
91
|
-
def raw_commit_message
|
92
|
-
@raw_commit_message ||= ::IO.readlines(commit_message_file)
|
93
|
-
end
|
94
|
-
|
95
|
-
# Strip comments and diff (from git-commit --verbose)
|
96
|
-
def commit_message
|
97
|
-
@commit_message ||= raw_commit_message.
|
98
|
-
reject { |line| line =~ /^#/ }.
|
99
|
-
take_while { |line| !line.start_with?('diff --git') }
|
100
|
-
end
|
101
|
-
|
102
|
-
class << self
|
103
|
-
def file_type(*types)
|
104
|
-
self.filetypes = types
|
105
|
-
end
|
106
|
-
alias file_types file_type
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Overcommit::GitHook
|
2
|
-
class ChangeID < HookSpecificCheck
|
3
|
-
include HookRegistry
|
4
|
-
|
5
|
-
stealth! # Not really a 'check', but we need it to run
|
6
|
-
required! # Not skipped when ENV['SKIP_CHECKS'] == 'all'
|
7
|
-
|
8
|
-
SCRIPT_LOCATION = Overcommit::Utils.script_path 'gerrit-change-id'
|
9
|
-
|
10
|
-
def run_check
|
11
|
-
system `#{SCRIPT_LOCATION} #{@arguments.join(' ')}`
|
12
|
-
:good
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Overcommit::GitHook
|
2
|
-
class ReleaseNote < HookSpecificCheck
|
3
|
-
include HookRegistry
|
4
|
-
|
5
|
-
EMPTY_RELEASE_NOTE = /^release notes?\s*[:.]?\n{2,}/im
|
6
|
-
def run_check
|
7
|
-
if commit_message.join =~ EMPTY_RELEASE_NOTE
|
8
|
-
strip_release_note
|
9
|
-
return :warn, 'Empty release note found, automatically removed'
|
10
|
-
end
|
11
|
-
|
12
|
-
:good
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def strip_release_note
|
18
|
-
stripped_message = commit_message.join.sub(EMPTY_RELEASE_NOTE, '')
|
19
|
-
|
20
|
-
::File.open(commit_message_file, 'w') do |file|
|
21
|
-
file.write(stripped_message)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Overcommit::GitHook
|
2
|
-
class RussianNovel < HookSpecificCheck
|
3
|
-
include HookRegistry
|
4
|
-
|
5
|
-
stealth!
|
6
|
-
|
7
|
-
RUSSIAN_NOVEL_LENGTH = 30
|
8
|
-
def run_check
|
9
|
-
if commit_message.length > RUSSIAN_NOVEL_LENGTH
|
10
|
-
return :warn, 'You seem to have authored a Russian novel; congratulations!'
|
11
|
-
end
|
12
|
-
|
13
|
-
:good
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Overcommit::GitHook
|
2
|
-
class TextWidth < HookSpecificCheck
|
3
|
-
include HookRegistry
|
4
|
-
|
5
|
-
def run_check
|
6
|
-
if commit_message.first.size > 60
|
7
|
-
return :warn, 'Please keep the subject < ~60 characters'
|
8
|
-
end
|
9
|
-
|
10
|
-
commit_message.each do |line|
|
11
|
-
chomped = line.chomp
|
12
|
-
if chomped.size > 72
|
13
|
-
return :warn, "> 72 characters, please hard wrap: '#{chomped}'"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
:good
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module Overcommit::GitHook
|
2
|
-
class TrailingPeriod < HookSpecificCheck
|
3
|
-
include HookRegistry
|
4
|
-
|
5
|
-
def run_check
|
6
|
-
if commit_message[0].rstrip.end_with?('.')
|
7
|
-
return :warn, 'Please omit trailing period from commit message subject'
|
8
|
-
end
|
9
|
-
|
10
|
-
:good
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Overcommit::GitHook
|
2
|
-
class AuthorName < HookSpecificCheck
|
3
|
-
include HookRegistry
|
4
|
-
|
5
|
-
def run_check
|
6
|
-
name = `git config --get user.name`.chomp
|
7
|
-
unless name.split(' ').count >= 2
|
8
|
-
return :bad, "Author must have at least first and last name; " <<
|
9
|
-
"was: '#{name}'.\n Set your name with " <<
|
10
|
-
"`git config --global user.name 'Your Name'`"
|
11
|
-
end
|
12
|
-
|
13
|
-
:good
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Overcommit::GitHook
|
2
|
-
class CausesEmail < HookSpecificCheck
|
3
|
-
include HookRegistry
|
4
|
-
|
5
|
-
def run_check
|
6
|
-
email = `git config --get user.email`.chomp
|
7
|
-
unless email =~ /@causes\.com$/
|
8
|
-
return :bad, "Author must use a causes.com address; was '#{email}'.\n" <<
|
9
|
-
"Set user with `git config --global user.email YOUR_EMAIL@causes.com`"
|
10
|
-
end
|
11
|
-
|
12
|
-
:good
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Overcommit::GitHook
|
2
|
-
class CoffeeLint < HookSpecificCheck
|
3
|
-
include HookRegistry
|
4
|
-
file_type :coffee
|
5
|
-
|
6
|
-
def run_check
|
7
|
-
unless in_path? 'coffeelint'
|
8
|
-
return :warn, 'Run `npm install -g coffeelint`'
|
9
|
-
end
|
10
|
-
|
11
|
-
paths = staged.collect(&:path).join(' ')
|
12
|
-
output = `coffeelint --quiet #{paths}`.split("\n")
|
13
|
-
return ($?.success? ? :good : :bad), output
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Overcommit::GitHook
|
2
|
-
class CssLinter < HookSpecificCheck
|
3
|
-
include HookRegistry
|
4
|
-
file_type :css
|
5
|
-
|
6
|
-
CSS_LINTER_PATH = Overcommit::Utils.script_path 'csslint-rhino.js'
|
7
|
-
|
8
|
-
def run_check
|
9
|
-
return :warn, "Rhino is not installed" unless in_path? 'rhino'
|
10
|
-
|
11
|
-
paths = staged.collect(&:path).join(' ')
|
12
|
-
|
13
|
-
output = `rhino #{CSS_LINTER_PATH} --quiet --format=compact #{paths} | grep 'Error - '`
|
14
|
-
return (output !~ /Error - (?!Unknown @ rule)/ ? :good : :bad), output
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|