pre-commit 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -39,4 +39,4 @@ To enable `white_space`, `console_log` and `debugger` checks:
39
39
 
40
40
  Note: If no checks are configured, a default set of checks is run:
41
41
 
42
- white_space, console_log, debugger, tabs, jshint
42
+ white_space, console_log, debugger, tabs, jshint, migrations
@@ -0,0 +1,55 @@
1
+ class PreCommit
2
+ class MigrationCheck
3
+
4
+ attr_accessor :error_message
5
+
6
+ def call
7
+ staged_files = load_staged_files
8
+ run(staged_files)
9
+
10
+ if !passed? && error_message
11
+ $stderr.puts "pre-commit: #{error_message}"
12
+ end
13
+
14
+ passed?
15
+ end
16
+
17
+ def run(staged_files)
18
+ migration_present = migration_file_present?(staged_files)
19
+ schema_change = schema_file_present?(staged_files)
20
+
21
+ if migration_present && !schema_change
22
+ @error_message = "It looks like you're adding a migration, but did not update the schema file"
23
+ @passed = false
24
+ elsif schema_change && !migration_present
25
+ @error_message = "You're trying to change the schema without adding a migraiton file"
26
+ @passed = false
27
+ else
28
+ @passed = true
29
+ end
30
+ end
31
+
32
+ def migration_file_present?(staged_files)
33
+ staged_files.any? { |file| file =~ /db\/migrate\/.*\.rb/ }
34
+ end
35
+
36
+ def schema_file_present?(staged_files)
37
+ staged_files.any? do |file|
38
+ basename = File.basename(file)
39
+
40
+ [/schema\.rb/i, /structure.*\.sql/].any? do |regex|
41
+ basename =~ regex
42
+ end
43
+ end
44
+ end
45
+
46
+ def passed?
47
+ @passed
48
+ end
49
+
50
+ def load_staged_files
51
+ Utils.staged_files('.').split(" ")
52
+ end
53
+
54
+ end
55
+ end
@@ -6,6 +6,7 @@ require 'pre-commit/checks/console_log'
6
6
  require 'pre-commit/checks/debugger_check'
7
7
  require 'pre-commit/checks/jslint_check'
8
8
  require 'pre-commit/checks/jshint_check'
9
+ require 'pre-commit/checks/migration_check'
9
10
 
10
11
  class PreCommit
11
12
 
@@ -64,7 +65,8 @@ class PreCommit
64
65
  :debugger => DebuggerCheck,
65
66
  :tabs => Tabs,
66
67
  :closure_syntax_check => ClosureSyntaxCheck,
67
- :merge_conflict => MergeConflict
68
+ :merge_conflict => MergeConflict,
69
+ :migrations => MigrationCheck.new
68
70
  }
69
71
 
70
72
  # Can not delete this method with out a deprecation strategy.
@@ -82,7 +84,7 @@ class PreCommit
82
84
  checks_to_run = `git config pre-commit.checks`.chomp.split(/,\s*/).map(&:to_sym)
83
85
 
84
86
  if checks_to_run.empty?
85
- Checks.values_at(:white_space, :console_log, :debugger, :tabs, :jshint)
87
+ Checks.values_at(:white_space, :console_log, :debugger, :tabs, :jshint, :migrations)
86
88
  else
87
89
  Checks.values_at(*checks_to_run)
88
90
  end.compact
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pre-commit
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.9
5
+ version: 0.1.10
6
6
  platform: ruby
7
7
  authors:
8
8
  - Shajith Chacko, Josh Lubaway
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-21 00:00:00 -07:00
13
+ date: 2011-05-05 00:00:00 -07:00
14
14
  default_executable: pre-commit
15
15
  dependencies: []
16
16
 
@@ -29,6 +29,7 @@ files:
29
29
  - lib/pre-commit/checks/jshint_check.rb
30
30
  - lib/pre-commit/checks/jslint_check.rb
31
31
  - lib/pre-commit/checks/merge_conflict.rb
32
+ - lib/pre-commit/checks/migration_check.rb
32
33
  - lib/pre-commit/checks/tabs.rb
33
34
  - lib/pre-commit/checks.rb
34
35
  - lib/pre-commit/runner.rb