git_wrapper 1.0.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.
Files changed (39) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +4 -0
  3. data/README.md +74 -0
  4. data/Rakefile +1 -0
  5. data/git_wrapper.gemspec +21 -0
  6. data/lib/git_wrapper/commands/add.rb +21 -0
  7. data/lib/git_wrapper/commands/branch.rb +73 -0
  8. data/lib/git_wrapper/commands/checkout.rb +21 -0
  9. data/lib/git_wrapper/commands/commit.rb +21 -0
  10. data/lib/git_wrapper/commands/config.rb +26 -0
  11. data/lib/git_wrapper/commands/diff.rb +27 -0
  12. data/lib/git_wrapper/commands/fetch.rb +21 -0
  13. data/lib/git_wrapper/commands/git.rb +44 -0
  14. data/lib/git_wrapper/commands/init.rb +16 -0
  15. data/lib/git_wrapper/commands/log.rb +82 -0
  16. data/lib/git_wrapper/commands/merge.rb +16 -0
  17. data/lib/git_wrapper/commands/pull.rb +21 -0
  18. data/lib/git_wrapper/commands/push.rb +27 -0
  19. data/lib/git_wrapper/commands/remote.rb +49 -0
  20. data/lib/git_wrapper/commands/remove.rb +16 -0
  21. data/lib/git_wrapper/commands/reset.rb +36 -0
  22. data/lib/git_wrapper/commands/revert.rb +23 -0
  23. data/lib/git_wrapper/commands/shell.rb +67 -0
  24. data/lib/git_wrapper/commands/show.rb +40 -0
  25. data/lib/git_wrapper/commands/status.rb +17 -0
  26. data/lib/git_wrapper/commands/tag.rb +54 -0
  27. data/lib/git_wrapper/repository.rb +208 -0
  28. data/lib/git_wrapper/results/diff_name_status.rb +28 -0
  29. data/lib/git_wrapper/results/file_status.rb +21 -0
  30. data/lib/git_wrapper/results/log_info.rb +23 -0
  31. data/lib/git_wrapper/results/status_porcelain.rb +40 -0
  32. data/lib/git_wrapper/version.rb +3 -0
  33. data/lib/git_wrapper.rb +45 -0
  34. data/spec/repository_spec.rb +886 -0
  35. data/spec/spec_helper.rb +10 -0
  36. data/spec/status_porcelain_parser_spec.rb +78 -0
  37. data/spec/support/helpers/file_helper.rb +37 -0
  38. data/spec/support/matchers/git_status_matchers.rb +40 -0
  39. metadata +105 -0
