overcommit 0.6.3 → 0.7.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/lib/overcommit/cli.rb +7 -0
- data/lib/overcommit/hook/base.rb +2 -2
- data/lib/overcommit/hook/commit_msg/gerrit_change_id.rb +1 -1
- data/lib/overcommit/hook/post_checkout/bundle_check.rb +2 -2
- data/lib/overcommit/hook/pre_commit/author_email.rb +1 -1
- data/lib/overcommit/hook/pre_commit/author_name.rb +1 -1
- data/lib/overcommit/hook/pre_commit/bundle_check.rb +3 -3
- data/lib/overcommit/hook/pre_commit/coffee_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/css_lint.rb +1 -3
- data/lib/overcommit/hook/pre_commit/haml_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/hard_tabs.rb +1 -3
- data/lib/overcommit/hook/pre_commit/js_hint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/jscs.rb +1 -1
- data/lib/overcommit/hook/pre_commit/python_flake8.rb +1 -1
- data/lib/overcommit/hook/pre_commit/rubocop.rb +4 -2
- data/lib/overcommit/hook/pre_commit/scss_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/trailing_whitespace.rb +1 -3
- data/lib/overcommit/installer.rb +4 -0
- data/lib/overcommit/subprocess.rb +37 -0
- data/lib/overcommit/utils.rb +3 -3
- data/lib/overcommit/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92e61229cb593b12785dc6f250aaf20b59335277
|
4
|
+
data.tar.gz: 6109a2ebdd9e9ad8fb6612178dc38c919decc366
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a30a6cef4ea66c146c536e3868e12e2ce8a80dbc4c10955e3e6f18990dc0f75a21e439032bdcd180086aa6fd47a4a327d9ca36441f654f4e1400777ce333d8c
|
7
|
+
data.tar.gz: 1d0a931ee95dac1fa0f7bf35f3e154033d831df840f1ba30772108612bc5aafd52315bded077ec359873cc2d3298f76aca2800fec55ae862b89f45867af15b11
|
data/lib/overcommit/cli.rb
CHANGED
@@ -45,6 +45,10 @@ module Overcommit
|
|
45
45
|
@options[:action] = :install
|
46
46
|
end
|
47
47
|
|
48
|
+
opts.on('-f', '--force', 'Overwrite any previously installed hooks') do
|
49
|
+
@options[:force] = true
|
50
|
+
end
|
51
|
+
|
48
52
|
opts.on('-t', '--template-dir', 'Print location of template directory') do
|
49
53
|
@options[:action] = :template_dir
|
50
54
|
end
|
@@ -81,6 +85,9 @@ module Overcommit
|
|
81
85
|
rescue Overcommit::Exceptions::InvalidGitRepo => error
|
82
86
|
log.warning "Invalid repo #{target}: #{error}"
|
83
87
|
halt 69 # EX_UNAVAILABLE
|
88
|
+
rescue Overcommit::Exceptions::PreExistingHooks => error
|
89
|
+
log.warning "Unable to install into #{target}: #{error}"
|
90
|
+
halt 73 # EX_CANTCREAT
|
84
91
|
end
|
85
92
|
end
|
86
93
|
end
|
data/lib/overcommit/hook/base.rb
CHANGED
@@ -51,8 +51,8 @@ module Overcommit::Hook
|
|
51
51
|
Overcommit::Utils.in_path?(cmd)
|
52
52
|
end
|
53
53
|
|
54
|
-
def
|
55
|
-
Overcommit::Utils.
|
54
|
+
def execute(cmd)
|
55
|
+
Overcommit::Utils.execute(cmd)
|
56
56
|
end
|
57
57
|
|
58
58
|
# Gets a list of staged files that apply to this hook based on its
|
@@ -7,7 +7,7 @@ module Overcommit::Hook::CommitMsg
|
|
7
7
|
# edit the message after a prepare-commit-msg hook was run.
|
8
8
|
class GerritChangeId < Base
|
9
9
|
def run
|
10
|
-
result =
|
10
|
+
result = execute([SCRIPT_LOCATION, commit_message_file])
|
11
11
|
return (result.success? ? :good : :bad), result.stdout
|
12
12
|
end
|
13
13
|
|
@@ -15,7 +15,7 @@ module Overcommit::Hook::PostCheckout
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def dependencies_changed?
|
18
|
-
result =
|
18
|
+
result = execute(%w[git diff --exit-code --name-only] + [new_head, previous_head])
|
19
19
|
|
20
20
|
result.stdout.split("\n").any? do |file|
|
21
21
|
Array(@config['include']).any? { |glob| File.fnmatch(glob, file) }
|
@@ -23,7 +23,7 @@ module Overcommit::Hook::PostCheckout
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def dependencies_satisfied?
|
26
|
-
|
26
|
+
execute(%w[bundle check]).success?
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -2,7 +2,7 @@ module Overcommit::Hook::PreCommit
|
|
2
2
|
# Checks the format of an author's email address.
|
3
3
|
class AuthorEmail < Base
|
4
4
|
def run
|
5
|
-
result =
|
5
|
+
result = execute(%w[git config --get user.email])
|
6
6
|
email = result.stdout.chomp
|
7
7
|
|
8
8
|
unless email =~ /#{@config['pattern']}/
|
@@ -2,7 +2,7 @@ module Overcommit::Hook::PreCommit
|
|
2
2
|
# Ensures that a commit author has a name with at least first and last names.
|
3
3
|
class AuthorName < Base
|
4
4
|
def run
|
5
|
-
result =
|
5
|
+
result = execute(%w[git config --get user.name])
|
6
6
|
name = result.stdout.chomp
|
7
7
|
|
8
8
|
unless name.split(' ').count >= 2
|
@@ -8,14 +8,14 @@ module Overcommit::Hook::PreCommit
|
|
8
8
|
end
|
9
9
|
|
10
10
|
# Ignore if Gemfile.lock is not tracked by git
|
11
|
-
return :good if
|
11
|
+
return :good if execute(%w[git check-ignore] + [LOCK_FILE]).success?
|
12
12
|
|
13
|
-
result =
|
13
|
+
result = execute(%w[bundle check])
|
14
14
|
unless result.success?
|
15
15
|
return :bad, result.stdout
|
16
16
|
end
|
17
17
|
|
18
|
-
result =
|
18
|
+
result = execute(%w[git diff --quiet --] + [LOCK_FILE])
|
19
19
|
unless result.success?
|
20
20
|
return :bad, "#{LOCK_FILE} is not up-to-date -- run `bundle check`"
|
21
21
|
end
|
@@ -6,7 +6,7 @@ module Overcommit::Hook::PreCommit
|
|
6
6
|
return :warn, 'Run `npm install -g coffeelint`'
|
7
7
|
end
|
8
8
|
|
9
|
-
result =
|
9
|
+
result = execute(%w[coffeelint --quiet] + applicable_files)
|
10
10
|
return :good if result.success?
|
11
11
|
return :bad, result.stdout
|
12
12
|
end
|
@@ -6,9 +6,7 @@ module Overcommit::Hook::PreCommit
|
|
6
6
|
return :warn, 'csslint not installed -- run `npm install -g csslint`'
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
result = command("csslint --quiet --format=compact #{paths} | grep 'Error - '")
|
9
|
+
result = execute(%w[csslint --quiet --format=compact] + applicable_files)
|
12
10
|
output = result.stdout
|
13
11
|
return (output !~ /Error - (?!Unknown @ rule)/ ? :good : :bad), output
|
14
12
|
end
|
@@ -6,7 +6,7 @@ module Overcommit::Hook::PreCommit
|
|
6
6
|
return :warn, 'haml-lint not installed -- run `gem install haml-lint`'
|
7
7
|
end
|
8
8
|
|
9
|
-
result =
|
9
|
+
result = execute(%w[haml-lint] + applicable_files)
|
10
10
|
return :good if result.success?
|
11
11
|
|
12
12
|
# Keep lines from the output for files that we actually modified
|
@@ -2,10 +2,8 @@ module Overcommit::Hook::PreCommit
|
|
2
2
|
# Checks for hard tabs in files.
|
3
3
|
class HardTabs < Base
|
4
4
|
def run
|
5
|
-
paths = applicable_files.join(' ')
|
6
|
-
|
7
5
|
# Catches hard tabs
|
8
|
-
result =
|
6
|
+
result = execute(%w[grep -IHn] + ["\t"] + applicable_files)
|
9
7
|
unless result.stdout.empty?
|
10
8
|
return :bad, "Hard tabs detected:\n#{result.stdout}"
|
11
9
|
end
|
@@ -6,7 +6,7 @@ module Overcommit::Hook::PreCommit
|
|
6
6
|
return :warn, 'jshint not installed -- run `npm install -g jshint`'
|
7
7
|
end
|
8
8
|
|
9
|
-
result =
|
9
|
+
result = execute(%w[jshint] + applicable_files)
|
10
10
|
output = result.stdout
|
11
11
|
|
12
12
|
return (output.empty? ? :good : :bad), output
|
@@ -7,7 +7,7 @@ module Overcommit::Hook::PreCommit
|
|
7
7
|
return :warn, 'jscs not installed -- run `npm install -g jscs`'
|
8
8
|
end
|
9
9
|
|
10
|
-
result =
|
10
|
+
result = execute(%w[jscs --reporter=inline] + applicable_files)
|
11
11
|
return :good if result.success?
|
12
12
|
|
13
13
|
if /Config.*not found/i =~ result.stderr
|
@@ -6,7 +6,7 @@ module Overcommit::Hook::PreCommit
|
|
6
6
|
return :warn, 'flake8 not installed -- run `pip install flake8`'
|
7
7
|
end
|
8
8
|
|
9
|
-
result =
|
9
|
+
result = execute(%w[flake8] + applicable_files)
|
10
10
|
|
11
11
|
return (result.success? ? :good : :bad), result.stdout
|
12
12
|
end
|
@@ -6,11 +6,13 @@ module Overcommit::Hook::PreCommit
|
|
6
6
|
return :warn, 'Rubocop not installed -- run `gem install rubocop`'
|
7
7
|
end
|
8
8
|
|
9
|
-
result =
|
9
|
+
result = execute(%w[rubocop --format=emacs] + applicable_files)
|
10
10
|
return :good if result.success?
|
11
11
|
|
12
|
+
output = result.stdout + result.stderr
|
13
|
+
|
12
14
|
# Keep lines from the output for files that we actually modified
|
13
|
-
error_lines, warning_lines =
|
15
|
+
error_lines, warning_lines = output.split("\n").partition do |output_line|
|
14
16
|
if match = output_line.match(/^([^:]+):(\d+)/)
|
15
17
|
file = match[1]
|
16
18
|
line = match[2]
|
@@ -6,7 +6,7 @@ module Overcommit::Hook::PreCommit
|
|
6
6
|
return :warn, 'scss-lint not installed -- run `gem install scss-lint`'
|
7
7
|
end
|
8
8
|
|
9
|
-
result =
|
9
|
+
result = execute(%w[scss-lint] + applicable_files)
|
10
10
|
return :good if result.success?
|
11
11
|
|
12
12
|
# Keep lines from the output for files that we actually modified
|
@@ -2,9 +2,7 @@ module Overcommit::Hook::PreCommit
|
|
2
2
|
# Checks for trailing whitespace in files.
|
3
3
|
class TrailingWhitespace < Base
|
4
4
|
def run
|
5
|
-
|
6
|
-
|
7
|
-
result = command("grep -IHn \"\\s$\" #{paths}")
|
5
|
+
result = execute(%w[grep -IHn \s$] + applicable_files)
|
8
6
|
unless result.stdout.empty?
|
9
7
|
return :bad, "Trailing whitespace detected:\n#{result.stdout}"
|
10
8
|
end
|
data/lib/overcommit/installer.rb
CHANGED
@@ -101,6 +101,10 @@ module Overcommit
|
|
101
101
|
|
102
102
|
def overcommit_symlink?(file)
|
103
103
|
File.symlink?(file) && File.readlink(file) == 'overcommit-hook'
|
104
|
+
rescue Errno::ENOENT
|
105
|
+
# Some Ruby implementations (e.g. JRuby) raise an error when the file
|
106
|
+
# doesn't exist. Standardize the behavior to return false.
|
107
|
+
false
|
104
108
|
end
|
105
109
|
end
|
106
110
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'childprocess'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
module Overcommit
|
5
|
+
# Manages execution of a child process, collecting the exit status and
|
6
|
+
# standard out/error output.
|
7
|
+
class Subprocess
|
8
|
+
# Encapsulates the result of a process.
|
9
|
+
Result = Struct.new(:status, :stderr, :stdout) do
|
10
|
+
def success?
|
11
|
+
status == 0
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Spawns a new process using the given array of arguments (the first
|
16
|
+
# element is the command).
|
17
|
+
def self.spawn(args)
|
18
|
+
process = ChildProcess.build(*args)
|
19
|
+
|
20
|
+
err = ::Tempfile.new('err')
|
21
|
+
err.sync = true
|
22
|
+
out = ::Tempfile.new('out')
|
23
|
+
out.sync = true
|
24
|
+
|
25
|
+
process.io.stderr = err
|
26
|
+
process.io.stdout = out
|
27
|
+
|
28
|
+
process.start
|
29
|
+
process.wait
|
30
|
+
|
31
|
+
err.rewind
|
32
|
+
out.rewind
|
33
|
+
|
34
|
+
Result.new(process.exit_code, err.read, out.read)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/overcommit/utils.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'overcommit/subprocess'
|
2
2
|
|
3
3
|
module Overcommit
|
4
4
|
# Utility functions for general use.
|
@@ -62,9 +62,9 @@ module Overcommit
|
|
62
62
|
# Overcommit to call other Ruby executables without requiring that they be
|
63
63
|
# specified in Overcommit's Gemfile--a nasty consequence of using
|
64
64
|
# `bundle exec overcommit` while developing locally.
|
65
|
-
def
|
65
|
+
def execute(args)
|
66
66
|
with_environment 'RUBYOPT' => nil do
|
67
|
-
|
67
|
+
Subprocess.spawn(args)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
data/lib/overcommit/version.rb
CHANGED
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.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Causes Engineering
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: childprocess
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
18
|
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 0.5.1
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 0.5.1
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rspec
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - '='
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 0.
|
48
|
+
version: 0.12.0
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - '='
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
55
|
+
version: 0.12.0
|
56
56
|
description: Utility to install, configure, and extend Git hooks
|
57
57
|
email:
|
58
58
|
- eng@causes.com
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/overcommit/constants.rb
|
72
72
|
- lib/overcommit/utils.rb
|
73
73
|
- lib/overcommit/hook_runner.rb
|
74
|
+
- lib/overcommit/subprocess.rb
|
74
75
|
- lib/overcommit/hook/commit_msg/trailing_period.rb
|
75
76
|
- lib/overcommit/hook/commit_msg/gerrit_change_id.rb
|
76
77
|
- lib/overcommit/hook/commit_msg/single_line_subject.rb
|