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 +4 -4
- data/README.md +7 -7
- data/lib/plugins/pre_commit/checks/migration.rb +30 -10
- data/lib/pre-commit/checks/plugin/config_file.rb +1 -1
- data/lib/pre-commit/runner.rb +15 -2
- data/lib/pre-commit/utils/staged_files.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ab21a6aa71a872a9bcd1764a116ccb93bfd9ac6
|
4
|
+
data.tar.gz: fbc548adf285e5872c4b14b633f108eb28a62c66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
[](https://rubygems.org/gems/pre-commit)
|
4
|
+
[](https://codeclimate.com/github/jish/pre-commit)
|
5
|
+
[](https://coveralls.io/r/jish/pre-commit?branch=master)
|
6
|
+
[](https://travis-ci.org/jish/pre-commit)
|
7
7
|
[](https://gemnasium.com/jish/pre-commit)
|
8
|
-
[](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/
|
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/
|
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 =
|
12
|
-
schema_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
|
-
|
20
|
-
|
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
|
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
|
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
|
35
|
-
staged_files.select
|
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/
|
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'"
|
data/lib/pre-commit/runner.rb
CHANGED
@@ -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
|
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)
|
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.
|
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-
|
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.
|
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.
|
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:
|