@@ -0,0 +1,10 @@
1
+ require 'git_wrapper'
2
+
3
+ include GitWrapper
4
+ include GitWrapper::Results
5
+
6
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
7
+
8
+ RSpec.configure do |config|
9
+
10
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitWrapper, '-> Status porcelain parser' do
4
+
5
+ it 'Untracked file' do
6
+ text = '?? file.txt'
7
+ file_status = StatusPorcelain.parse(text)
8
+
9
+ file_status.file_name.should eq('file.txt')
10
+ file_status.status.should be(:untracked)
11
+ file_status.staged_for_commit.should be_false
12
+ end
13
+
14
+ it 'New file' do
15
+ text = 'A file.txt'
16
+ file_status = StatusPorcelain.parse(text)
17
+
18
+ file_status.file_name.should eq('file.txt')
19
+ file_status.status.should be(:new_file)
20
+ file_status.staged_for_commit.should be_true
21
+ end
22
+
23
+ it 'Modified' do
24
+ text = ' M file.txt'
25
+ file_status = StatusPorcelain.parse(text)
26
+
27
+ file_status.file_name.should eq('file.txt')
28
+ file_status.status.should be(:modified)
29
+ file_status.staged_for_commit.should be_false
30
+ end
31
+
32
+ it 'Modified and staged for commit' do
33
+ text = 'M file.txt'
34
+ file_status = StatusPorcelain.parse(text)
35
+
36
+ file_status.file_name.should eq('file.txt')
37
+ file_status.status.should be(:modified)
38
+ file_status.staged_for_commit.should be_true
39
+ end
40
+
41
+ it 'Deleted' do
42
+ text = ' D file.txt'
43
+ file_status = StatusPorcelain.parse(text)
44
+
45
+ file_status.file_name.should eq('file.txt')
46
+ file_status.status.should be(:deleted)
47
+ file_status.staged_for_commit.should be_false
48
+ end
49
+
50
+ it 'Deleted and staged for commit' do
51
+ text = 'D file.txt'
52
+ file_status = StatusPorcelain.parse(text)
53
+
54
+ file_status.file_name.should eq('file.txt')
55
+ file_status.status.should be(:deleted)
56
+ file_status.staged_for_commit.should be_true
57
+ end
58
+
59
+ it 'Merge conflict' do
60
+ text = 'UU file.txt'
61
+ file_status = StatusPorcelain.parse(text)
62
+
63
+ file_status.file_name.should eq('file.txt')
64
+ file_status.status.should be(:merge_conflict)
65
+ file_status.staged_for_commit.should be_false
66
+ end
67
+
68
+ it 'Renamed' do
69
+ text = 'R file.txt -> new_file.txt'
70
+ file_status = StatusPorcelain.parse(text)
71
+
72
+ file_status.file_name.should eq('new_file.txt')
73
+ file_status.original_file_name.should eq('file.txt')
74
+ file_status.status.should be(:renamed)
75
+ file_status.staged_for_commit.should be_true
76
+ end
77
+
78
+ end
@@ -0,0 +1,37 @@
1
+ require 'fileutils'
2
+
3
+ class FileHelper
4
+
5
+ def initialize
6
+ @temp_folders = []
7
+ end
8
+
9
+ def create_temp_folder
10
+ folder_name = "#{ENV['TMP'].gsub('\\', '/')}/#{timestamp}"
11
+ @temp_folders << folder_name
12
+ Dir.mkdir folder_name
13
+ folder_name
14
+ end
15
+
16
+ def remove_temp_folders
17
+ @temp_folders.each do |folder_name|
18
+ FileUtils.rm_rf folder_name
19
+ end
20
+ end
21
+
22
+ def create_temp_file(folder, content)
23
+ file_name = "#{folder}/file #{timestamp}.txt"
24
+ sleep(0.01)
25
+ File.open(file_name, 'w') do |file|
26
+ file.puts content
27
+ end
28
+ file_name
29
+ end
30
+
31
+ private
32
+
33
+ def timestamp
34
+ (Time.now.to_f * 1000).to_i
35
+ end
36
+
37
+ end
@@ -0,0 +1,40 @@
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
+ RSpec::Matchers.define :be_git_untracked do |expected_file_name|
11
+ match do |actual|
12
+ actual.file_name == expected_file_name &&
13
+ actual.status == :untracked &&
14
+ !actual.staged_for_commit
15
+ end
16
+ end
17
+
18
+ RSpec::Matchers.define :be_git_new_file do |expected_file_name|
19
+ match do |actual|
20
+ actual.file_name == expected_file_name &&
21
+ actual.status == :new_file &&
22
+ actual.staged_for_commit
23
+ end
24
+ end
25
+
26
+ RSpec::Matchers.define :be_git_deleted do |expected_file_name|
27
+ match do |actual|
28
+ actual.file_name == expected_file_name &&
29
+ actual.status == :deleted &&
30
+ actual.staged_for_commit
31
+ end
32
+ end
33
+
34
+ RSpec::Matchers.define :be_git_merge_conflict do |expected_file_name|
35
+ match do |actual|
36
+ actual.file_name == expected_file_name &&
37
+ actual.status == :merge_conflict &&
38
+ !actual.staged_for_commit
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gabriel Naiman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: &26131704 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *26131704
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &26109240 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *26109240
36
+ description: OO git command line wrapper
37
+ email:
38
+ - gabynaiman@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - README.md
46
+ - Rakefile
47
+ - git_wrapper.gemspec
48
+ - lib/git_wrapper.rb
49
+ - lib/git_wrapper/commands/add.rb
50
+ - lib/git_wrapper/commands/branch.rb
51
+ - lib/git_wrapper/commands/checkout.rb
52
+ - lib/git_wrapper/commands/commit.rb
53
+ - lib/git_wrapper/commands/config.rb
54
+ - lib/git_wrapper/commands/diff.rb
55
+ - lib/git_wrapper/commands/fetch.rb
56
+ - lib/git_wrapper/commands/git.rb
57
+ - lib/git_wrapper/commands/init.rb
58
+ - lib/git_wrapper/commands/log.rb
59
+ - lib/git_wrapper/commands/merge.rb
60
+ - lib/git_wrapper/commands/pull.rb
61
+ - lib/git_wrapper/commands/push.rb
62
+ - lib/git_wrapper/commands/remote.rb
63
+ - lib/git_wrapper/commands/remove.rb
64
+ - lib/git_wrapper/commands/reset.rb
65
+ - lib/git_wrapper/commands/revert.rb
66
+ - lib/git_wrapper/commands/shell.rb
67
+ - lib/git_wrapper/commands/show.rb
68
+ - lib/git_wrapper/commands/status.rb
69
+ - lib/git_wrapper/commands/tag.rb
70
+ - lib/git_wrapper/repository.rb
71
+ - lib/git_wrapper/results/diff_name_status.rb
72
+ - lib/git_wrapper/results/file_status.rb
73
+ - lib/git_wrapper/results/log_info.rb
74
+ - lib/git_wrapper/results/status_porcelain.rb
75
+ - lib/git_wrapper/version.rb
76
+ - spec/repository_spec.rb
77
+ - spec/spec_helper.rb
78
+ - spec/status_porcelain_parser_spec.rb
79
+ - spec/support/helpers/file_helper.rb
80
+ - spec/support/matchers/git_status_matchers.rb
81
+ homepage: https://github.com/gabynaiman/git_wrapper
82
+ licenses: []
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.16
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: OO git command line wrapper
105
+ test_files: []