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,86 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
require 'tempfile'
|
3
|
-
|
4
|
-
# We run syntax checks against the version of the file that is staged in
|
5
|
-
# the index, not the one in the work tree. This class is a simple wrapper
|
6
|
-
# to make working with staged files easier.
|
7
|
-
module Overcommit
|
8
|
-
class StagedFile
|
9
|
-
attr_reader :contents, :original_path
|
10
|
-
|
11
|
-
def initialize(path)
|
12
|
-
@original_path = path
|
13
|
-
@contents = `git show :#{@original_path}`
|
14
|
-
end
|
15
|
-
|
16
|
-
# Given error output from a syntax checker, replace references to the
|
17
|
-
# temporary file path with the original path.
|
18
|
-
def filter_string(string)
|
19
|
-
string.gsub(path, @original_path)
|
20
|
-
end
|
21
|
-
|
22
|
-
# The path of the temporary file on disk, suitable for feeding in to a
|
23
|
-
# syntax checker.
|
24
|
-
def path
|
25
|
-
tempfile.path
|
26
|
-
end
|
27
|
-
|
28
|
-
# Set or overwrite the temporary file's contents.
|
29
|
-
#
|
30
|
-
# This is used by the ERB syntax checker, for example, to compile
|
31
|
-
# the template before checking.
|
32
|
-
def contents=(contents)
|
33
|
-
@contents = contents
|
34
|
-
write_tempfile
|
35
|
-
end
|
36
|
-
|
37
|
-
# Returns the set of line numbers corresponding to the lines that were
|
38
|
-
# changed in this file.
|
39
|
-
def modified_lines
|
40
|
-
@modified_lines ||= extract_modified_lines
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
DIFF_HUNK_REGEX = /
|
46
|
-
^@@\s
|
47
|
-
[^\s]+\s # Ignore old file range
|
48
|
-
\+(\d+)(?:,(\d+))? # Extract range of hunk containing start line and number of lines
|
49
|
-
\s@@.*$
|
50
|
-
/x
|
51
|
-
|
52
|
-
def extract_modified_lines
|
53
|
-
lines = Set.new
|
54
|
-
|
55
|
-
`git diff --no-ext-diff --cached -U0 -- #{@original_path}`.
|
56
|
-
scan(DIFF_HUNK_REGEX) do |start_line, lines_added|
|
57
|
-
|
58
|
-
lines_added = (lines_added || 1).to_i # When blank, one line was added
|
59
|
-
cur_line = start_line.to_i
|
60
|
-
|
61
|
-
lines_added.times do
|
62
|
-
lines.add cur_line
|
63
|
-
cur_line += 1
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
lines
|
68
|
-
end
|
69
|
-
|
70
|
-
def tempfile
|
71
|
-
unless @tempfile
|
72
|
-
basename = [@original_path.gsub('/', '_'), File.extname(@original_path)]
|
73
|
-
@tempfile = Tempfile.new(basename)
|
74
|
-
write_tempfile
|
75
|
-
end
|
76
|
-
@tempfile
|
77
|
-
end
|
78
|
-
|
79
|
-
def write_tempfile
|
80
|
-
tempfile.open if tempfile.closed?
|
81
|
-
tempfile.truncate 0
|
82
|
-
tempfile.write @contents
|
83
|
-
tempfile.close
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|