pre-commit 0.8.1 → 0.9.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 +7 -0
- data/README.md +2 -3
- data/bin/pre-commit +1 -2
- data/lib/pre-commit/checks/ci_check.rb +3 -42
- data/lib/pre-commit/checks/closure_check.rb +13 -0
- data/lib/pre-commit/checks/console_log_check.rb +11 -0
- data/lib/pre-commit/checks/debugger_check.rb +5 -42
- data/lib/pre-commit/checks/gemfile_path_check.rb +12 -0
- data/lib/pre-commit/checks/js_check.rb +10 -36
- data/lib/pre-commit/checks/jshint_check.rb +9 -18
- data/lib/pre-commit/checks/jslint_check.rb +4 -21
- data/lib/pre-commit/checks/local_check.rb +4 -21
- data/lib/pre-commit/checks/merge_conflict_check.rb +10 -0
- data/lib/pre-commit/checks/migration_check.rb +5 -32
- data/lib/pre-commit/checks/nb_space_check.rb +21 -0
- data/lib/pre-commit/checks/php_check.rb +9 -57
- data/lib/pre-commit/checks/pry_check.rb +5 -42
- data/lib/pre-commit/checks/rspec_focus_check.rb +6 -49
- data/lib/pre-commit/checks/rubocop_check.rb +17 -34
- data/lib/pre-commit/checks/ruby_symbol_hashrockets.rb +5 -46
- data/lib/pre-commit/checks/tabs_check.rb +12 -0
- data/lib/pre-commit/checks/whitespace_check.rb +16 -0
- data/lib/pre-commit/checks.rb +39 -41
- data/lib/pre-commit/cli.rb +1 -28
- data/lib/{support → pre-commit/support}/closure/compiler.jar +0 -0
- data/lib/{support → pre-commit/support}/jshint/jshint.js +0 -0
- data/lib/{support → pre-commit/support}/jslint/lint.js +0 -0
- data/{templates → lib/pre-commit/support/templates}/pre-commit-hook +0 -0
- data/lib/pre-commit/utils.rb +9 -12
- metadata +20 -24
- data/lib/pre-commit/base.rb +0 -7
- data/lib/pre-commit/checks/console_log.rb +0 -43
- data/lib/pre-commit/checks/merge_conflict.rb +0 -34
- data/lib/pre-commit/checks/tabs.rb +0 -54
- data/lib/support/all.rb +0 -2
- data/lib/support/closure/closure_checker.rb +0 -10
- data/lib/support/whitespace/whitespace +0 -46
- data/lib/support/whitespace/whitespace_checker.rb +0 -9
@@ -1,38 +1,15 @@
|
|
1
|
-
require 'pre-commit/base'
|
2
1
|
require 'pre-commit/utils'
|
3
2
|
require 'rubocop'
|
3
|
+
require 'stringio'
|
4
4
|
|
5
5
|
module PreCommit
|
6
6
|
class RubocopCheck
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def check_name
|
11
|
-
"Rubocop"
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(type = :all)
|
15
|
-
@type = type
|
16
|
-
end
|
17
|
-
|
18
|
-
def files_to_check
|
19
|
-
case @type
|
20
|
-
when :new
|
21
|
-
Utils.new_files('.').split(" ")
|
22
|
-
else
|
23
|
-
Utils.staged_files('.').split(" ")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def reject_non_rb(staged_files)
|
28
|
-
staged_files.select { |f| f =~ /\.rb$/ }
|
29
|
-
end
|
30
|
-
|
31
|
-
def call
|
32
|
-
rb_files = reject_non_rb(files_to_check)
|
33
|
-
return true if rb_files.empty?
|
7
|
+
def self.call(staged_files)
|
8
|
+
staged_files = staged_files.grep(/\.rb$/)
|
9
|
+
return if staged_files.empty?
|
34
10
|
config_file = `git config pre-commit.rubocop.config`.chomp
|
35
|
-
|
11
|
+
|
12
|
+
args = staged_files
|
36
13
|
if !config_file.empty?
|
37
14
|
if !File.exist? config_file
|
38
15
|
$stderr.puts "Warning: rubocop config file '" + config_file + "' does not exist"
|
@@ -43,13 +20,19 @@ module PreCommit
|
|
43
20
|
args = ['-c', config_file] + args
|
44
21
|
end
|
45
22
|
end
|
46
|
-
run(args)
|
47
|
-
end
|
48
23
|
|
49
|
-
|
50
|
-
|
51
|
-
return rubocop.run(rb_files) == 0
|
24
|
+
success, captured = capture { Rubocop::CLI.new.run(args) == 0 }
|
25
|
+
captured unless success
|
52
26
|
end
|
53
27
|
|
28
|
+
def self.capture
|
29
|
+
$stdout, stdout = StringIO.new, $stdout
|
30
|
+
$stderr, stderr = StringIO.new, $stderr
|
31
|
+
result = yield
|
32
|
+
[result, $stdout.string + $stderr.string]
|
33
|
+
ensure
|
34
|
+
$stdout = stdout
|
35
|
+
$stderr = stderr
|
36
|
+
end
|
54
37
|
end
|
55
38
|
end
|
@@ -2,54 +2,13 @@ require 'pre-commit/utils'
|
|
2
2
|
|
3
3
|
module PreCommit
|
4
4
|
class RubySymbolHashrockets
|
5
|
-
|
6
|
-
attr_accessor :staged_files, :error_message
|
7
|
-
|
8
5
|
HASHROCKET_PATTERN = '[^:](:{1}(?:\$|@|@@|[_A-Za-z])?\w*[=!?]?\s*=>\s*)'
|
9
6
|
|
10
|
-
def self.call
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
if !result
|
16
|
-
$stderr.puts check.error_message
|
17
|
-
$stderr.puts
|
18
|
-
$stderr.puts 'pre-commit: You can bypass this check using `git commit -n`'
|
19
|
-
$stderr.puts
|
20
|
-
end
|
21
|
-
|
22
|
-
result
|
7
|
+
def self.call(staged_files)
|
8
|
+
return if staged_files.empty?
|
9
|
+
lines = `#{Utils.grep} '#{HASHROCKET_PATTERN}' #{staged_files.join(" ")}`.strip
|
10
|
+
return unless $?.success?
|
11
|
+
"detected :symbol => value hashrocket:\n#{lines}"
|
23
12
|
end
|
24
|
-
|
25
|
-
def run
|
26
|
-
# There is nothing to check
|
27
|
-
return true if staged_files.empty?
|
28
|
-
|
29
|
-
if detected_bad_code?
|
30
|
-
@error_message = "pre-commit: detected :symbol => value hashrocket:\n"
|
31
|
-
@error_message += violations[:lines]
|
32
|
-
|
33
|
-
@passed = false
|
34
|
-
else
|
35
|
-
@passed = true
|
36
|
-
end
|
37
|
-
|
38
|
-
@passed
|
39
|
-
end
|
40
|
-
|
41
|
-
def detected_bad_code?
|
42
|
-
violations[:success]
|
43
|
-
end
|
44
|
-
|
45
|
-
def violations
|
46
|
-
@violations ||= begin
|
47
|
-
lines = `#{Utils.grep} '#{HASHROCKET_PATTERN}' #{staged_files}`
|
48
|
-
success = $?.exitstatus == 0
|
49
|
-
|
50
|
-
{ :lines => lines, :success => success}
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
13
|
end
|
55
14
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module PreCommit
|
2
|
+
class TabsCheck
|
3
|
+
LEADING_TAB_PATTERN = '^ *\t'
|
4
|
+
|
5
|
+
def self.call(staged_files)
|
6
|
+
return if staged_files.empty?
|
7
|
+
errors = `#{Utils.grep} '#{LEADING_TAB_PATTERN}' #{staged_files.join(" ")}`.strip
|
8
|
+
return unless $?.success?
|
9
|
+
"detected tab before initial space:\n#{errors}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module PreCommit
|
2
|
+
class WhiteSpaceCheck
|
3
|
+
def self.call(_)
|
4
|
+
errors = `git diff-index --check --cached head -- 2>&1`
|
5
|
+
return if $?.success?
|
6
|
+
|
7
|
+
# Initial commit: diff against the empty tree object
|
8
|
+
if errors =~ /fatal: bad revision 'head'/
|
9
|
+
errors = `git diff-index --check --cached 4b825dc642cb6eb9a060e54bf8d69288fbee4904 -- 2>&1`
|
10
|
+
return if $?.success?
|
11
|
+
end
|
12
|
+
|
13
|
+
errors
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/pre-commit/checks.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require 'support/all'
|
2
1
|
require 'pre-commit/utils'
|
3
|
-
require 'pre-commit/checks/
|
4
|
-
require 'pre-commit/checks/
|
5
|
-
require 'pre-commit/checks/
|
2
|
+
require 'pre-commit/checks/merge_conflict_check'
|
3
|
+
require 'pre-commit/checks/tabs_check'
|
4
|
+
require 'pre-commit/checks/console_log_check'
|
6
5
|
require 'pre-commit/checks/debugger_check'
|
7
6
|
require 'pre-commit/checks/local_check'
|
7
|
+
require 'pre-commit/checks/nb_space_check'
|
8
8
|
require 'pre-commit/checks/jslint_check'
|
9
9
|
require 'pre-commit/checks/jshint_check'
|
10
10
|
require 'pre-commit/checks/migration_check'
|
@@ -13,50 +13,36 @@ require 'pre-commit/checks/php_check'
|
|
13
13
|
require 'pre-commit/checks/pry_check'
|
14
14
|
require 'pre-commit/checks/rspec_focus_check'
|
15
15
|
require 'pre-commit/checks/ruby_symbol_hashrockets'
|
16
|
+
require 'pre-commit/checks/whitespace_check'
|
17
|
+
require 'pre-commit/checks/closure_check'
|
18
|
+
require 'pre-commit/checks/gemfile_path_check'
|
16
19
|
begin
|
17
20
|
require 'pre-commit/checks/rubocop_check'
|
18
21
|
rescue LoadError # no rubocop
|
19
22
|
end
|
20
23
|
|
21
24
|
module PreCommit
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
ClosureSyntaxCheck = lambda {
|
28
|
-
if File.exists?('public/javascripts') && (args = Utils.staged_files('public/javascripts')).size > 0
|
29
|
-
ClosureChecker.check(args.split(" "))
|
30
|
-
else
|
31
|
-
true
|
32
|
-
end
|
33
|
-
}
|
34
|
-
|
35
|
-
Checks = {
|
36
|
-
:white_space => WhiteSpace,
|
37
|
-
:console_log => ConsoleLog,
|
38
|
-
:js_lint_all => JslintCheck.new(:all),
|
39
|
-
:js_lint_new => JslintCheck.new(:new),
|
40
|
-
:jshint => JshintCheck.new,
|
25
|
+
CHECKS = {
|
26
|
+
:white_space => WhiteSpaceCheck,
|
27
|
+
:console_log => ConsoleLogCheck,
|
28
|
+
:js_lint => JslintCheck,
|
29
|
+
:jshint => JshintCheck,
|
41
30
|
:debugger => DebuggerCheck,
|
42
31
|
:pry => PryCheck,
|
43
32
|
:local => LocalCheck,
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
33
|
+
:nb_space => NbSpaceCheck,
|
34
|
+
:tabs => TabsCheck,
|
35
|
+
:closure_syntax_check => ClosureCheck,
|
36
|
+
:merge_conflict => MergeConflictCheck,
|
37
|
+
:migrations => MigrationCheck,
|
48
38
|
:ci => CiCheck.new,
|
49
39
|
:php => PhpCheck.new,
|
50
40
|
:rspec_focus => RSpecFocusCheck,
|
51
|
-
:ruby_symbol_hashrockets => RubySymbolHashrockets
|
41
|
+
:ruby_symbol_hashrockets => RubySymbolHashrockets,
|
42
|
+
:gemfile_path => GemfilePathCheck
|
52
43
|
}
|
53
44
|
|
54
|
-
if defined?(Rubocop)
|
55
|
-
Checks.merge!({
|
56
|
-
:rubocop_new => RubocopCheck.new(:new),
|
57
|
-
:rubocop_all => RubocopCheck.new(:all)
|
58
|
-
})
|
59
|
-
end
|
45
|
+
CHECKS[:rubocop] = RubocopCheck if defined?(Rubocop)
|
60
46
|
|
61
47
|
# Can not delete this method with out a deprecation strategy.
|
62
48
|
# It is refered to in the generated pre-commit hook in versions 0.0-0.1.1
|
@@ -73,18 +59,30 @@ module PreCommit
|
|
73
59
|
checks_to_run = `git config pre-commit.checks`.chomp.split(/,\s*/).map(&:to_sym)
|
74
60
|
|
75
61
|
if checks_to_run.empty?
|
76
|
-
|
77
|
-
:migrations, :merge_conflict, :local)
|
62
|
+
CHECKS.values_at(:white_space, :console_log, :debugger, :pry, :tabs, :jshint,
|
63
|
+
:migrations, :merge_conflict, :local, :nb_space)
|
78
64
|
else
|
79
|
-
|
65
|
+
[:js_lint, :rubocop].each do |check|
|
66
|
+
if checks_to_run.delete("#{check}_all".to_sym) || checks_to_run.delete("#{check}_new".to_sym)
|
67
|
+
$stderr.puts "please use just '#{check}' as check name"
|
68
|
+
checks_to_run << check
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
CHECKS.values_at(*checks_to_run)
|
80
73
|
end.compact
|
81
74
|
end
|
82
75
|
|
83
76
|
def self.run
|
84
|
-
|
85
|
-
|
77
|
+
staged_files = Utils.staged_files
|
78
|
+
errors = checks_to_run.map { |cmd| cmd.call(staged_files.dup) }.compact
|
79
|
+
if errors.any?
|
80
|
+
puts "pre-commit: Stopping commit because of errors."
|
81
|
+
puts errors.join("\n")
|
82
|
+
puts "pre-commit: You can bypass this check using `git commit -n`"
|
83
|
+
exit 1
|
84
|
+
else
|
85
|
+
exit 0
|
86
86
|
end
|
87
|
-
|
88
|
-
exit(exit_status ? 0 : 1)
|
89
87
|
end
|
90
88
|
end
|
data/lib/pre-commit/cli.rb
CHANGED
@@ -1,39 +1,12 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require 'pre-commit/base'
|
3
2
|
|
4
3
|
module PreCommit
|
5
4
|
class Cli
|
6
5
|
|
7
6
|
PRE_COMMIT_HOOK_PATH = '.git/hooks/pre-commit'
|
8
7
|
|
9
|
-
def answered_yes?(answer)
|
10
|
-
answer =~ /y\n/i || answer == "\n"
|
11
|
-
end
|
12
|
-
|
13
8
|
def install
|
14
|
-
|
15
|
-
ask_to_overwrite
|
16
|
-
end
|
17
|
-
|
18
|
-
install_pre_commit_hook
|
19
|
-
end
|
20
|
-
|
21
|
-
def ask_to_overwrite
|
22
|
-
puts "pre-commit: WARNING There is already a pre-commit hook installed in this git repo."
|
23
|
-
print "Would you like to overwrite it? [Yn] "
|
24
|
-
answer = $stdin.gets
|
25
|
-
|
26
|
-
if answered_yes?(answer)
|
27
|
-
FileUtils.rm(PRE_COMMIT_HOOK_PATH)
|
28
|
-
else
|
29
|
-
puts "Not overwriting existing hook: #{PRE_COMMIT_HOOK_PATH}"
|
30
|
-
puts
|
31
|
-
exit(1)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def install_pre_commit_hook
|
36
|
-
hook = File.join(PreCommit.root, 'templates', 'pre-commit-hook')
|
9
|
+
hook = File.expand_path("../support/templates/pre-commit-hook", __FILE__)
|
37
10
|
FileUtils.cp(hook, PRE_COMMIT_HOOK_PATH)
|
38
11
|
FileUtils.chmod(0755, PRE_COMMIT_HOOK_PATH)
|
39
12
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/pre-commit/utils.rb
CHANGED
@@ -1,20 +1,17 @@
|
|
1
1
|
module PreCommit
|
2
2
|
class Utils
|
3
3
|
|
4
|
-
def self.staged_files
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.new_files(*dirs)
|
12
|
-
@new_files ||= {}
|
13
|
-
@new_files[dirs.join(' ')] ||= `git status --short #{dirs.join(' ')} | grep ^A | xargs`.chomp.split("A ").join(" ")
|
4
|
+
def self.staged_files
|
5
|
+
@staged_files ||= begin
|
6
|
+
files = `git diff --cached --name-only --diff-filter=ACM`.split
|
7
|
+
files.reject { |f| size = File.size(f); size > 1_000_000 || (size > 20 && binary?(f)) }
|
8
|
+
end
|
14
9
|
end
|
15
10
|
|
16
|
-
|
17
|
-
|
11
|
+
# from https://github.com/djberg96/ptools/blob/master/lib/ptools.rb#L90
|
12
|
+
def self.binary?(file)
|
13
|
+
s = (File.read(file, File.stat(file).blksize) || "").split(//)
|
14
|
+
((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
|
18
15
|
end
|
19
16
|
|
20
17
|
def self.grep
|
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pre-commit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.9.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Shajith Chacko, Josh Lubaway
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-08-26 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: execjs
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
description: A git pre-commit hook written in ruby with a few more tricks up its sleeve
|
@@ -35,39 +32,39 @@ extensions: []
|
|
35
32
|
extra_rdoc_files:
|
36
33
|
- README.md
|
37
34
|
files:
|
38
|
-
- lib/pre-commit/base.rb
|
39
35
|
- lib/pre-commit/checks/ci_check.rb
|
40
|
-
- lib/pre-commit/checks/
|
36
|
+
- lib/pre-commit/checks/closure_check.rb
|
37
|
+
- lib/pre-commit/checks/console_log_check.rb
|
41
38
|
- lib/pre-commit/checks/debugger_check.rb
|
39
|
+
- lib/pre-commit/checks/gemfile_path_check.rb
|
42
40
|
- lib/pre-commit/checks/js_check.rb
|
43
41
|
- lib/pre-commit/checks/jshint_check.rb
|
44
42
|
- lib/pre-commit/checks/jslint_check.rb
|
45
43
|
- lib/pre-commit/checks/local_check.rb
|
46
|
-
- lib/pre-commit/checks/
|
44
|
+
- lib/pre-commit/checks/merge_conflict_check.rb
|
47
45
|
- lib/pre-commit/checks/migration_check.rb
|
46
|
+
- lib/pre-commit/checks/nb_space_check.rb
|
48
47
|
- lib/pre-commit/checks/php_check.rb
|
49
48
|
- lib/pre-commit/checks/pry_check.rb
|
50
49
|
- lib/pre-commit/checks/rspec_focus_check.rb
|
51
50
|
- lib/pre-commit/checks/rubocop_check.rb
|
52
51
|
- lib/pre-commit/checks/ruby_symbol_hashrockets.rb
|
53
|
-
- lib/pre-commit/checks/
|
52
|
+
- lib/pre-commit/checks/tabs_check.rb
|
53
|
+
- lib/pre-commit/checks/whitespace_check.rb
|
54
54
|
- lib/pre-commit/checks.rb
|
55
55
|
- lib/pre-commit/cli.rb
|
56
56
|
- lib/pre-commit/runner.rb
|
57
|
+
- lib/pre-commit/support/closure/compiler.jar
|
58
|
+
- lib/pre-commit/support/jshint/jshint.js
|
59
|
+
- lib/pre-commit/support/jslint/lint.js
|
60
|
+
- lib/pre-commit/support/templates/pre-commit-hook
|
57
61
|
- lib/pre-commit/utils.rb
|
58
62
|
- lib/pre-commit.rb
|
59
|
-
- lib/support/all.rb
|
60
|
-
- lib/support/closure/closure_checker.rb
|
61
|
-
- lib/support/closure/compiler.jar
|
62
|
-
- lib/support/jshint/jshint.js
|
63
|
-
- lib/support/jslint/lint.js
|
64
|
-
- lib/support/whitespace/whitespace
|
65
|
-
- lib/support/whitespace/whitespace_checker.rb
|
66
|
-
- templates/pre-commit-hook
|
67
63
|
- README.md
|
68
64
|
- bin/pre-commit
|
69
65
|
homepage: http://github.com/jish/pre-commit
|
70
66
|
licenses: []
|
67
|
+
metadata: {}
|
71
68
|
post_install_message:
|
72
69
|
rdoc_options:
|
73
70
|
- --main
|
@@ -75,21 +72,20 @@ rdoc_options:
|
|
75
72
|
require_paths:
|
76
73
|
- lib
|
77
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
-
none: false
|
79
75
|
requirements:
|
80
|
-
- -
|
76
|
+
- - '>='
|
81
77
|
- !ruby/object:Gem::Version
|
82
78
|
version: '0'
|
83
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
80
|
requirements:
|
86
|
-
- -
|
81
|
+
- - '>='
|
87
82
|
- !ruby/object:Gem::Version
|
88
83
|
version: '0'
|
89
84
|
requirements: []
|
90
85
|
rubyforge_project:
|
91
|
-
rubygems_version:
|
86
|
+
rubygems_version: 2.0.2
|
92
87
|
signing_key:
|
93
88
|
specification_version: 3
|
94
89
|
summary: A slightly better git pre-commit hook
|
95
90
|
test_files: []
|
91
|
+
has_rdoc:
|
data/lib/pre-commit/base.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
module PreCommit
|
2
|
-
class ConsoleLog
|
3
|
-
|
4
|
-
attr_accessor :staged_files, :error_message
|
5
|
-
|
6
|
-
def self.call(quiet=false)
|
7
|
-
check = new
|
8
|
-
check.staged_files = Utils.staged_files('public/javascripts')
|
9
|
-
|
10
|
-
result = check.run
|
11
|
-
if !quiet && !result
|
12
|
-
puts check.error_message
|
13
|
-
end
|
14
|
-
result
|
15
|
-
end
|
16
|
-
|
17
|
-
def run
|
18
|
-
return true if staged_js_files.empty?
|
19
|
-
if detected_bad_code?
|
20
|
-
@error_message = "pre-commit: console.log found:\n"
|
21
|
-
@error_message += instances_of_console_log_violations
|
22
|
-
false
|
23
|
-
else
|
24
|
-
true
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def detected_bad_code?
|
29
|
-
system("grep -v \/\/ #{staged_js_files} | grep -qe \"console\\.log\"")
|
30
|
-
end
|
31
|
-
|
32
|
-
def instances_of_console_log_violations
|
33
|
-
`grep -nHe \"console\\.log\" #{staged_js_files}`
|
34
|
-
end
|
35
|
-
|
36
|
-
def staged_js_files
|
37
|
-
@staged_js_files ||= staged_files.split(" ").select do |file|
|
38
|
-
File.extname(file) == ".js"
|
39
|
-
end.join(" ")
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module PreCommit
|
2
|
-
class MergeConflict
|
3
|
-
|
4
|
-
attr_accessor :staged_files
|
5
|
-
|
6
|
-
def self.call
|
7
|
-
check = new
|
8
|
-
check.staged_files = Utils.staged_files('.')
|
9
|
-
check.run
|
10
|
-
end
|
11
|
-
|
12
|
-
def run
|
13
|
-
if detected_bad_code?
|
14
|
-
$stderr.puts 'pre-commit: detected a merge conflict'
|
15
|
-
$stderr.puts errors
|
16
|
-
$stderr.puts
|
17
|
-
$stderr.puts 'pre-commit: You can bypass this check using `git commit -n`'
|
18
|
-
$stderr.puts
|
19
|
-
false
|
20
|
-
else
|
21
|
-
true
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def detected_bad_code?
|
26
|
-
system("grep '<<<<<<<' #{staged_files} --quiet")
|
27
|
-
end
|
28
|
-
|
29
|
-
def errors
|
30
|
-
`grep -nH '<<<<<<<' #{staged_files}`
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'pre-commit/utils'
|
2
|
-
|
3
|
-
module PreCommit
|
4
|
-
class Tabs
|
5
|
-
|
6
|
-
attr_accessor :staged_files, :error_message
|
7
|
-
|
8
|
-
# Maintaining the functionality of `call` for backwards compatibility
|
9
|
-
# Currently, the call method is expected to:
|
10
|
-
# * run a check
|
11
|
-
# * print any corresponding error messages if the check fails
|
12
|
-
def self.call
|
13
|
-
check = new
|
14
|
-
check.staged_files = Utils.staged_files('*')
|
15
|
-
result = check.run
|
16
|
-
|
17
|
-
if !result
|
18
|
-
$stderr.puts check.error_message
|
19
|
-
$stderr.puts
|
20
|
-
$stderr.puts 'pre-commit: You can bypass this check using `git commit -n`'
|
21
|
-
$stderr.puts
|
22
|
-
end
|
23
|
-
|
24
|
-
result
|
25
|
-
end
|
26
|
-
|
27
|
-
def run
|
28
|
-
# There is nothing to check
|
29
|
-
if staged_files.empty?
|
30
|
-
return true
|
31
|
-
end
|
32
|
-
|
33
|
-
if detected_bad_code?
|
34
|
-
@error_message = "pre-commit: detected tab before initial space:\n"
|
35
|
-
@error_message += violations
|
36
|
-
|
37
|
-
@passed = false
|
38
|
-
else
|
39
|
-
@passed = true
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
LEADING_TAB_PATTERN = '^ *\t'
|
44
|
-
|
45
|
-
def detected_bad_code?
|
46
|
-
system("#{Utils.grep} -q '#{LEADING_TAB_PATTERN}' #{staged_files}")
|
47
|
-
end
|
48
|
-
|
49
|
-
def violations
|
50
|
-
`#{Utils.grep} '#{LEADING_TAB_PATTERN}' #{staged_files}`
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
data/lib/support/all.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
module PreCommit
|
2
|
-
class ClosureChecker
|
3
|
-
CLOSURE_PATH = File.join(File.dirname(__FILE__),"compiler.jar")
|
4
|
-
|
5
|
-
def self.check(files)
|
6
|
-
js_args = files.map {|arg| "--js #{arg}"}.join(' ')
|
7
|
-
system("java -jar #{CLOSURE_PATH} #{js_args} --js_output_file /tmp/jammit.js")
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
#
|
3
|
-
# An example hook script to verify what is about to be committed.
|
4
|
-
# Called by "git commit" with no arguments. The hook should
|
5
|
-
# exit with non-zero status after issuing an appropriate message if
|
6
|
-
# it wants to stop the commit.
|
7
|
-
#
|
8
|
-
# To enable this hook, rename this file to "pre-commit".
|
9
|
-
|
10
|
-
if git rev-parse --verify HEAD >/dev/null 2>&1
|
11
|
-
then
|
12
|
-
against=HEAD
|
13
|
-
else
|
14
|
-
# Initial commit: diff against an empty tree object
|
15
|
-
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
16
|
-
fi
|
17
|
-
|
18
|
-
# If you want to allow non-ascii filenames set this variable to true.
|
19
|
-
allownonascii=$(git config hooks.allownonascii)
|
20
|
-
|
21
|
-
# Cross platform projects tend to avoid non-ascii filenames; prevent
|
22
|
-
# them from being added to the repository. We exploit the fact that the
|
23
|
-
# printable range starts at the space character and ends with tilde.
|
24
|
-
if [ "$allownonascii" != "true" ] &&
|
25
|
-
# Note that the use of brackets around a tr range is ok here, (it's
|
26
|
-
# even required, for portability to Solaris 10's /usr/bin/tr), since
|
27
|
-
# the square bracket bytes happen to fall in the designated range.
|
28
|
-
test "$(git diff --cached --name-only --diff-filter=A -z $against |
|
29
|
-
LC_ALL=C tr -d '[ -~]\0')"
|
30
|
-
then
|
31
|
-
echo "Error: Attempt to add a non-ascii file name."
|
32
|
-
echo
|
33
|
-
echo "This can cause problems if you want to work"
|
34
|
-
echo "with people on other platforms."
|
35
|
-
echo
|
36
|
-
echo "To be portable it is advisable to rename the file ..."
|
37
|
-
echo
|
38
|
-
echo "If you know what you are doing you can disable this"
|
39
|
-
echo "check using:"
|
40
|
-
echo
|
41
|
-
echo " git config hooks.allownonascii true"
|
42
|
-
echo
|
43
|
-
exit 1
|
44
|
-
fi
|
45
|
-
|
46
|
-
exec git diff-index --check --cached $against --
|