git_awesome_diff 0.0.2

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.
@@ -0,0 +1,3 @@
1
+ .bundle
2
+ .yard
3
+ vendor
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ git_awesome_diff (0.0.2)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ activesupport (3.2.8)
10
+ i18n (~> 0.6)
11
+ multi_json (~> 1.0)
12
+ colorize (0.5.8)
13
+ commander (4.1.2)
14
+ highline (~> 1.6.11)
15
+ diff-lcs (1.1.3)
16
+ grit (2.5.0)
17
+ diff-lcs (~> 1.1)
18
+ mime-types (~> 1.15)
19
+ posix-spawn (~> 0.3.6)
20
+ highline (1.6.14)
21
+ i18n (0.6.0)
22
+ mime-types (1.19)
23
+ multi_json (1.3.6)
24
+ posix-spawn (0.3.6)
25
+ rake (0.9.2.2)
26
+ rspec (2.10.0)
27
+ rspec-core (~> 2.10.0)
28
+ rspec-expectations (~> 2.10.0)
29
+ rspec-mocks (~> 2.10.0)
30
+ rspec-core (2.10.1)
31
+ rspec-expectations (2.10.0)
32
+ diff-lcs (~> 1.1.3)
33
+ rspec-mocks (2.10.1)
34
+ yard (0.8.2.1)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ activesupport
41
+ colorize
42
+ commander
43
+ git_awesome_diff!
44
+ grit
45
+ rake
46
+ rspec
47
+ yard
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2012 Max Prokopiev, Timur Vafin, FlatStack, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ git-awesome-diff
2
+ ================
3
+
4
+ Object Oriented Diffing for Git
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'git-awesome-diff'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install git-awesome-diff
20
+
21
+ Usage
22
+ -----
23
+
24
+ git awesome-diff ref1 ref2
25
+
26
+ For example:
27
+
28
+ git awesome-diff HEAD~1 master
29
+
30
+ Specs
31
+ -----
32
+
33
+ bundle exec rake
34
+
35
+ Contributing
36
+ ------------
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
43
+
44
+ Credits
45
+ -------
46
+
47
+ Made by [Max Prokopiev](https://github.com/juggler), [Timur Vafin](https://github.com/timurvafin)
48
+ in terms of HackDay @[FlatStack, LLC](http://www.flatstack.com)
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc 'Run specs'
7
+ RSpec::Core::RakeTask.new do |t|
8
+ t.verbose = false
9
+ end
10
+
11
+ task :default => :spec
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'commander/import'
4
+ require 'git_awesome_diff'
5
+
6
+ program :version, '1.0'
7
+ program :description, 'Git awesome diff tool'
8
+
9
+ default_command :make_diff
10
+
11
+ command :make_diff do |c|
12
+ c.syntax = 'git awesome-diff [ref1] [ref2]'
13
+ c.summary = 'prints diff'
14
+ c.description = ''
15
+ c.example 'description', 'command example'
16
+ c.option '--format TYPE', 'Some switch that does something'
17
+ c.option '--path PATH', 'Path to the repo'
18
+ c.option '--exclude REGEXP', 'Exclude files from processing'
19
+
20
+ c.action do |args, options|
21
+ options.default \
22
+ :path => Dir.pwd,
23
+ :format => 'pretty'
24
+
25
+ gad = GitAwesomeDiff::Diff.new(File.expand_path(options.path), options.exclude)
26
+
27
+ if gad.valid?
28
+ gad.diff!(*args)
29
+ GitAwesomeDiff::Formatter.new(gad.added_objects, gad.removed_objects).print(options.format, *args)
30
+ else
31
+ puts gad.errors.join("\n")
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/git_awesome_diff/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Max Prokopiev", "Timur Vafin", "FlatStack, LLC"]
6
+ gem.email = ["max-prokopiev@yandex.ru", "me@timurv.ru"]
7
+ gem.description = %q{Object Oriented Diffing for Git}
8
+ gem.summary = %q{Object Oriented Diffing for Git}
9
+ gem.homepage = "https://github.com/fs/git-awesome-diff"
10
+
11
+ gem.add_development_dependency "grit"
12
+ gem.add_development_dependency "rake"
13
+ gem.add_development_dependency "yard"
14
+ gem.add_development_dependency "activesupport"
15
+ gem.add_development_dependency "commander"
16
+ gem.add_development_dependency "colorize"
17
+ gem.add_development_dependency "rspec"
18
+
19
+ gem.files = `git ls-files`.split($\)
20
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
+ gem.name = "git_awesome_diff"
23
+ gem.require_paths = ["lib"]
24
+ gem.version = GitAwesomeDiff::VERSION
25
+ end
@@ -0,0 +1,10 @@
1
+ require 'grit'
2
+ require 'yard'
3
+ require 'active_support/all'
4
+ require 'colorize'
5
+
6
+ module GitAwesomeDiff
7
+ autoload :VERSION, 'git_awesome_diff/version'
8
+ autoload :Diff, 'git_awesome_diff/diff'
9
+ autoload :Formatter, 'git_awesome_diff/formatter'
10
+ end
@@ -0,0 +1,86 @@
1
+ module GitAwesomeDiff
2
+ class Diff
3
+ attr_reader :path, :exclude_paths, :repo, :head, :errors, :added_objects, :removed_objects
4
+
5
+ def initialize(path, exclude_paths = '')
6
+ @path, @exclude_paths = path, exclude_paths
7
+
8
+ load_repo
9
+
10
+ validate!
11
+ return false unless valid?
12
+
13
+ save_head
14
+ end
15
+
16
+ def valid?
17
+ errors.blank?
18
+ end
19
+
20
+ def diff!(*refs)
21
+ ref1 = parse_rev(refs.shift || 'HEAD~1')
22
+ ref2 = parse_rev(refs.shift || 'master')
23
+ registry = []
24
+
25
+ @added_objects, @removed_objects = [], []
26
+
27
+ begin
28
+ checkout(ref1)
29
+ registry << generate_yardoc
30
+
31
+ checkout(ref2)
32
+ registry << generate_yardoc
33
+
34
+ @added_objects = (registry[1] - registry[0]).sort
35
+ @removed_objects = (registry[0] - registry[1]).sort
36
+ ensure
37
+ checkout(head)
38
+ end
39
+
40
+ self
41
+ end
42
+
43
+ private
44
+
45
+ def load_repo
46
+ Dir.chdir(path)
47
+ @repo = Grit::Repo.new(path)
48
+ end
49
+
50
+ def validate!
51
+ @errors = []
52
+ @errors << 'Repository should be clean' unless repo_clean?
53
+ @errors << 'HEAD is unknown' unless head_present?
54
+ end
55
+
56
+ def repo_clean?
57
+ repo.status.changed.merge(repo.status.added).merge(repo.status.deleted).blank?
58
+ end
59
+
60
+ def head_present?
61
+ repo.head.present?
62
+ end
63
+
64
+ def save_head
65
+ @head = repo.head.name
66
+ end
67
+
68
+ def parse_rev(rev)
69
+ (repo.git.native 'rev-parse', {verify: true}, rev).chop
70
+ end
71
+
72
+ def checkout(rev)
73
+ repo.git.native :checkout, {}, rev
74
+ end
75
+
76
+ def generate_yardoc
77
+ options = ['--no-output', '--no-stats', '--no-save', '--quiet']
78
+ options << "--exclude=#{exclude_paths}" if exclude_paths.present?
79
+ options << path
80
+
81
+ YARD::Registry.clear
82
+ YARD::CLI::Yardoc.run(*options)
83
+ YARD::Registry.all.map {|o| o.path}
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,35 @@
1
+ module GitAwesomeDiff
2
+ class Formatter
3
+ def initialize(added_objects, removed_objects)
4
+ @added = added_objects
5
+ @removed = removed_objects
6
+ end
7
+
8
+ def print(format, *args)
9
+ puts "Showing diff between #{args[0]} and #{args[1]}\n".colorize(:black)
10
+ case format
11
+ when /pretty/ then pretty_print
12
+ when /simple/ then simple_print
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def pretty_print
19
+ if @added.present?
20
+ puts "Added objects:"
21
+ puts "\t" + @added.join("\n\t").colorize(:green)
22
+ end
23
+ puts
24
+ if @removed.present?
25
+ puts "Removed objects:"
26
+ puts "\t" + @removed.join("\n\t").colorize(:red)
27
+ end
28
+ end
29
+
30
+ def simple_print
31
+ puts "+#{@added.join("\n+")}\n\n" if @added.present?
32
+ puts "-#{@removed.join("\n-")}\n\n" if @removed.present?
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module GitAwesomeDiff
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,2 @@
1
+ class TestClass
2
+ end
@@ -0,0 +1,5 @@
1
+ class TestClass
2
+ def first_method
3
+ foobar
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ class TestClass
2
+ def first_method
3
+ foobar
4
+ end
5
+ def second_method(arg)
6
+ test
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ class SecondClass
2
+
3
+ def another_method
4
+ foobar
5
+ end
6
+
7
+ def second_method(arg)
8
+ test
9
+ end
10
+
11
+ def test_method(t)
12
+ puts
13
+ end
14
+ end
@@ -0,0 +1,96 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe GitAwesomeDiff::Diff do
4
+
5
+ before :all do
6
+ @repo_path = create_test_repo
7
+ end
8
+
9
+ let(:awesome_diff) { GitAwesomeDiff::Diff.new(@repo_path) }
10
+ subject { awesome_diff }
11
+
12
+ its(:head) { should match 'master' }
13
+ its(:repo) { should be_kind_of Grit::Repo }
14
+
15
+ describe '#valid' do
16
+ context 'when there is no errors' do
17
+ it { should be_valid }
18
+ end
19
+
20
+ context 'when repo is not clean' do
21
+ before do
22
+ File.rename('test.rb', '1.rb')
23
+ end
24
+
25
+ after do
26
+ File.rename('1.rb', 'test.rb')
27
+ end
28
+
29
+ it { should_not be_valid }
30
+
31
+ describe 'errors' do
32
+ subject { awesome_diff.errors }
33
+
34
+ it { should_not be_empty }
35
+ its(:first) { should match 'Repository should be clean' }
36
+ end
37
+ end
38
+
39
+ context 'when there is no HEAD' do
40
+ before do
41
+ File.rename('.git/HEAD', '.git/HEAD_')
42
+ `touch .git/HEAD`
43
+ end
44
+
45
+ after do
46
+ File.rename('.git/HEAD_', '.git/HEAD')
47
+ end
48
+
49
+ it { should_not be_valid }
50
+
51
+ describe 'errors' do
52
+ subject { awesome_diff.errors }
53
+
54
+ it { should_not be_empty }
55
+ its(:first) { should match 'HEAD is unknown' }
56
+ end
57
+ end
58
+ end
59
+
60
+ describe '#diff!' do
61
+ context 'when there are only added objects' do
62
+ let(:diff) { awesome_diff.diff!('HEAD~3', 'HEAD~2') }
63
+
64
+ describe 'added object' do
65
+ subject { diff.added_objects }
66
+
67
+ it { should_not be_empty }
68
+ its(:first) { should match 'TestClass#first_method' }
69
+ end
70
+
71
+ describe 'removed objects' do
72
+ subject { diff.removed_objects }
73
+
74
+ it { should be_empty }
75
+ end
76
+ end
77
+
78
+ context 'when there are both added and removed objects' do
79
+ let(:diff) { awesome_diff.diff!('HEAD~1', 'master') }
80
+
81
+ describe 'added objects' do
82
+ subject { diff.added_objects }
83
+
84
+ it { should_not be_empty }
85
+ it { should == ['SecondClass', 'SecondClass#another_method', 'SecondClass#second_method', 'SecondClass#test_method'] }
86
+ end
87
+
88
+ describe 'removed objects' do
89
+ subject { diff.removed_objects }
90
+
91
+ it { should_not be_empty }
92
+ it { should == ["TestClass", "TestClass#first_method", "TestClass#second_method"] }
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,11 @@
1
+ require 'git_awesome_diff'
2
+
3
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each do |f|
4
+ require f
5
+ end
6
+
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+ end
@@ -0,0 +1,18 @@
1
+ require 'tmpdir'
2
+
3
+ def create_test_repo
4
+ repo_dir = Dir.mktmpdir
5
+ repo_full_path = "#{repo_dir}/.git"
6
+ `git --git-dir=#{repo_full_path} init`
7
+ @repo = Grit::Repo.new(repo_full_path)
8
+
9
+ fixtures = Dir[File.expand_path(File.dirname(__FILE__) + '/../fixtures/*.rb')]
10
+ Dir.chdir(repo_dir)
11
+ fixtures.each_with_index do |file, index|
12
+ FileUtils.cp(file, 'test.rb')
13
+ @repo.add 'test.rb'
14
+ @repo.commit_all "commit #{index}"
15
+ end
16
+
17
+ repo_dir
18
+ end
metadata ADDED
@@ -0,0 +1,196 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_awesome_diff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Max Prokopiev
9
+ - Timur Vafin
10
+ - FlatStack, LLC
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-09-26 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: grit
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: rake
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: yard
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ - !ruby/object:Gem::Dependency
65
+ name: activesupport
66
+ requirement: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ - !ruby/object:Gem::Dependency
81
+ name: commander
82
+ requirement: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: colorize
98
+ requirement: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rspec
114
+ requirement: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ description: Object Oriented Diffing for Git
129
+ email:
130
+ - max-prokopiev@yandex.ru
131
+ - me@timurv.ru
132
+ executables:
133
+ - git_awesome_diff
134
+ extensions: []
135
+ extra_rdoc_files: []
136
+ files:
137
+ - .gitignore
138
+ - .rspec
139
+ - .rvmrc
140
+ - Gemfile
141
+ - Gemfile.lock
142
+ - LICENSE
143
+ - README.md
144
+ - Rakefile
145
+ - bin/git_awesome_diff
146
+ - git_awesome_diff.gemspec
147
+ - lib/git_awesome_diff.rb
148
+ - lib/git_awesome_diff/diff.rb
149
+ - lib/git_awesome_diff/formatter.rb
150
+ - lib/git_awesome_diff/version.rb
151
+ - spec/fixtures/initial.rb
152
+ - spec/fixtures/step1.rb
153
+ - spec/fixtures/step2.rb
154
+ - spec/fixtures/step3.rb
155
+ - spec/git_awesome_diff/diff_spec.rb
156
+ - spec/spec_helper.rb
157
+ - spec/support/helpers.rb
158
+ homepage: https://github.com/fs/git-awesome-diff
159
+ licenses: []
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ segments:
171
+ - 0
172
+ hash: 545746365725136601
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ none: false
175
+ requirements:
176
+ - - ! '>='
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ segments:
180
+ - 0
181
+ hash: 545746365725136601
182
+ requirements: []
183
+ rubyforge_project:
184
+ rubygems_version: 1.8.24
185
+ signing_key:
186
+ specification_version: 3
187
+ summary: Object Oriented Diffing for Git
188
+ test_files:
189
+ - spec/fixtures/initial.rb
190
+ - spec/fixtures/step1.rb
191
+ - spec/fixtures/step2.rb
192
+ - spec/fixtures/step3.rb
193
+ - spec/git_awesome_diff/diff_spec.rb
194
+ - spec/spec_helper.rb
195
+ - spec/support/helpers.rb
196
+ has_rdoc: