git_wrapper 1.0.3 → 1.1.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.
data/.coveralls.yml ADDED
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+ repo_token: DuFQczMz4oKxkdQZy7XcgYO8aol5vxML3
data/.gitignore CHANGED
@@ -3,3 +3,5 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  .idea
6
+ coverage
7
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - 2.0
5
+ - jruby
6
+ before_script:
7
+ - git config --global user.name "User Name"
8
+ - git config --global user.email "user@mail.com"
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in git_wrapper.gemspec
4
4
  gemspec
5
+
6
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # GitWrapper
2
2
 
3
- OO git command line wrapper
3
+ [![Gem Version](https://badge.fury.io/rb/git_wrapper.png)](https://rubygems.org/gems/git_wrapper)
4
+ [![Build Status](https://travis-ci.org/gabynaiman/git_wrapper.png?branch=master)](https://travis-ci.org/gabynaiman/git_wrapper)
5
+ [![Coverage Status](https://coveralls.io/repos/gabynaiman/git_wrapper/badge.png?branch=master)](https://coveralls.io/r/gabynaiman/git_wrapper?branch=master)
6
+ [![Code Climate](https://codeclimate.com/github/gabynaiman/git_wrapper.png)](https://codeclimate.com/github/gabynaiman/git_wrapper)
7
+ [![Dependency Status](https://gemnasium.com/gabynaiman/git_wrapper.png)](https://gemnasium.com/gabynaiman/git_wrapper)
8
+
9
+ Object Oriented git command line wrapper
4
10
 
5
11
  ## Installation
6
12
 
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new do |task|
5
+ task.pattern = 'spec/**/*_spec.rb'
6
+ task.rspec_opts = '--tty --color -f documentation'
7
+ task.verbose = false
8
+ end
9
+
10
+ task default: :spec
data/git_wrapper.gemspec CHANGED
@@ -17,5 +17,9 @@ Gem::Specification.new do |s|
17
17
  s.require_paths = ["lib"]
18
18
 
19
19
  s.add_runtime_dependency 'nokogiri'
20
+
21
+ s.add_development_dependency "bundler", "~> 1.3"
22
+ s.add_development_dependency "rake"
20
23
  s.add_development_dependency 'rspec'
24
+ s.add_development_dependency "simplecov"
21
25
  end
@@ -0,0 +1,23 @@
1
+ module GitWrapper
2
+ module Commands
3
+ class DiffTree < Git
4
+
5
+ def commit(commit)
6
+ @commit = commit
7
+ self
8
+ end
9
+
10
+ def command
11
+ "diff-tree #{@commit} -r --name-status"
12
+ end
13
+
14
+ def result
15
+ files = output.split(/\n/)[1..-1] || []
16
+ files.map do |line|
17
+ Results::DiffNameStatus.parse(line)
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -30,10 +30,16 @@ module GitWrapper
30
30
  end
31
31
  end
32
32
 
33
+ def success?
34
+ @success
35
+ end
36
+
33
37
  def result
34
38
  @success
35
39
  end
36
40
 
41
+ private
42
+
37
43
  def to_relative_path(file_name)
38
44
  base_folder = location_folder.gsub("\\", "/")
39
45
  file_name.gsub("\\", "/").gsub(base_folder + "/", "")
@@ -1,6 +1,7 @@
1
1
  module GitWrapper
2
2
  module Commands
3
3
  class Log < Git
4
+
4
5
  ATTRIBUTES = {
5
6
  :commit_hash => 'H',
6
7
  :abbreviated_commit_hash => 'h',
@@ -38,8 +39,8 @@ module GitWrapper
38
39
  :reflog_subject => 'gs'
39
40
  }
40
41
 
41
- def file(file_name)
42
- @file = to_relative_path(file_name)
42
+ def files(files)
43
+ @files = files.map{|f|to_relative_path(f)}
43
44
  self
44
45
  end
45
46
 
@@ -48,25 +49,59 @@ module GitWrapper
48
49
  self
49
50
  end
50
51
 
52
+ def author(author)
53
+ @author = author
54
+ self
55
+ end
56
+
57
+ def grep(grep)
58
+ @grep = grep
59
+ self
60
+ end
61
+
62
+ def since(date)
63
+ @since = date
64
+ self
65
+ end
66
+
67
+ def until(date)
68
+ @until = date
69
+ self
70
+ end
71
+
72
+ def skip(skip)
73
+ @skip = skip
74
+ self
75
+ end
76
+
77
+ def max_count(max_count)
78
+ @max_count = max_count
79
+ self
80
+ end
81
+
51
82
  def command
52
- command = "log --format=\"<log>#{xml_structure}</log>\""
83
+ command = "log -i --format=\"<log>#{xml_structure}</log>\""
53
84
  command += " #{@commit}" if @commit
54
- command += " \"#{@file}\"" if @file
85
+ command += " --author \"#{@author}\"" if @author
86
+ command += " --since \"#{@since}\"" if @since
87
+ command += " --until \"#{@until}\"" if @until
88
+ command += " --grep \"#{@grep}\"" if @grep
89
+ command += " --skip #{@skip}" if @skip
90
+ command += " --max-count \"#{@max_count}\"" if @max_count
91
+ command += " #{@files.map{|f| "\"#{f}\"" }.join(' ')}" if @files
55
92
  command
56
93
  end
57
94
 
58
95
  def result
59
- if output.nil?
60
- return nil if @commit
61
- return []
62
- end
96
+ return nil unless success?
63
97
 
64
- results = Nokogiri::XML("<logs>#{output}</logs>").xpath('logs/log').map do |element|
65
- Results::LogInfo.new(Hash[*element.children.map { |node| [node.name.to_sym, node.text] }.flatten])
98
+ results = []
99
+ if output
100
+ results = Nokogiri::XML("<logs>#{output}</logs>").xpath('logs/log').map do |element|
101
+ Results::LogInfo.new(Hash[*element.children.flat_map { |node| [node.name.to_sym, node.text] }])
102
+ end
66
103
  end
67
-
68
- return results.first if @commit
69
- results
104
+ @commit ? results.first : results
70
105
  end
71
106
 
72
107
  private
@@ -0,0 +1,52 @@
1
+ module GitWrapper
2
+ module Commands
3
+ class RevList < Git
4
+
5
+ def author(author)
6
+ @author = author
7
+ self
8
+ end
9
+
10
+ def grep(grep)
11
+ @grep = grep
12
+ self
13
+ end
14
+
15
+ def since(date)
16
+ @since = date
17
+ self
18
+ end
19
+
20
+ def until(date)
21
+ @until = date
22
+ self
23
+ end
24
+
25
+ def count
26
+ @count = true
27
+ self
28
+ end
29
+
30
+ def files(files)
31
+ @files = files.map { |f| to_relative_path(f) }
32
+ self
33
+ end
34
+
35
+ def command
36
+ command = "rev-list HEAD -i #{@count ? ' --count ' : ''}"
37
+ command += " --author \"#{@author}\"" if @author
38
+ command += " --since \"#{@since}\"" if @since
39
+ command += " --until \"#{@until}\"" if @until
40
+ command += " --grep \"#{@grep}\"" if @grep
41
+ command += " #{@files.map{|f| "\"#{f}\"" }.join(' ')}" if @files
42
+ command
43
+ end
44
+
45
+ def result
46
+ return nil unless success?
47
+ @count ? output.to_i : output.split(/\n/)
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -11,6 +11,8 @@ module GitWrapper
11
11
  end
12
12
  end
13
13
 
14
+ private
15
+
14
16
  def self.ruby_execute(command, options={})
15
17
  location_folder = options[:chdir] || '.'
16
18
  result = nil
@@ -96,13 +96,27 @@ module GitWrapper
96
96
  end
97
97
 
98
98
  def log(options={})
99
- if options[:file_name]
100
- execute(Commands::Log.new(@location).file(options[:file_name]))
101
- elsif options[:commit]
102
- execute(Commands::Log.new(@location).commit(options[:commit]))
103
- else
104
- execute(Commands::Log.new(@location))
99
+ command = Commands::Log.new(@location)
100
+ options.each do |option, value|
101
+ command.send option, value if value && !value.to_s.strip.empty?
102
+ end
103
+ execute(command)
104
+ end
105
+
106
+ def rev_list(options={})
107
+ command = Commands::RevList.new(@location)
108
+ options.each do |option, value|
109
+ command.send option, value if value && !value.to_s.strip.empty?
110
+ end
111
+ execute(command)
112
+ end
113
+
114
+ def rev_list_count(options={})
115
+ command = Commands::RevList.new(@location).count
116
+ options.each do |option, value|
117
+ command.send option, value if value && !value.to_s.strip.empty?
105
118
  end
119
+ execute(command)
106
120
  end
107
121
 
108
122
  def branches
@@ -174,6 +188,10 @@ module GitWrapper
174
188
  execute(Commands::Diff.new(@location).with(commit).reverse)
175
189
  end
176
190
 
191
+ def diff_tree(commit)
192
+ execute(Commands::DiffTree.new(@location).commit(commit))
193
+ end
194
+
177
195
  def revert(commit)
178
196
  if log(:commit => commit).merge?
179
197
  execute(Commands::Revert.new(@location).merge(commit))
@@ -1,9 +1,14 @@
1
1
  module GitWrapper
2
2
  module Results
3
3
  class LogInfo
4
+
4
5
  def initialize(attributes)
5
- attributes.each do |name, value|
6
- define_singleton_method name, lambda { value }
6
+ @attributes = attributes
7
+ end
8
+
9
+ Commands::Log::ATTRIBUTES.keys.each do |name|
10
+ define_method name do
11
+ @attributes[name]
7
12
  end
8
13
  end
9
14
 
@@ -1,3 +1,3 @@
1
1
  module GitWrapper
2
- VERSION = '1.0.3'
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/git_wrapper.rb CHANGED
@@ -25,9 +25,11 @@ require 'git_wrapper/commands/tag'
25
25
  require 'git_wrapper/commands/merge'
26
26
  require 'git_wrapper/commands/fetch'
27
27
  require 'git_wrapper/commands/diff'
28
+ require 'git_wrapper/commands/diff_tree'
28
29
  require 'git_wrapper/commands/revert'
29
30
  require 'git_wrapper/commands/reset'
30
31
  require 'git_wrapper/commands/config'
32
+ require 'git_wrapper/commands/rev_list'
31
33
 
32
34
  require 'git_wrapper/results/file_status'
33
35
  require 'git_wrapper/results/status_porcelain'
@@ -0,0 +1,8 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start
@@ -117,12 +117,12 @@ describe GitWrapper, '-> Repository' do
117
117
  repo.commit('comment').should be_false
118
118
  end
119
119
 
120
- it 'Commt in name of another user' do
120
+ it 'Commit in name of another user' do
121
121
  repo = Repository.new(@file_helper.create_temp_folder)
122
122
  repo.init
123
123
  @file_helper.create_temp_file(repo.location, 'test')
124
124
  repo.add_all
125
- repo.commit('first_commit', :author_name => 'another_author', :author_email => 'another_author@mail.com').should be_true
125
+ repo.commit('first_commit', author_name: 'another_author', author_email: 'another_author@mail.com').should be_true
126
126
 
127
127
  log = repo.log.first
128
128
  log.author_name.should eq 'another_author'
@@ -255,7 +255,7 @@ describe GitWrapper, '-> Repository' do
255
255
  my_repo.show_theirs(File.basename(my_file)).should eq("version theirs\n")
256
256
  end
257
257
 
258
- it 'Show file from differente versions' do
258
+ it 'Show file from different versions' do
259
259
  repo = Repository.new(@file_helper.create_temp_folder)
260
260
  repo.init
261
261
 
@@ -298,8 +298,8 @@ describe GitWrapper, '-> Repository' do
298
298
  repo.add_all
299
299
  repo.commit('second commit')
300
300
 
301
- repo.log(:file_name => File.basename(file_name1)).should have(2).items
302
- repo.log(:file_name => File.basename(file_name2)).should have(1).items
301
+ repo.log(files: [File.basename(file_name1)]).should have(2).items
302
+ repo.log(files: [File.basename(file_name2)]).should have(1).items
303
303
  end
304
304
 
305
305
  it 'Show merge logs' do
@@ -333,6 +333,314 @@ describe GitWrapper, '-> Repository' do
333
333
  log.parents.last.should eq second_commit.commit_hash
334
334
  end
335
335
 
336
+ it 'Show logs by files' do
337
+ repo = Repository.new(@file_helper.create_temp_folder)
338
+ repo.init
339
+
340
+ file_name1 = @file_helper.create_temp_file(repo.location, 'test')
341
+ file_name2 = @file_helper.create_temp_file(repo.location, 'test')
342
+
343
+ repo.add_all
344
+ repo.commit('first commit')
345
+
346
+ file_name3 = @file_helper.create_temp_file(repo.location, 'test')
347
+ File.open(file_name1, 'w') { |f| f.puts 'test 2' }
348
+
349
+ repo.add_all
350
+ repo.commit('second commit')
351
+
352
+ File.open(file_name3, 'w') { |f| f.puts 'test 2' }
353
+
354
+ repo.add_all
355
+ repo.commit('third commit')
356
+
357
+ files = [file_name1, file_name2, file_name3].map { |f| File.basename(f) }
358
+
359
+ repo.log(files: files).should have(3).items
360
+
361
+ files = [file_name1, file_name2].map { |f| File.basename(f) }
362
+
363
+ repo.log(files: files).should have(2).items
364
+ repo.log(files: []).should have(3).items
365
+ repo.log(files: nil).should have(3).items
366
+
367
+ repo.log.should have(3).items
368
+
369
+ files = [file_name1, 'non_exist_file.txt'].map { |f| File.basename(f) }
370
+
371
+ repo.log(files: files).should be_nil
372
+ end
373
+
374
+ it 'Show commit logs by author' do
375
+ repo = Repository.new(@file_helper.create_temp_folder)
376
+ repo.init
377
+
378
+ @file_helper.create_temp_file(repo.location, 'test')
379
+ @file_helper.create_temp_file(repo.location, 'test')
380
+
381
+ repo.add_all
382
+
383
+ repo.commit('first_commit', author_name: 'author_name', author_email: 'author_name@mail.com')
384
+
385
+ repo.log(author: 'another_name').should have(0).items
386
+ repo.log(author: 'Author_name').should have(1).items
387
+ repo.log(author: 'author_name@mail.com').should have(1).items
388
+ repo.log(author: '').should have(1).items
389
+ repo.log(author: nil).should have(1).items
390
+ end
391
+
392
+ it 'Show commit logs by until' do
393
+ repo = Repository.new(@file_helper.create_temp_folder)
394
+ repo.init
395
+
396
+ @file_helper.create_temp_file(repo.location, 'test')
397
+ @file_helper.create_temp_file(repo.location, 'test')
398
+ repo.add_all
399
+ repo.commit 'first_commit'
400
+
401
+ repo.log(until: yesterday).should have(0).items
402
+ repo.log(until: today).should have(0).items
403
+ repo.log(until: now).should have(1).items
404
+ repo.log(until: tomorrow).should have(1).items
405
+ repo.log(until: '').should have(1).items
406
+ repo.log(until: nil).should have(1).items
407
+ end
408
+
409
+ it 'Show commit logs by since' do
410
+ repo = Repository.new(@file_helper.create_temp_folder)
411
+ repo.init
412
+
413
+ @file_helper.create_temp_file(repo.location, 'test')
414
+ @file_helper.create_temp_file(repo.location, 'test')
415
+ repo.add_all
416
+ repo.commit 'first_commit'
417
+
418
+ repo.log(since: next_hour).should have(0).items
419
+ repo.log(since: tomorrow).should have(0).items
420
+ repo.log(since: next_month).should have(0).items
421
+ repo.log(since: next_year).should have(0).items
422
+ repo.log(since: today).should have(1).items
423
+ repo.log(since: yesterday).should have(1).items
424
+ repo.log(since: '').should have(1).items
425
+ repo.log(since: nil).should have(1).items
426
+ end
427
+
428
+ it 'Show commit logs by grep' do
429
+ repo = Repository.new(@file_helper.create_temp_folder)
430
+ repo.init
431
+
432
+ @file_helper.create_temp_file(repo.location, 'test')
433
+ @file_helper.create_temp_file(repo.location, 'test')
434
+ repo.add_all
435
+ repo.commit 'first_commit'
436
+
437
+ repo.log(grep: 'second_commit').should have(0).items
438
+ repo.log(grep: 'FirsT_commit').should have(1).items
439
+ repo.log(grep: 'first').should have(1).items
440
+ repo.log(grep: '').should have(1).items
441
+ repo.log(grep: nil).should have(1).items
442
+ end
443
+
444
+ it 'Show commit logs by author, since, until, grep and files' do
445
+ repo = Repository.new(@file_helper.create_temp_folder)
446
+ repo.init
447
+
448
+ file_name1 = @file_helper.create_temp_file(repo.location, 'test')
449
+ file_name2 = @file_helper.create_temp_file(repo.location, 'test')
450
+ repo.add_all
451
+ repo.commit('first_commit', author_name: 'author_name', author_email: 'author_name@mail.com')
452
+
453
+ files = [file_name1, file_name2].map { |f| File.basename(f) }
454
+
455
+ repo.log(author: 'author_name', since: yesterday, until: yesterday, grep: 'first_commit', files: files).should have(0).items
456
+ repo.log(author: 'author_name', since: yesterday, until: tomorrow, grep: 'first_commit', files: files).should have(1).items
457
+ end
458
+
459
+ it 'Show paginate logs' do
460
+ repo = Repository.new(@file_helper.create_temp_folder)
461
+ repo.init
462
+
463
+ 20.times do |i|
464
+ @file_helper.create_temp_file(repo.location, 'test')
465
+ repo.add_all
466
+ repo.commit 'commit_' + i.to_s
467
+ end
468
+
469
+ repo.log.should have(20).items
470
+ repo.log(max_count: 5).map(&:subject).should eq (15..19).map{ |i| "commit_#{i}" }.reverse
471
+ repo.log(skip: 2).first.subject.should eq 'commit_17'
472
+ repo.log(skip: 2, max_count: 5).map(&:subject).should eq (13..17).map{ |i| "commit_#{i}" }.reverse
473
+ end
474
+
475
+ it 'Rev List' do
476
+ repo = Repository.new(@file_helper.create_temp_folder)
477
+ repo.init
478
+
479
+ 2.times do |i|
480
+ @file_helper.create_temp_file(repo.location, 'test')
481
+ repo.add_all
482
+ repo.commit "Commit #{i}"
483
+ end
484
+
485
+ repo.rev_list.should have(2).items
486
+ 2.times { |i| repo.rev_list[i].should eq repo.log[i].commit_hash }
487
+ end
488
+
489
+ it 'Rev List count' do
490
+ repo = Repository.new(@file_helper.create_temp_folder)
491
+ repo.init
492
+
493
+ 2.times do |i|
494
+ @file_helper.create_temp_file(repo.location, 'test')
495
+ repo.add_all
496
+ repo.commit "Commit #{i}"
497
+
498
+ repo.rev_list_count.should eq i+1
499
+ repo.rev_list_count(grep: "Commit #{i}").should eq 1
500
+ end
501
+
502
+ end
503
+
504
+ it 'Rev List by author' do
505
+ repo = Repository.new(@file_helper.create_temp_folder)
506
+ repo.init
507
+
508
+ 2.times do |i|
509
+ @file_helper.create_temp_file(repo.location, 'test')
510
+ repo.add_all
511
+ repo.commit( "Commit #{i}", author_name: 'author_name', author_email: 'author_name@mail.com' )
512
+ end
513
+
514
+ repo.rev_list(author: 'author_name').should have(2).items
515
+ 2.times { |i| repo.rev_list(author: 'author_name')[i].should eq repo.log[i].commit_hash }
516
+
517
+ repo.log(author: 'Author_name').should have(2).items
518
+ repo.log(author: 'author_name@mail.com').should have(2).items
519
+ repo.log(author: '').should have(2).items
520
+ repo.log(author: nil).should have(2).items
521
+ repo.log(author: 'another_name').should have(0).items
522
+ end
523
+
524
+ it 'Rev List by since' do
525
+ repo = Repository.new(@file_helper.create_temp_folder)
526
+ repo.init
527
+
528
+ 2.times do |i|
529
+ @file_helper.create_temp_file(repo.location, 'test')
530
+ repo.add_all
531
+ repo.commit "Commit #{i}"
532
+ end
533
+
534
+ repo.rev_list(since: today).should have(2).items
535
+ 2.times { |i| repo.rev_list(since: today)[i].should eq repo.log(since: today)[i].commit_hash }
536
+
537
+ repo.log(since: next_hour).should have(0).items
538
+ repo.log(since: tomorrow).should have(0).items
539
+ repo.log(since: next_month).should have(0).items
540
+ repo.log(since: next_year).should have(0).items
541
+ repo.log(since: yesterday).should have(2).items
542
+ repo.log(since: '').should have(2).items
543
+ repo.log(since: nil).should have(2).items
544
+ end
545
+
546
+ it 'Rev List by until' do
547
+
548
+ repo = Repository.new(@file_helper.create_temp_folder)
549
+ repo.init
550
+
551
+ 2.times do |i|
552
+ @file_helper.create_temp_file(repo.location, 'test')
553
+ repo.add_all
554
+ repo.commit "Commit #{i}"
555
+ end
556
+
557
+ repo.rev_list(until: now).should have(2).items
558
+ 2.times { |i| repo.rev_list(until: now)[i].should eq repo.log(until: now)[i].commit_hash }
559
+
560
+ repo.log(until: yesterday).should have(0).items
561
+ repo.log(until: today).should have(0).items
562
+ repo.log(until: tomorrow).should have(2).items
563
+ repo.log(until: '').should have(2).items
564
+ repo.log(until: nil).should have(2).items
565
+ end
566
+
567
+ it 'Rev List by grep' do
568
+ repo = Repository.new(@file_helper.create_temp_folder)
569
+ repo.init
570
+
571
+ 2.times do |i|
572
+ @file_helper.create_temp_file(repo.location, 'test')
573
+ repo.add_all
574
+ repo.commit "Commit #{i}"
575
+ end
576
+
577
+ commits = repo.rev_list(grep: 'Commit 1')
578
+ commits.should have(1).items
579
+ commits.first.should eq repo.log(grep: 'Commit 1').first.commit_hash
580
+
581
+ repo.rev_list(grep: 'CoMMiT 1').should have(1).items
582
+ repo.rev_list(grep: 'Commit 2').should have(0).items
583
+ repo.rev_list(grep: 'Comm').should have(2).items
584
+ repo.rev_list(grep: '').should have(2).items
585
+ repo.rev_list(grep: nil).should have(2).items
586
+
587
+ end
588
+
589
+ it 'Rev List by files' do
590
+ repo = Repository.new(@file_helper.create_temp_folder)
591
+ repo.init
592
+
593
+ file_name1 = @file_helper.create_temp_file(repo.location, 'test')
594
+ file_name2 = @file_helper.create_temp_file(repo.location, 'test')
595
+
596
+ repo.add_all
597
+ repo.commit('first commit')
598
+
599
+ file_name3 = @file_helper.create_temp_file(repo.location, 'test')
600
+ File.open(file_name1, 'w') { |f| f.puts 'test 2' }
601
+
602
+ repo.add_all
603
+ repo.commit('second commit')
604
+
605
+ File.open(file_name3, 'w') { |f| f.puts 'test 2' }
606
+
607
+ repo.add_all
608
+ repo.commit('third commit')
609
+
610
+ files = [file_name1, file_name2, file_name3].map { |f| File.basename(f) }
611
+
612
+ repo.rev_list(files: files).should have(3).items
613
+ 3.times { |i| repo.rev_list(files: files)[i].should eq repo.log(files: files)[i].commit_hash }
614
+
615
+ files = [file_name1, file_name2].map { |f| File.basename(f) }
616
+
617
+ repo.rev_list(files: files).should have(2).items
618
+ repo.rev_list(files: []).should have(3).items
619
+ repo.rev_list(files: nil).should have(3).items
620
+
621
+ repo.rev_list.should have(3).items
622
+
623
+ files = [file_name1, 'non_exist_file.txt'].map { |f| File.basename(f) }
624
+
625
+ repo.rev_list(files: files).should be_nil
626
+ end
627
+
628
+ it 'Rev List bt author, since, until, grep and files' do
629
+ repo = Repository.new(@file_helper.create_temp_folder)
630
+ repo.init
631
+
632
+ file_name1 = @file_helper.create_temp_file(repo.location, 'test')
633
+ file_name2 = @file_helper.create_temp_file(repo.location, 'test')
634
+
635
+ repo.add_all
636
+ repo.commit('first_commit', author_name: 'author_name', author_email: 'author_name@mail.com')
637
+
638
+ files = [file_name1, file_name2].map { |f| File.basename(f) }
639
+
640
+ repo.rev_list(author: 'author_name', since: yesterday, until: yesterday, grep: 'first_commit', files: files).should have(0).items
641
+ repo.rev_list(author: 'author_name', since: yesterday, until: tomorrow, grep: 'first_commit', files: files).should have(1).items
642
+ end
643
+
336
644
  it 'Show existent branches' do
337
645
  origin = Repository.new(@file_helper.create_temp_folder)
338
646
  origin.init_bare
@@ -663,6 +971,47 @@ describe GitWrapper, '-> Repository' do
663
971
  diff_reverse.select { |d| d.file_name == File.basename(file4) }.first.status.should be(:new_file)
664
972
  end
665
973
 
974
+ it 'Diff tree file status for commits' do
975
+ repo = Repository.new(@file_helper.create_temp_folder)
976
+ repo.init
977
+
978
+ file_name1 = @file_helper.create_temp_file(repo.location, 'test')
979
+ file_name2 = @file_helper.create_temp_file(repo.location, 'test')
980
+
981
+ repo.add_all
982
+ repo.commit('first_commit', author_name: 'another_author', author_email: 'another_author@mail.com')
983
+
984
+ File.open(file_name1, 'w') { |f| f.puts 'test 2' }
985
+ File.open(file_name2, 'w') { |f| f.puts 'test 2' }
986
+
987
+ repo.add_all
988
+ repo.commit('second commit', author_name: 'another_author', author_email: 'another_author@mail.com')
989
+
990
+ File.open(file_name1, 'w') { |f| f.puts 'test 3' }
991
+ File.delete file_name2
992
+ file_name3 = @file_helper.create_temp_file(repo.location, 'test')
993
+
994
+ repo.add_all
995
+ repo.commit('third commit', author_name: 'another_author', author_email: 'another_author@mail.com')
996
+
997
+ log = repo.log(author: 'another_author')
998
+
999
+ diff = repo.diff_tree log[0].commit_hash
1000
+ diff.should have(3).items
1001
+ diff.select { |d| d.file_name == File.basename(file_name1) }.first.status.should be :modified
1002
+ diff.select { |d| d.file_name == File.basename(file_name2) }.first.status.should be :deleted
1003
+ diff.select { |d| d.file_name == File.basename(file_name3) }.first.status.should be :new_file
1004
+
1005
+ diff = repo.diff_tree log[1].commit_hash
1006
+ diff.should have(2).items
1007
+ diff.select { |d| d.file_name == File.basename(file_name1) }.first.status.should be :modified
1008
+ diff.select { |d| d.file_name == File.basename(file_name2) }.first.status.should be :modified
1009
+ diff.select { |d| d.file_name == File.basename(file_name3) }.should be_empty
1010
+
1011
+ diff = repo.diff_tree log[2].commit_hash
1012
+ diff.should have(0).items
1013
+ end
1014
+
666
1015
  it 'Revert a specific commit' do
667
1016
  repo = Repository.new(@file_helper.create_temp_folder)
668
1017
  repo.init
@@ -779,7 +1128,7 @@ describe GitWrapper, '-> Repository' do
779
1128
  repo.status.should have(1).items
780
1129
  repo.status.first.should be_git_new_file(File.basename(file2))
781
1130
 
782
- repo.reset(:mode => :hard).should be_true
1131
+ repo.reset(mode: :hard).should be_true
783
1132
 
784
1133
  File.exist?(file1).should be_true
785
1134
  File.exist?(file2).should be_false
@@ -811,7 +1160,7 @@ describe GitWrapper, '-> Repository' do
811
1160
  repo.log.should have(2).items
812
1161
  repo.log.first.subject.should eq 'second commit'
813
1162
 
814
- repo.reset(:commit => repo.log.last.commit_hash).should be_true
1163
+ repo.reset(commit: repo.log.last.commit_hash).should be_true
815
1164
 
816
1165
  File.exist?(file1).should be_true
817
1166
  File.exist?(file2).should be_true
@@ -850,7 +1199,7 @@ describe GitWrapper, '-> Repository' do
850
1199
  repo.log.should have(2).items
851
1200
  repo.log.first.subject.should eq 'second commit'
852
1201
 
853
- repo.reset(:mode => :hard, :commit => repo.log.last.commit_hash).should be_true
1202
+ repo.reset(mode: :hard, commit: repo.log.last.commit_hash).should be_true
854
1203
 
855
1204
  File.exist?(file1).should be_true
856
1205
  File.exist?(file2).should be_false
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,13 @@
1
+ require 'coverage_helper'
1
2
  require 'git_wrapper'
2
3
 
3
4
  include GitWrapper
4
5
  include GitWrapper::Results
5
6
 
7
+ GitWrapper.logger.level = Logger::Severity::ERROR
8
+
6
9
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
7
10
 
8
11
  RSpec.configure do |config|
9
-
12
+ config.include DateHelper
10
13
  end
@@ -0,0 +1,51 @@
1
+ require 'time'
2
+
3
+ module DateHelper
4
+
5
+ def yesterday
6
+ Time.now - seconds_per_day
7
+ end
8
+
9
+ def tomorrow
10
+ Time.now + seconds_per_day
11
+ end
12
+
13
+ def today
14
+ Time.parse Time.now.strftime("%Y-%m-%d 00:00:00 -0300")
15
+ end
16
+
17
+ def now
18
+ Time.now
19
+ end
20
+
21
+ def next_hour
22
+ Time.now + seconds_per_hour
23
+ end
24
+
25
+ def next_month
26
+ Time.now + seconds_per_month
27
+ end
28
+
29
+ def next_year
30
+ Time.new + seconds_per_year
31
+ end
32
+
33
+ private
34
+
35
+ def seconds_per_hour
36
+ 60 * 60
37
+ end
38
+
39
+ def seconds_per_day
40
+ seconds_per_hour * 24
41
+ end
42
+
43
+ def seconds_per_month
44
+ seconds_per_day * 31
45
+ end
46
+
47
+ def seconds_per_year
48
+ seconds_per_day * 365
49
+ end
50
+
51
+ end
@@ -31,7 +31,7 @@ class FileHelper
31
31
  private
32
32
 
33
33
  def temp_path
34
- Pathname.new("#{File.dirname(__FILE__)}/../../tmp").expand_path.to_s
34
+ Pathname.new("#{File.dirname(__FILE__)}/../../../tmp").expand_path.to_s
35
35
  end
36
36
 
37
37
  def timestamp
@@ -1,12 +1,3 @@
1
- RSpec::Matchers.define :eq_git_status do |expected|
2
- match do |actual|
3
- (expected[:file_name].nil? || actual.file_name == expected[:file_name]) &&
4
- (expected[:original_file_name].nil? || actual.original_file_name == expected[:original_file_name]) &&
5
- (expected[:status].nil? || actual.status == expected[:status]) &&
6
- (expected[:staged_for_commit].nil? || actual.staged_for_commit == expected[:staged_for_commit])
7
- end
8
- end
9
-
10
1
  RSpec::Matchers.define :be_git_untracked do |expected_file_name|
11
2
  match do |actual|
12
3
  actual.file_name == expected_file_name &&
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-18 00:00:00.000000000 Z
12
+ date: 2013-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -27,6 +27,38 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
30
62
  - !ruby/object:Gem::Dependency
31
63
  name: rspec
32
64
  requirement: !ruby/object:Gem::Requirement
@@ -43,6 +75,22 @@ dependencies:
43
75
  - - ! '>='
44
76
  - !ruby/object:Gem::Version
45
77
  version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
46
94
  description: OO git command line wrapper
47
95
  email:
48
96
  - gabynaiman@gmail.com
@@ -50,7 +98,9 @@ executables: []
50
98
  extensions: []
51
99
  extra_rdoc_files: []
52
100
  files:
101
+ - .coveralls.yml
53
102
  - .gitignore
103
+ - .travis.yml
54
104
  - Gemfile
55
105
  - README.md
56
106
  - Rakefile
@@ -62,6 +112,7 @@ files:
62
112
  - lib/git_wrapper/commands/commit.rb
63
113
  - lib/git_wrapper/commands/config.rb
64
114
  - lib/git_wrapper/commands/diff.rb
115
+ - lib/git_wrapper/commands/diff_tree.rb
65
116
  - lib/git_wrapper/commands/fetch.rb
66
117
  - lib/git_wrapper/commands/git.rb
67
118
  - lib/git_wrapper/commands/init.rb
@@ -72,6 +123,7 @@ files:
72
123
  - lib/git_wrapper/commands/remote.rb
73
124
  - lib/git_wrapper/commands/remove.rb
74
125
  - lib/git_wrapper/commands/reset.rb
126
+ - lib/git_wrapper/commands/rev_list.rb
75
127
  - lib/git_wrapper/commands/revert.rb
76
128
  - lib/git_wrapper/commands/shell.rb
77
129
  - lib/git_wrapper/commands/show.rb
@@ -83,9 +135,11 @@ files:
83
135
  - lib/git_wrapper/results/log_info.rb
84
136
  - lib/git_wrapper/results/status_porcelain.rb
85
137
  - lib/git_wrapper/version.rb
138
+ - spec/coverage_helper.rb
86
139
  - spec/repository_spec.rb
87
140
  - spec/spec_helper.rb
88
141
  - spec/status_porcelain_parser_spec.rb
142
+ - spec/support/helpers/date_helper.rb
89
143
  - spec/support/helpers/file_helper.rb
90
144
  - spec/support/matchers/git_status_matchers.rb
91
145
  homepage: https://github.com/gabynaiman/git_wrapper
@@ -113,3 +167,4 @@ signing_key:
113
167
  specification_version: 3
114
168
  summary: OO git command line wrapper
115
169
  test_files: []
170
+ has_rdoc: