pre-commit 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -27,6 +27,10 @@ These are the available checks:
27
27
  * closure\_syntax\_check
28
28
  * php (Runs php -l on all staged files)
29
29
  * ruby_symbol_hashrockets (1.9 syntax. BAD :foo => "bar". GOOD foo: "bar")
30
+ * local (executes `config/pre-commit.rb` with list of changed files)
31
+ * merge conflict (Will check if you are about to check in a merge conflict)
32
+ * migrations (Will make sure you check in the proper files after creating a Rails migration)
33
+ * ci (Will run the `pre_commit:ci` rake task and pass or fail accordingly)
30
34
 
31
35
  To configure which checks you would like to run, simply set the `pre-commit.checks` git configuration setting.
32
36
 
@@ -42,4 +46,4 @@ To enable `white_space`, `console_log` and `debugger` checks:
42
46
 
43
47
  Note: If no checks are configured, a default set of checks is run:
44
48
 
45
- white_space, console_log, debugger, tabs, jshint, migrations
49
+ white_space, console_log, debugger, tabs, jshint, migrations, merge_conflict, local
data/bin/pre-commit CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  require 'pre-commit/cli'
4
4
 
5
- PRE_COMMIT_HOOK_PATH = '.git/hooks/pre-commit'
6
-
7
5
  if ARGV[0] != "install"
8
6
  puts "Usage: pre-commit install"
9
7
  exit(1)
@@ -17,5 +15,5 @@ end
17
15
  cli = PreCommit::Cli.new
18
16
  cli.install
19
17
 
20
- puts "Installed hook: #{PRE_COMMIT_HOOK_PATH}"
18
+ puts "Installed hook: #{PreCommit::Cli::PRE_COMMIT_HOOK_PATH}"
21
19
  puts
@@ -1,4 +1,4 @@
1
- class PreCommit
1
+ module PreCommit
2
2
 
3
3
  def self.root
4
4
  root = File.expand_path('../../..', __FILE__)
@@ -4,6 +4,7 @@ require 'pre-commit/checks/merge_conflict'
4
4
  require 'pre-commit/checks/tabs'
5
5
  require 'pre-commit/checks/console_log'
6
6
  require 'pre-commit/checks/debugger_check'
7
+ require 'pre-commit/checks/local_check'
7
8
  require 'pre-commit/checks/jslint_check'
8
9
  require 'pre-commit/checks/jshint_check'
9
10
  require 'pre-commit/checks/migration_check'
@@ -11,7 +12,7 @@ require 'pre-commit/checks/ci_check'
11
12
  require 'pre-commit/checks/php_check'
12
13
  require 'pre-commit/checks/ruby_symbol_hashrockets'
13
14
 
14
- class PreCommit
15
+ module PreCommit
15
16
 
16
17
  WhiteSpace = lambda {
17
18
  WhiteSpaceChecker.check
@@ -34,6 +35,7 @@ class PreCommit
34
35
  :js_lint_new => JslintCheck.new(:new),
35
36
  :jshint => JshintCheck.new,
36
37
  :debugger => DebuggerCheck,
38
+ :local => LocalCheck,
37
39
  :tabs => Tabs,
38
40
  :closure_syntax_check => ClosureSyntaxCheck,
39
41
  :merge_conflict => MergeConflict,
@@ -59,7 +61,7 @@ class PreCommit
59
61
 
60
62
  if checks_to_run.empty?
61
63
  Checks.values_at(:white_space, :console_log, :debugger, :tabs, :jshint,
62
- :migrations, :merge_conflict)
64
+ :migrations, :merge_conflict, :local)
63
65
  else
64
66
  Checks.values_at(*checks_to_run)
65
67
  end.compact
@@ -67,7 +69,7 @@ class PreCommit
67
69
 
68
70
  def self.run
69
71
  exit_status = self.checks_to_run.inject(true) do |acc, cmd|
70
- acc = cmd.call && acc
72
+ cmd.call && acc
71
73
  end
72
74
 
73
75
  exit(exit_status ? 0 : 1)
@@ -1,47 +1,49 @@
1
- class CiCheck
1
+ module PreCommit
2
+ class CiCheck
2
3
 
3
- CI_TASK_NAME = 'pre_commit:ci'
4
+ CI_TASK_NAME = 'pre_commit:ci'
4
5
 
5
- def call
6
- if rakefile_present? && has_ci_task?
7
- run
8
- else
9
- $stderr.puts "pre-commit: skipping ci check. The `#{CI_TASK_NAME}` task is not defined."
6
+ def call
7
+ if rakefile_present? && has_ci_task?
8
+ run
9
+ else
10
+ $stderr.puts "pre-commit: skipping ci check. The `#{CI_TASK_NAME}` task is not defined."
10
11
 
11
- # pretend the check passed and move on
12
- true
12
+ # pretend the check passed and move on
13
+ true
14
+ end
13
15
  end
14
- end
15
16
 
16
- def run
17
- if tests_passed?
18
- true
19
- else
20
- $stderr.puts 'pre-commit: your test suite has failed'
21
- $stderr.puts "for the full output run `#{CI_TASK_NAME}`"
22
- $stderr.puts
17
+ def run
18
+ if tests_passed?
19
+ true
20
+ else
21
+ $stderr.puts 'pre-commit: your test suite has failed'
22
+ $stderr.puts "for the full output run `#{CI_TASK_NAME}`"
23
+ $stderr.puts
23
24
 
24
- false
25
+ false
26
+ end
25
27
  end
26
- end
27
28
 
28
- def tests_passed?
29
- system("rake #{CI_TASK_NAME} --silent")
30
- end
29
+ def tests_passed?
30
+ system("rake #{CI_TASK_NAME} --silent")
31
+ end
31
32
 
32
- def rakefile_present?
33
- ['rakefile', 'Rakefile', 'rakefile.rb', 'Rakefile.rb'].any? do |file|
34
- File.exist?(file)
33
+ def rakefile_present?
34
+ ['rakefile', 'Rakefile', 'rakefile.rb', 'Rakefile.rb'].any? do |file|
35
+ File.exist?(file)
36
+ end
35
37
  end
36
- end
37
38
 
38
- def has_ci_task?
39
- require 'rake'
40
- Rake.application.init
41
- Rake.application.load_rakefile
42
- Rake::Task.task_defined?(CI_TASK_NAME)
43
- rescue LoadError
44
- $stderr.puts 'pre-commit: rake not found, skipping ci check'
45
- end
39
+ def has_ci_task?
40
+ require 'rake'
41
+ Rake.application.init
42
+ Rake.application.load_rakefile
43
+ Rake::Task.task_defined?(CI_TASK_NAME)
44
+ rescue LoadError
45
+ $stderr.puts 'pre-commit: rake not found, skipping ci check'
46
+ end
46
47
 
48
+ end
47
49
  end
@@ -1,40 +1,43 @@
1
- class ConsoleLog
1
+ module PreCommit
2
+ class ConsoleLog
2
3
 
3
- attr_accessor :staged_files, :error_message
4
+ attr_accessor :staged_files, :error_message
4
5
 
5
- def self.call(quiet=false)
6
- check = new
7
- check.staged_files = Utils.staged_files('public/javascripts')
6
+ def self.call(quiet=false)
7
+ check = new
8
+ check.staged_files = Utils.staged_files('public/javascripts')
8
9
 
9
- result = check.run
10
- if !quiet && !result
11
- puts check.error_message
10
+ result = check.run
11
+ if !quiet && !result
12
+ puts check.error_message
13
+ end
14
+ result
12
15
  end
13
- result
14
- end
15
16
 
16
- def run
17
- return true if staged_js_files.empty?
18
- if detected_bad_code?
19
- @error_message = "pre-commit: console.log found:\n"
20
- @error_message += instances_of_console_log_violations
21
- false
22
- else
23
- true
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
24
26
  end
25
- end
26
27
 
27
- def detected_bad_code?
28
- system("grep -v \/\/ #{staged_js_files} | grep -qe \"console\\.log\"")
29
- end
28
+ def detected_bad_code?
29
+ system("grep -v \/\/ #{staged_js_files} | grep -qe \"console\\.log\"")
30
+ end
30
31
 
31
- def instances_of_console_log_violations
32
- `grep -nHe \"console\\.log\" #{staged_js_files}`
33
- end
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
34
41
 
35
- def staged_js_files
36
- @staged_js_files ||= staged_files.split(" ").select do |file|
37
- File.extname(file) == ".js"
38
- end.join(" ")
39
42
  end
40
43
  end
@@ -1,44 +1,47 @@
1
- class DebuggerCheck
2
- attr_accessor :staged_files, :error_message, :grep_command
1
+ module PreCommit
2
+ class DebuggerCheck
3
+
4
+ attr_accessor :staged_files, :error_message, :grep_command
5
+
6
+ def self.call(quiet=false)
7
+ dirs = ['app/', 'lib/', 'script/', 'vendor/', 'test/'].reject {|d| !File.exists?(d)}
8
+ check = new
9
+ check.staged_files = Utils.staged_files(*dirs)
10
+
11
+ result = check.run
12
+ if !quiet && !result
13
+ $stderr.puts check.error_message
14
+ $stderr.puts
15
+ check.print_dash_n_reminder
16
+ end
17
+ result
18
+ end
3
19
 
4
- def self.call(quiet=false)
5
- dirs = ['app/', 'lib/', 'script/', 'vendor/', 'test/'].reject {|d| !File.exists?(d)}
6
- check = new
7
- check.staged_files = Utils.staged_files(*dirs)
20
+ def run
21
+ return true if staged_files.empty?
8
22
 
9
- result = check.run
10
- if !quiet && !result
11
- $stderr.puts check.error_message
12
- $stderr.puts
13
- check.print_dash_n_reminder
23
+ if detected_bad_code?
24
+ @error_message = "pre-commit: debugger statement(s) found:\n"
25
+ @error_message += instances_of_debugger_violations
26
+ false
27
+ else
28
+ true
29
+ end
14
30
  end
15
- result
16
- end
17
31
 
18
- def run
19
- return true if staged_files.empty?
20
-
21
- if detected_bad_code?
22
- @error_message = "pre-commit: debugger statement(s) found:\n"
23
- @error_message += instances_of_debugger_violations
24
- false
25
- else
26
- true
32
+ def detected_bad_code?
33
+ !system("git diff --cached -Sdebugger --quiet --exit-code")
27
34
  end
28
- end
29
35
 
30
- def detected_bad_code?
31
- !system("git diff --cached -Sdebugger --quiet --exit-code")
32
- end
36
+ def instances_of_debugger_violations
37
+ cmd = grep_command || "git grep"
38
+ `#{cmd} -nH debugger #{staged_files}`
39
+ end
33
40
 
34
- def instances_of_debugger_violations
35
- cmd = grep_command || "git grep"
36
- `#{cmd} -nH debugger #{staged_files}`
37
- end
41
+ def print_dash_n_reminder
42
+ $stderr.puts 'You can bypass this check using `git commit -n`'
43
+ $stderr.puts
44
+ end
38
45
 
39
- def print_dash_n_reminder
40
- $stderr.puts 'You can bypass this check using `git commit -n`'
41
- $stderr.puts
42
46
  end
43
-
44
47
  end
@@ -2,7 +2,7 @@ require 'pre-commit/base'
2
2
  require 'pre-commit/utils'
3
3
  require 'execjs'
4
4
 
5
- class PreCommit
5
+ module PreCommit
6
6
  class JsCheck
7
7
 
8
8
  def call
@@ -1,6 +1,6 @@
1
1
  require 'pre-commit/checks/js_check'
2
2
 
3
- class PreCommit
3
+ module PreCommit
4
4
  class JshintCheck < JsCheck
5
5
 
6
6
  def check_name
@@ -30,5 +30,6 @@ class PreCommit
30
30
  def linter_src
31
31
  File.join(PreCommit.root, 'lib', 'support', 'jshint', 'jshint.js')
32
32
  end
33
+
33
34
  end
34
35
  end
@@ -1,8 +1,6 @@
1
1
  require 'pre-commit/checks/js_check'
2
2
 
3
- # This (PreCommit) should be a module
4
- # ... it should also have a cooler name :P
5
- class PreCommit
3
+ module PreCommit
6
4
  class JslintCheck < JsCheck
7
5
 
8
6
  attr_accessor :type
@@ -0,0 +1,28 @@
1
+ require 'pre-commit/utils'
2
+
3
+ module PreCommit
4
+ class LocalCheck
5
+
6
+ DEFAULT_LOCATION = "config/pre-commit.rb"
7
+ attr_accessor :error_message
8
+
9
+ def self.call(quiet=false)
10
+ check = new
11
+ result = check.run(DEFAULT_LOCATION, Utils.staged_files("."))
12
+ puts check.error_message if !result && !quiet
13
+ result
14
+ end
15
+
16
+ def run(file, staged_files)
17
+ return true unless File.exist?(file)
18
+ output = `ruby #{file} #{staged_files} 2>&1`
19
+ if $?.success?
20
+ true
21
+ else
22
+ self.error_message = "#{file} failed:\n#{output}"
23
+ false
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -1,32 +1,34 @@
1
- class MergeConflict
1
+ module PreCommit
2
+ class MergeConflict
2
3
 
3
- attr_accessor :staged_files
4
+ attr_accessor :staged_files
4
5
 
5
- def self.call
6
- check = new
7
- check.staged_files = Utils.staged_files('.')
8
- check.run
9
- end
6
+ def self.call
7
+ check = new
8
+ check.staged_files = Utils.staged_files('.')
9
+ check.run
10
+ end
10
11
 
11
- def run
12
- if detected_bad_code?
13
- $stderr.puts 'pre-commit: detected a merge conflict'
14
- $stderr.puts errors
15
- $stderr.puts
16
- $stderr.puts 'pre-commit: You can bypass this check using `git commit -n`'
17
- $stderr.puts
18
- false
19
- else
20
- true
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
21
23
  end
22
- end
23
24
 
24
- def detected_bad_code?
25
- system("grep '<<<<<<<' #{staged_files} --quiet")
26
- end
25
+ def detected_bad_code?
26
+ system("grep '<<<<<<<' #{staged_files} --quiet")
27
+ end
27
28
 
28
- def errors
29
- `grep -nH '<<<<<<<' #{staged_files}`
30
- end
29
+ def errors
30
+ `grep -nH '<<<<<<<' #{staged_files}`
31
+ end
31
32
 
33
+ end
32
34
  end
@@ -1,4 +1,4 @@
1
- class PreCommit
1
+ module PreCommit
2
2
  class MigrationCheck
3
3
 
4
4
  attr_accessor :error_message
@@ -1,7 +1,7 @@
1
1
  require 'pre-commit/base'
2
2
  require 'pre-commit/utils'
3
3
 
4
- class PreCommit
4
+ module PreCommit
5
5
  class PhpCheck
6
6
 
7
7
  def files_to_check
@@ -71,4 +71,3 @@ class PreCommit
71
71
 
72
72
  end
73
73
  end
74
-
@@ -1,49 +1,55 @@
1
- class RubySymbolHashrockets
2
- attr_accessor :staged_files, :error_message
1
+ require 'pre-commit/utils'
3
2
 
4
- HASHROCKET_PATTERN = ':(?:\$|@|@@|[_A-Za-z])?\w*[=!?]?\s*=>\s*'
3
+ module PreCommit
4
+ class RubySymbolHashrockets
5
5
 
6
- def self.call
7
- check = new
8
- check.staged_files = Utils.staged_files('*')
9
- result = check.run
6
+ attr_accessor :staged_files, :error_message
10
7
 
