overcommit 0.18.0 → 0.19.0
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 +4 -4
- data/config/default.yml +17 -0
- data/lib/overcommit/git_repo.rb +6 -6
- data/lib/overcommit/hook/pre_commit/brakeman.rb +2 -2
- data/lib/overcommit/hook/pre_commit/image_optim.rb +1 -1
- data/lib/overcommit/hook/pre_commit/jsxcs.rb +28 -0
- data/lib/overcommit/hook/pre_commit/reek.rb +29 -0
- data/lib/overcommit/hook_context/pre_commit.rb +8 -0
- data/lib/overcommit/installer.rb +7 -3
- data/lib/overcommit/utils.rb +39 -2
- data/lib/overcommit/version.rb +1 -1
- data/libexec/index-tags +4 -4
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 996dd0cae1610ccd8862512890ce60c917eb9998
|
4
|
+
data.tar.gz: 8a7a2dc6f4f36ec0d650fea031bff26a963ef510
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40272621da3bd248750062ae0cb16a7c8a5e08fd3cdef1d508579ac740a4ec80a69147e121f66316f3e14c3a68297b5e572b8805fac33294e1c568814aaec3c0
|
7
|
+
data.tar.gz: 2321fa13f258e8d24952655e06f9a3c450a03365759c94dc4e9b60e0a2c6b087e8b7298c168c81a38a4a6577a8f8a86cd80e2f090d8f16df5d87147d10e91fff
|
data/config/default.yml
CHANGED
@@ -131,6 +131,12 @@ PreCommit:
|
|
131
131
|
install_command: 'npm install -g jscs'
|
132
132
|
include: '**/*.js'
|
133
133
|
|
134
|
+
Jsxcs:
|
135
|
+
description: 'Analyzing with JSXCS'
|
136
|
+
required_executable: 'jsxcs'
|
137
|
+
install_command: 'npm install -g jsxcs'
|
138
|
+
include: '**/*.jsx'
|
139
|
+
|
134
140
|
JsHint:
|
135
141
|
description: 'Analyzing with JSHint'
|
136
142
|
required_executable: 'jshint'
|
@@ -173,6 +179,17 @@ PreCommit:
|
|
173
179
|
- 'db/schema.rb'
|
174
180
|
- 'db/structure.sql'
|
175
181
|
|
182
|
+
Reek:
|
183
|
+
description: 'Analyzing with Reek'
|
184
|
+
required_executable: 'reek'
|
185
|
+
install_command: 'gem install reek'
|
186
|
+
include:
|
187
|
+
- '**/*.gemspec'
|
188
|
+
- '**/*.rake'
|
189
|
+
- '**/*.rb'
|
190
|
+
- '**/Gemfile'
|
191
|
+
- '**/Rakefile'
|
192
|
+
|
176
193
|
Rubocop:
|
177
194
|
description: 'Analyzing with Rubocop'
|
178
195
|
required_executable: 'rubocop'
|
data/lib/overcommit/git_repo.rb
CHANGED
@@ -68,7 +68,7 @@ module Overcommit
|
|
68
68
|
@merge_head = merge_head
|
69
69
|
end
|
70
70
|
|
71
|
-
merge_msg_file = File.expand_path('
|
71
|
+
merge_msg_file = File.expand_path('MERGE_MSG', Overcommit::Utils.git_dir)
|
72
72
|
@merge_msg = File.open(merge_msg_file).read if File.exist?(merge_msg_file)
|
73
73
|
end
|
74
74
|
|
@@ -90,16 +90,16 @@ module Overcommit
|
|
90
90
|
# of a merge.
|
91
91
|
def restore_merge_state
|
92
92
|
if @merge_head
|
93
|
-
FileUtils.touch(File.expand_path('
|
93
|
+
FileUtils.touch(File.expand_path('MERGE_MODE', Overcommit::Utils.git_dir))
|
94
94
|
|
95
|
-
File.open(File.expand_path('
|
95
|
+
File.open(File.expand_path('MERGE_HEAD', Overcommit::Utils.git_dir), 'w') do |f|
|
96
96
|
f.write("#{@merge_head}\n")
|
97
97
|
end
|
98
98
|
@merge_head = nil
|
99
99
|
end
|
100
100
|
|
101
101
|
if @merge_msg
|
102
|
-
File.open(File.expand_path('
|
102
|
+
File.open(File.expand_path('MERGE_MSG', Overcommit::Utils.git_dir), 'w') do |f|
|
103
103
|
f.write("#{@merge_msg}\n")
|
104
104
|
end
|
105
105
|
@merge_msg = nil
|
@@ -110,8 +110,8 @@ module Overcommit
|
|
110
110
|
# of a cherry-pick.
|
111
111
|
def restore_cherry_pick_state
|
112
112
|
if @cherry_head
|
113
|
-
File.open(File.expand_path('
|
114
|
-
Overcommit::Utils.
|
113
|
+
File.open(File.expand_path('CHERRY_PICK_HEAD',
|
114
|
+
Overcommit::Utils.git_dir), 'w') do |f|
|
115
115
|
f.write("#{@cherry_head}\n")
|
116
116
|
end
|
117
117
|
@cherry_head = nil
|
@@ -2,8 +2,8 @@ module Overcommit::Hook::PreCommit
|
|
2
2
|
# Runs `brakeman` against any modified Ruby/Rails files.
|
3
3
|
class Brakeman < Base
|
4
4
|
def run
|
5
|
-
result = execute(%W[#{executable} --exit-on-warn --quiet --summary --only-files]
|
6
|
-
applicable_files)
|
5
|
+
result = execute(%W[#{executable} --exit-on-warn --quiet --summary --only-files] <<
|
6
|
+
applicable_files.join(','))
|
7
7
|
return :pass if result.success?
|
8
8
|
|
9
9
|
[:fail, result.stdout]
|
@@ -19,7 +19,7 @@ module Overcommit::Hook::PreCommit
|
|
19
19
|
return :fail,
|
20
20
|
"The following images are optimizable:\n#{optimized_images.join("\n")}" \
|
21
21
|
"\n\nOptimize them by running:\n" \
|
22
|
-
" image_optim #{optimized_images.join(' ')}"
|
22
|
+
" image_optim --no-pngout #{optimized_images.join(' ')}"
|
23
23
|
end
|
24
24
|
|
25
25
|
:pass
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Overcommit::Hook::PreCommit
|
2
|
+
# Runs `jsxcs` (JSCS (JavaScript Code Style Checker) wrapper for JSX files)
|
3
|
+
# against any modified JavaScript files.
|
4
|
+
class Jsxcs < Base
|
5
|
+
def run
|
6
|
+
result = execute(%W[#{executable} --reporter=inline] + applicable_files)
|
7
|
+
return :pass if result.success?
|
8
|
+
|
9
|
+
if result.status == 1
|
10
|
+
return :warn, result.stderr.chomp
|
11
|
+
end
|
12
|
+
|
13
|
+
# Keep lines from the output for files that we actually modified
|
14
|
+
error_lines, warning_lines = result.stdout.split("\n").partition do |output_line|
|
15
|
+
if match = output_line.match(/^([^:]+):[^\d]+(\d+)/)
|
16
|
+
file = match[1]
|
17
|
+
line = match[2]
|
18
|
+
end
|
19
|
+
modified_lines(file).include?(line.to_i)
|
20
|
+
end
|
21
|
+
|
22
|
+
return :fail, error_lines.join("\n") unless error_lines.empty?
|
23
|
+
|
24
|
+
[:warn, "Modified files have lints (on lines you didn't modify)\n" <<
|
25
|
+
warning_lines.join("\n")]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Overcommit::Hook::PreCommit
|
2
|
+
# Runs `reek` against any modified Ruby files.
|
3
|
+
class Reek < Base
|
4
|
+
def run
|
5
|
+
result = execute(%W[#{executable} --single-line --no-color] + applicable_files)
|
6
|
+
return :pass if result.success?
|
7
|
+
|
8
|
+
output = cleanup_output(result.stdout + result.stderr)
|
9
|
+
|
10
|
+
# Keep lines from the output for files that we actually modified
|
11
|
+
error_lines, warning_lines = output.partition do |output_line|
|
12
|
+
if (match = output_line.match(/^([^:]+):(\d+)/))
|
13
|
+
file = match[1]
|
14
|
+
line = match[2]
|
15
|
+
end
|
16
|
+
modified_lines(file).include?(line.to_i)
|
17
|
+
end
|
18
|
+
|
19
|
+
return :fail, error_lines.join("\n") unless error_lines.empty?
|
20
|
+
|
21
|
+
[:warn, "Modified files have lints (on lines you didn't modify)\n" <<
|
22
|
+
warning_lines.join("\n")]
|
23
|
+
end
|
24
|
+
|
25
|
+
def cleanup_output(raw_output)
|
26
|
+
raw_output.split("\n").grep(/^(.(?!warning))*$/)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -40,13 +40,20 @@ module Overcommit::HookContext
|
|
40
40
|
|
41
41
|
# Restore unstaged changes and reset file modification times so it appears
|
42
42
|
# as if nothing ever changed.
|
43
|
+
#
|
44
|
+
# We want to restore the modification times for each of the files after
|
45
|
+
# every step to ensure as little time as possible has passed while the
|
46
|
+
# modification time on the file was newer. This helps us play more nicely
|
47
|
+
# with file watchers.
|
43
48
|
def cleanup_environment
|
44
49
|
unless initial_commit? || (@stash_attempted && !@changes_stashed)
|
45
50
|
clear_working_tree # Ensure working tree is clean before restoring it
|
51
|
+
restore_modified_times
|
46
52
|
end
|
47
53
|
|
48
54
|
if @changes_stashed
|
49
55
|
restore_working_tree
|
56
|
+
restore_modified_times
|
50
57
|
end
|
51
58
|
|
52
59
|
Overcommit::GitRepo.restore_merge_state
|
@@ -124,6 +131,7 @@ module Overcommit::HookContext
|
|
124
131
|
def restore_modified_times
|
125
132
|
modified_files.each do |file|
|
126
133
|
next if Overcommit::Utils.broken_symlink?(file)
|
134
|
+
next unless File.exist?(file)
|
127
135
|
time = @modified_times[file]
|
128
136
|
File.utime(time, time, file)
|
129
137
|
end
|
data/lib/overcommit/installer.rb
CHANGED
@@ -2,7 +2,7 @@ require 'fileutils'
|
|
2
2
|
|
3
3
|
module Overcommit
|
4
4
|
# Manages the installation of Overcommit hooks in a git repository.
|
5
|
-
class Installer
|
5
|
+
class Installer # rubocop:disable ClassLength
|
6
6
|
MASTER_HOOK =
|
7
7
|
File.join(OVERCOMMIT_HOME, 'template-dir', 'hooks', 'overcommit-hook')
|
8
8
|
|
@@ -60,7 +60,7 @@ module Overcommit
|
|
60
60
|
|
61
61
|
def hooks_path
|
62
62
|
absolute_target = File.expand_path(@target)
|
63
|
-
File.join(absolute_target, '
|
63
|
+
File.join(Overcommit::Utils.git_dir(absolute_target), 'hooks')
|
64
64
|
end
|
65
65
|
|
66
66
|
def master_hook_install_path
|
@@ -78,7 +78,11 @@ module Overcommit
|
|
78
78
|
raise Overcommit::Exceptions::InvalidGitRepo, 'is not a directory'
|
79
79
|
end
|
80
80
|
|
81
|
-
|
81
|
+
git_dir_check = Dir.chdir(absolute_target) do
|
82
|
+
Overcommit::Utils.execute(%w[git rev-parse --git-dir])
|
83
|
+
end
|
84
|
+
|
85
|
+
unless git_dir_check.success?
|
82
86
|
raise Overcommit::Exceptions::InvalidGitRepo, 'does not appear to be a git repository'
|
83
87
|
end
|
84
88
|
end
|
data/lib/overcommit/utils.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'pathname'
|
1
2
|
require 'overcommit/subprocess'
|
2
3
|
|
3
4
|
module Overcommit
|
@@ -9,11 +10,47 @@ module Overcommit
|
|
9
10
|
end
|
10
11
|
|
11
12
|
# Returns an absolute path to the root of the repository.
|
13
|
+
#
|
14
|
+
# We do this ourselves rather than call `git rev-parse --show-toplevel` to
|
15
|
+
# solve an issue where the .git directory might not actually be valid in
|
16
|
+
# tests.
|
17
|
+
#
|
18
|
+
# @return [String]
|
12
19
|
def repo_root
|
13
20
|
@repo_root ||=
|
14
21
|
begin
|
15
|
-
|
16
|
-
|
22
|
+
git_dir = Pathname.new(File.expand_path('.')).enum_for(:ascend).find do |path|
|
23
|
+
File.exist?(File.join(path, '.git'))
|
24
|
+
end
|
25
|
+
|
26
|
+
unless git_dir
|
27
|
+
raise Overcommit::Exceptions::InvalidGitRepo, 'no .git directory found'
|
28
|
+
end
|
29
|
+
|
30
|
+
git_dir.to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns an absolute path to the .git directory for a repo.
|
35
|
+
#
|
36
|
+
# @param repo_dir [String] root directory of git repo
|
37
|
+
# @return [String]
|
38
|
+
def git_dir(repo_dir = repo_root)
|
39
|
+
@git_dir ||=
|
40
|
+
begin
|
41
|
+
git_dir = File.expand_path('.git', repo_dir)
|
42
|
+
|
43
|
+
# .git could also be a file that contains the location of the git directory
|
44
|
+
unless File.directory?(git_dir)
|
45
|
+
git_dir = File.read(git_dir)[/^gitdir: (.*)$/, 1]
|
46
|
+
|
47
|
+
# Resolve relative paths
|
48
|
+
unless git_dir.start_with?('/')
|
49
|
+
git_dir = File.expand_path(git_dir, repo_dir)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
git_dir
|
17
54
|
end
|
18
55
|
end
|
19
56
|
|
data/lib/overcommit/version.rb
CHANGED
data/libexec/index-tags
CHANGED
@@ -6,10 +6,10 @@
|
|
6
6
|
|
7
7
|
set -e
|
8
8
|
|
9
|
-
trap "rm -f
|
10
|
-
err_file
|
11
|
-
if ctags --tag-relative -Rf
|
12
|
-
mv
|
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
13
|
[ -e ${err_file} ] && rm -f ${err_file}
|
14
14
|
else
|
15
15
|
# Ignore STDERR unless `ctags` returned a non-zero exit code
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: overcommit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Causes Engineering
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-11-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: childprocess
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- lib/overcommit/hook/base.rb
|
100
100
|
- lib/overcommit/hook/pre_commit/author_email.rb
|
101
101
|
- lib/overcommit/hook/pre_commit/pry_binding.rb
|
102
|
+
- lib/overcommit/hook/pre_commit/jsxcs.rb
|
102
103
|
- lib/overcommit/hook/pre_commit/image_optim.rb
|
103
104
|
- lib/overcommit/hook/pre_commit/css_lint.rb
|
104
105
|
- lib/overcommit/hook/pre_commit/jsx_hint.rb
|
@@ -120,6 +121,7 @@ files:
|
|
120
121
|
- lib/overcommit/hook/pre_commit/haml_lint.rb
|
121
122
|
- lib/overcommit/hook/pre_commit/coffee_lint.rb
|
122
123
|
- lib/overcommit/hook/pre_commit/brakeman.rb
|
124
|
+
- lib/overcommit/hook/pre_commit/reek.rb
|
123
125
|
- lib/overcommit/hook/pre_commit/jscs.rb
|
124
126
|
- lib/overcommit/hook/pre_commit/scss_lint.rb
|
125
127
|
- lib/overcommit/hook/pre_commit/base.rb
|