overcommit 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/config/templates.yml CHANGED
@@ -6,6 +6,7 @@ default:
6
6
  - release_note
7
7
  pre_commit:
8
8
  - causes_email
9
+ - image_optimization
9
10
  - restricted_paths
10
11
  - test_history
11
12
  all:
@@ -0,0 +1,50 @@
1
+ module Overcommit::GitHook
2
+ class ImageOptimization < HookSpecificCheck
3
+ include HookRegistry
4
+ file_types :gif, :jpeg, :jpg, :png
5
+
6
+ def run_check
7
+ begin
8
+ require 'image_optim'
9
+ rescue LoadError
10
+ return :warn, "'image_optim' gem not installed -- run `gem install image_optim`"
11
+ end
12
+
13
+ optimized_images =
14
+ begin
15
+ ImageSet.new(staged.map(&:original_path)).
16
+ optimize_with(ImageOptim.new(:pngout => false))
17
+
18
+ rescue ImageOptim::BinNotFoundError => e
19
+ return :stop,
20
+ "#{e.message}. The image_optim gem is dependendent on this binary. " <<
21
+ "See https://github.com/toy/image_optim for more info."
22
+ end
23
+
24
+ if optimized_images.any?
25
+ return :bad,
26
+ "Optimized #{optimized_images.map(&:to_s).inspect}. " <<
27
+ " Please add them to your commit."
28
+ else
29
+ return :good
30
+ end
31
+ end
32
+
33
+ class ImageSet
34
+ attr_reader :image_paths
35
+
36
+ def initialize(image_paths)
37
+ @image_paths ||= image_paths
38
+ end
39
+
40
+ def optimize_with(image_optim)
41
+ results =
42
+ image_optim.optimize_images!(image_paths) do |path, was_optimized|
43
+ path if was_optimized
44
+ end
45
+
46
+ results.compact
47
+ end
48
+ end
49
+ end
50
+ end
@@ -50,7 +50,7 @@ module Overcommit
50
50
  # Get a list of staged Added, Copied, or Modified files (ignore renames
51
51
  # and deletions, since there should be nothing to check).
52
52
  def modified_files
53
- `git diff --cached --name-only --diff-filter=ACM`.split "\n"
53
+ `git diff --cached --name-only --diff-filter=ACM --ignore-submodules=all`.split "\n"
54
54
  end
55
55
 
56
56
  private
@@ -1,3 +1,3 @@
1
1
  module Overcommit
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overcommit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 2
10
- version: 0.3.2
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Causes Engineering
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-10-28 00:00:00 -07:00
18
+ date: 2013-11-06 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -34,6 +34,22 @@ dependencies:
34
34
  version: 2.13.0
35
35
  type: :development
36
36
  version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: image_optim
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - "="
44
+ - !ruby/object:Gem::Version
45
+ hash: 57
46
+ segments:
47
+ - 0
48
+ - 9
49
+ - 1
50
+ version: 0.9.1
51
+ type: :development
52
+ version_requirements: *id002
37
53
  description: Overcommit is a utility to install and extend Git hooks
38
54
  email: eng@causes.com
39
55
  executables:
@@ -62,6 +78,7 @@ files:
62
78
  - lib/overcommit/plugins/pre_commit/causes_email.rb
63
79
  - lib/overcommit/plugins/pre_commit/author_name.rb
64
80
  - lib/overcommit/plugins/pre_commit/whitespace.rb
81
+ - lib/overcommit/plugins/pre_commit/image_optimization.rb
65
82
  - lib/overcommit/plugins/pre_commit/python_flake8.rb
66
83
  - lib/overcommit/plugins/pre_commit/coffee_lint.rb
67
84
  - lib/overcommit/plugins/pre_commit/test_history.rb