11
- if !result
12
- $stderr.puts check.error_message
13
- $stderr.puts
14
- $stderr.puts 'pre-commit: You can bypass this check using `git commit -n`'
15
- $stderr.puts
8
+ HASHROCKET_PATTERN = ':(?:\$|@|@@|[_A-Za-z])?\w*[=!?]?\s*=>\s*'
9
+
10
+ def self.call
11
+ check = new
12
+ check.staged_files = Utils.staged_files('*')
13
+ result = check.run
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
16
23
  end
17
24
 
18
- result
19
- end
25
+ def run
26
+ # There is nothing to check
27
+ return true if staged_files.empty?
20
28
 
21
- def run
22
- # There is nothing to check
23
- return true if staged_files.empty?
29
+ if detected_bad_code?
30
+ @error_message = "pre-commit: detected :symbol => value hashrocket:\n"
31
+ @error_message += violations[:lines]
24
32
 
25
- if detected_bad_code?
26
- @error_message = "pre-commit: detected :symbol => value hashrocket:\n"
27
- @error_message += violations[:lines]
33
+ @passed = false
34
+ else
35
+ @passed = true
36
+ end
28
37
 
29
- @passed = false
30
- else
31
- @passed = true
38
+ @passed
32
39
  end
33
40
 
34
- @passed
35
- end
36
-
37
- def detected_bad_code?
38
- violations[:success]
39
- end
41
+ def detected_bad_code?
42
+ violations[:success]
43
+ end
40
44
 
41
- def violations
42
- @violations ||= begin
43
- lines = `#{Utils.grep} '#{HASHROCKET_PATTERN}' #{staged_files}`
44
- success = $?.exitstatus == 0
45
+ def violations
46
+ @violations ||= begin
47
+ lines = `#{Utils.grep} '#{HASHROCKET_PATTERN}' #{staged_files}`
48
+ success = $?.exitstatus == 0
45
49
 
46
- { :lines => lines, :success => success}
50
+ { :lines => lines, :success => success}
51
+ end
47
52
  end
53
+
48
54
  end
49
55
  end
@@ -1,49 +1,54 @@
1
- class Tabs
2
-
3
- attr_accessor :staged_files, :error_message
4
-
5
- # Maintaining the functionality of `call` for backwards compatibility
6
- # Currently, the call method is expected to:
7
- # * run a check
8
- # * print any corresponding error messages if the check fails
9
- def self.call
10
- check = new
11
- check.staged_files = Utils.staged_files('*')
12
- result = check.run
13
-
14
- if !result
15
- $stderr.puts check.error_message
16
- $stderr.puts
17
- $stderr.puts 'pre-commit: You can bypass this check using `git commit -n`'
18
- $stderr.puts
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
19
25
  end
20
26
 
21
- result
22
- end
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
23
36
 
24
- def run
25
- # There is nothing to check
26
- if staged_files.empty?
27
- return true
37
+ @passed = false
38
+ else
39
+ @passed = true
40
+ end
28
41
  end
29
42
 
30
- if detected_bad_code?
31
- @error_message = "pre-commit: detected tab before initial space:\n"
32
- @error_message += violations
43
+ LEADING_TAB_PATTERN = '^ *\t'
33
44
 
34
- @passed = false
35
- else
36
- @passed = true
45
+ def detected_bad_code?
46
+ system("#{Utils.grep} -q '#{LEADING_TAB_PATTERN}' #{staged_files}")
37
47
  end
38
- end
39
48
 
40
- LEADING_TAB_PATTERN = '^ *\t'
41
-
42
- def detected_bad_code?
43
- system("#{Utils.grep} -q '#{LEADING_TAB_PATTERN}' #{staged_files}")
44
- end
49
+ def violations
50
+ `#{Utils.grep} '#{LEADING_TAB_PATTERN}' #{staged_files}`
51
+ end
45
52
 
46
- def violations
47
- `#{Utils.grep} '#{LEADING_TAB_PATTERN}' #{staged_files}`
48
53
  end
49
54
  end
@@ -1,7 +1,7 @@
1
1
  require 'fileutils'
2
2
  require 'pre-commit/base'
3
3
 
4
- class PreCommit
4
+ module PreCommit
5
5
  class Cli
6
6
 
7
7
  PRE_COMMIT_HOOK_PATH = '.git/hooks/pre-commit'
@@ -1,19 +1,21 @@
1
- class Runner
1
+ module PreCommit
2
+ class Runner
2
3
 
3
- def run
4
- checks_to_run = PreCommit.checks_to_run
4
+ def run
5
+ checks_to_run = PreCommit.checks_to_run
5
6
 
6
- all_passed = checks_to_run.inject(true) do |current_status, check|
7
- passed = check.call
7
+ all_passed = checks_to_run.inject(true) do |current_status, check|
8
+ passed = check.call
8
9
 
9
- if !passed && check.respond_to?(:error_message)
10
- puts check.error_message
10
+ if !passed && check.respond_to?(:error_message)
11
+ puts check.error_message
12
+ end
13
+
14
+ check && current_status
11
15
  end
12
16
 
13
- check && current_status
17
+ exit(all_passed ? 0 : 1)
14
18
  end
15
19
 
16
- exit(all_passed ? 0 : 1)
17
20
  end
18
-
19
21
  end
@@ -1,28 +1,30 @@
1
- class Utils
1
+ module PreCommit
2
+ class Utils
2
3
 
3
- def self.staged_files(*dirs)
4
- dirs = reject_missing(dirs)
4
+ def self.staged_files(*dirs)
5
+ dirs = reject_missing(dirs)
5
6
 
6
- @staged_files ||= {}
7
- @staged_files[dirs.join(' ')] ||= `git diff --cached --name-only --diff-filter=ACM #{dirs.join(' ')} | xargs`.chomp
8
- end
7
+ @staged_files ||= {}
8
+ @staged_files[dirs.join(' ')] ||= `git diff --cached --name-only --diff-filter=ACM #{dirs.join(' ')} | xargs`.chomp
9
+ end
9
10
 
10
- def self.new_files(*dirs)
11
- @new_files ||= {}
12
- @new_files[dirs.join(' ')] ||= `git status --short #{dirs.join(' ')} | grep ^A | xargs`.chomp.split("A ").join(" ")
13
- end
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(" ")
14
+ end
14
15
 
15
- def self.reject_missing(dirs)
16
- dirs.reject { |dir| !File.exist?(dir) }
17
- end
16
+ def self.reject_missing(dirs)
17
+ dirs.reject { |dir| !File.exist?(dir) }
18
+ end
18
19
 
19
- def self.grep
20
- grep_version = `grep --version | head -n 1 | sed -e 's/^[^0-9.]*\([0-9.]*\)$/\1/'`
21
- if grep_version =~ /FreeBSD/
22
- "grep -EnIH"
23
- else
24
- "grep -PnIH"
20
+ def self.grep
21
+ grep_version = `grep --version | head -n 1 | sed -e 's/^[^0-9.]*\([0-9.]*\)$/\1/'`
22
+ if grep_version =~ /FreeBSD/
23
+ "grep -EnIH"
24
+ else
25
+ "grep -PnIH"
26
+ end
25
27
  end
26
- end
27
28
 
29
+ end
28
30
  end
@@ -1,8 +1,10 @@
1
- class ClosureChecker
2
- CLOSURE_PATH = File.join(File.dirname(__FILE__),"compiler.jar")
3
-
4
- def self.check(files)
5
- js_args = files.map {|arg| "--js #{arg}"}.join(' ')
6
- system("java -jar #{CLOSURE_PATH} #{js_args} --js_output_file /tmp/jammit.js")
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
7
9
  end
8
10
  end
@@ -1,7 +1,9 @@
1
- class WhiteSpaceChecker
2
- WHITESPACE_SCRIPT_PATH = File.join(File.dirname(__FILE__), "whitespace")
1
+ module PreCommit
2
+ class WhiteSpaceChecker
3
+ WHITESPACE_SCRIPT_PATH = File.join(File.dirname(__FILE__), "whitespace")
3
4
 
4
- def self.check
5
- system("sh #{WHITESPACE_SCRIPT_PATH}")
5
+ def self.check
6
+ system("sh #{WHITESPACE_SCRIPT_PATH}")
7
+ end
6
8
  end
7
9
  end
@@ -1,18 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- if system("which rvm > /dev/null")
4
- cmd = "rvm default do ruby -rrubygems "
3
+ cmd = if system("which rvm > /dev/null")
4
+ "rvm default do ruby -rrubygems"
5
5
  elsif system("which rbenv > /dev/null")
6
- cmd = "rbenv exec ruby -rrubygems "
6
+ "rbenv exec ruby -rrubygems"
7
7
  else
8
- cmd = "ruby -rrubygems "
8
+ "ruby -r rubygems"
9
9
  end
10
+ cmd << " -r pre-commit"
10
11
 
11
- if !system("#{cmd} -rpre-commit -e '' 2> /dev/null")
12
+ if !system("#{cmd} -e '' 2>&1")
12
13
  $stderr.puts "pre-commit: WARNING: Skipping checks because the pre-commit gem is not installed. (Did you change your Ruby version?)"
13
14
  exit(0)
14
15
  end
15
16
 
16
- cmd << %Q{-e "require 'pre-commit'; PreCommit.run"}
17
-
18
- exit(system(cmd) ? 0 : 1)
17
+ exec("#{cmd} -e 'PreCommit.run'")
metadata CHANGED
@@ -1,43 +1,40 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pre-commit
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 6
8
- - 1
9
- version: 0.6.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Shajith Chacko, Josh Lubaway
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-11-07 00:00:00 -08:00
18
- default_executable: pre-commit
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-02-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: execjs
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
30
22
  type: :runtime
31
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
32
30
  description: A git pre-commit hook written in ruby with a few more tricks up its sleeve
33
31
  email: dontneedmoreemail@example.com
34
- executables:
32
+ executables:
35
33
  - pre-commit
36
34
  extensions: []
37
-
38
- extra_rdoc_files:
35
+ extra_rdoc_files:
39
36
  - README.md
40
- files:
37
+ files:
41
38
  - lib/pre-commit/base.rb
42
39
  - lib/pre-commit/checks/ci_check.rb
43
40
  - lib/pre-commit/checks/console_log.rb
@@ -45,6 +42,7 @@ files:
45
42
  - lib/pre-commit/checks/js_check.rb
46
43
  - lib/pre-commit/checks/jshint_check.rb
47
44
  - lib/pre-commit/checks/jslint_check.rb
45
+ - lib/pre-commit/checks/local_check.rb
48
46
  - lib/pre-commit/checks/merge_conflict.rb
49
47
  - lib/pre-commit/checks/migration_check.rb
50
48
  - lib/pre-commit/checks/php_check.rb
@@ -64,36 +62,31 @@ files:
64
62
  - lib/support/whitespace/whitespace_checker.rb
65
63
  - templates/pre-commit-hook
66
64
  - README.md
67
- has_rdoc: true
65
+ - bin/pre-commit
68
66
  homepage: http://github.com/jish/pre-commit
69
67
  licenses: []
70
-
71
68
  post_install_message:
72
- rdoc_options:
69
+ rdoc_options:
73
70
  - --main
74
71
  - README.md
75
- require_paths:
72
+ require_paths:
76
73
  - lib
77
- required_ruby_version: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- segments:
82
- - 0
83
- version: "0"
84
- required_rubygems_version: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- segments:
89
- - 0
90
- version: "0"
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
91
86
  requirements: []
92
-
93
87
  rubyforge_project:
94
- rubygems_version: 1.3.6
88
+ rubygems_version: 1.8.23
95
89
  signing_key:
96
90
  specification_version: 3
97
91
  summary: A slightly better git pre-commit hook
98
92
  test_files: []
99
-