pre-commit 0.17.0 → 0.18.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7c3a12b035bf764791d70ec6cb4fba9fd3778d6
4
- data.tar.gz: ec677fe164684322255b950dd125571c202dcd72
3
+ metadata.gz: 4ab21a6aa71a872a9bcd1764a116ccb93bfd9ac6
4
+ data.tar.gz: fbc548adf285e5872c4b14b633f108eb28a62c66
5
5
  SHA512:
6
- metadata.gz: 025a3bc6ada1545472d509af763ae76151c7506fe417165392cdea1589b349a7b3cd3e9a2a77ff43f904ac4761528b83d5c5ddedb62ce97c953c6a4ee1125663
7
- data.tar.gz: b7891532e91f04eda649a830e341ceab2ef01c7f831119be762e88241357c30efaa22789b0f480777a7aea83aad08acb16b5a2f31af6eb10f65bf7c4a84b3447
6
+ metadata.gz: 01f05a9e0cb5323a53afade54f4528c7de3957dc39eea2c68ffc1607a95b1281a5fc39c5756471e4f4e6b7146450540cb34351a782b55a27ed45fb71dcef70c3
7
+ data.tar.gz: 884e6682da33909cda2f6340fbf495226eb107d20c2aafb28ebf07e8f2aa0fea4b18579ab8bcf215718c1d01ac439815d403fe8515a1e90d014496e5afb4a8d6
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  A better pre-commit hook for git.
2
2
 
3
- [![Current version](https://badge.fury.io/rb/pre-commit.png)](https://rubygems.org/gems/pre-commit)
4
- [![Code Climate](https://codeclimate.com/github/jish/pre-commit.png)](https://codeclimate.com/github/jish/pre-commit)
5
- [![Coverage Status](https://coveralls.io/repos/jish/pre-commit/badge.png?branch=master)](https://coveralls.io/r/jish/pre-commit?branch=master)
6
- [![Build status](https://secure.travis-ci.org/jish/pre-commit.png?branch=master)](https://travis-ci.org/jish/pre-commit)
3
+ [![Current version](https://badge.fury.io/rb/pre-commit.svg)](https://rubygems.org/gems/pre-commit)
4
+ [![Code Climate](https://img.shields.io/codeclimate/github/jish/pre-commit.svg)](https://codeclimate.com/github/jish/pre-commit)
5
+ [![Coverage Status](https://img.shields.io/coveralls/jish/pre-commit/master.svg)](https://coveralls.io/r/jish/pre-commit?branch=master)
6
+ [![Build status](https://travis-ci.org/jish/pre-commit.svg?branch=master)](https://travis-ci.org/jish/pre-commit)
7
7
  [![Dependency Status](https://gemnasium.com/jish/pre-commit.png)](https://gemnasium.com/jish/pre-commit)
8
- [![Documentation](http://b.repl.ca/v1/yard-docs-blue.png)](http://rubydoc.info/gems/pre-commit/frames)
8
+ [![Documentation](https://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/gems/pre-commit/frames)
9
9
 
10
10
  ## Installation
11
11
 
@@ -74,7 +74,7 @@ Example move `jshint` from `checks` to `warnings` in `yaml` provider and save co
74
74
  ```bash
75
75
  pre-commit disable yaml checks jshint
76
76
  pre-commit enable yaml warnings jshint
77
- git add config/pre-commit.yml
77
+ git add config/pre_commit.yml
78
78
  git commit -m "pre-commit: move jshint from checks to warnings"
79
79
  ```
80
80
 
@@ -103,7 +103,7 @@ pre-commit run <file-list> # run on the list of files, patterns not supported
103
103
 
104
104
  - `default` - basic settings, read only
105
105
  - `git` - reads configuration from `git config pre-commit.*`, allow local update
106
- - `yaml` - reads configuration from `/etc/pre-commit.yml`, `$HOME/.pre-commit.yml` and `config/pre-commit.yml`, allows `config/pre-commit.yml` updates
106
+ - `yaml` - reads configuration from `/etc/pre_commit.yml`, `$HOME/.pre_commit.yml` and `config/pre_commit.yml`, allows `config/pre_commit.yml` updates
107
107
  - `env` - reads configuration from environment variables
108
108
 
109
109
  ## [Contributing](CONTRIBUTING.md)
@@ -3,36 +3,56 @@ require 'pre-commit/checks/plugin'
3
3
  module PreCommit
4
4
  module Checks
5
5
  class Migration < Plugin
6
+ VERSION_PATTERN = /(\d{14})/
7
+
8
+ self::VersionedFile = Struct.new(:file, :version) do
9
+ alias_method :to_s, :file
10
+ end
11
+
6
12
  def self.aliases
7
13
  [:migrations]
8
14
  end
9
15
 
10
16
  def call(staged_files)
11
- migration_files = migration_files(staged_files)
12
- schema_files = schema_files(staged_files)
17
+ migration_files = versioned_migration_files(staged_files)
18
+ schema_files = versioned_schema_files(staged_files)
13
19
 
14
20
  if migration_files.any? && schema_files.none?
15
21
  "It looks like you're adding a migration, but did not update the schema file"
16
22
  elsif migration_files.none? && schema_files.any?
17
23
  "You're trying to change the schema without adding a migration file"
18
24
  elsif migration_files.any? && schema_files.any?
19
- versions = migration_files.map { |f| f[/\d+/] }
20
- schema = schema_files.map { |f| File.read(f) }.join
21
- missing_versions = versions.select { |version| !schema.include?(version) }
25
+ migration_versions = migration_files.map(&:version)
26
+ missing_versions = migration_versions - schema_files.map(&:version)
22
27
  if missing_versions.any?
23
- "You did not add the schema versions for #{versions.join(', ')} to #{schema_files.join(' or ')}"
28
+ "You did not add the schema versions for "\
29
+ "#{migration_versions.join(', ')} to #{schema_files.join(' or ')}"
24
30
  end
25
31
  end
26
32
  end
27
33
 
28
34
  private
29
35
 
30
- def migration_files(staged_files)
31
- staged_files.grep(/db\/migrate\/.*\.rb/)
36
+ def versioned_migration_files(staged_files)
37
+ files = staged_files.grep(/db\/migrate\/.*\.rb/)
38
+
39
+ files.each_with_object([]) do |f, result|
40
+ if f =~ VERSION_PATTERN
41
+ result << VersionedFile.new(f, $1)
42
+ end
43
+ end
32
44
  end
33
45
 
34
- def schema_files(staged_files)
35
- staged_files.select { |f| File.basename(f) =~ /schema\.rb|structure.*\.sql/ }
46
+ def versioned_schema_files(staged_files)
47
+ files = staged_files.select do |f|
48
+ File.basename(f) =~ /schema\.rb|structure.*\.sql/
49
+ end
50
+
51
+ files.each_with_object([]) do |f, result|
52
+ if IO.read(f) =~ VERSION_PATTERN
53
+ result << VersionedFile.new(f, $1)
54
+ end
55
+ end
36
56
  end
37
57
 
38
58
  def self.description
@@ -56,7 +56,7 @@ module PreCommit
56
56
  $stderr.puts "Warning: #{name} config file '#{config_location}' does not exist"
57
57
  $stderr.puts "Set the path to the config file using:"
58
58
  $stderr.puts "\tgit config pre-commit.#{property_name} 'path/relative/to/git/dir/#{name}.config'"
59
- $stderr.puts "Or in 'config/pre-commit.yml':"
59
+ $stderr.puts "Or in 'config/pre_commit.yml':"
60
60
  $stderr.puts "\t#{yaml_property_name}: path/relative/to/git/dir/#{name}.config"
61
61
  $stderr.puts "Or set the environment variable:"
62
62
  $stderr.puts "\texport #{environment_variable_name}='path/relative/to/git/dir/#{name}.config'"
@@ -1,4 +1,6 @@
1
1
  require 'pluginator'
2
+ require 'benchmark'
3
+
2
4
  require 'pre-commit/utils/staged_files'
3
5
  require 'pre-commit/configuration'
4
6
  require 'pre-commit/list_evaluator'
@@ -7,13 +9,14 @@ module PreCommit
7
9
  class Runner
8
10
  include PreCommit::Utils::StagedFiles
9
11
 
10
- attr_reader :pluginator, :config
12
+ attr_reader :pluginator, :config, :debug
11
13
 
12
14
  def initialize(stderr = nil, staged_files = nil, config = nil, pluginator = nil)
13
15
  @stderr = (stderr or $stderr)
14
16
  @pluginator = (pluginator or PreCommit.pluginator)
15
17
  @config = (config or PreCommit::Configuration.new(@pluginator))
16
18
  @staged_files = staged_files
19
+ @debug = ENV["PRE_COMMIT_DEBUG"]
17
20
  end
18
21
 
19
22
  def run(*args)
@@ -36,7 +39,17 @@ module PreCommit
36
39
  end
37
40
 
38
41
  def execute(list)
39
- list.map{|cmd| cmd.new(pluginator, config, list).call(staged_files.dup) }.compact
42
+ list.map do |cmd|
43
+ result = nil
44
+
45
+ seconds = Benchmark.realtime do
46
+ result = cmd.new(pluginator, config, list).call(staged_files.dup)
47
+ end
48
+
49
+ puts "#{cmd} #{seconds*1000}ms" if debug
50
+
51
+ result
52
+ end.compact
40
53
  end
41
54
 
42
55
  def list_to_run(name)
@@ -6,7 +6,7 @@ module PreCommit
6
6
  case args[0].to_s
7
7
  when "all" then staged_files_all
8
8
  when "" then staged_files
9
- else staged_files=args
9
+ else self.staged_files=args
10
10
  end
11
11
  end
12
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pre-commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shajith Chacko, Josh Lubaway
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-02 00:00:00.000000000 Z
11
+ date: 2014-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pluginator
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.23'
103
+ version: '0.25'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0.23'
110
+ version: '0.25'
111
111
  description: A git pre-commit hook written in ruby with a few more tricks up its sleeve
112
112
  email: dontneedmoreemail@example.com
113
113
  executables: