minigit 0.0.1 → 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.
@@ -4,7 +4,10 @@ rvm:
4
4
  - 1.8.7
5
5
  - 1.9.2
6
6
  - 1.9.3
7
- # - jruby-18mode # JRuby in 1.8 mode
8
- # - jruby-19mode # JRuby in 1.9 mode
7
+ - 2.0.0
8
+ - ree
9
+ - jruby-18mode
10
+ - jruby-19mode
11
+ - jruby-head
9
12
  - rbx-18mode
10
13
  - rbx-19mode
@@ -1,5 +1,5 @@
1
1
  require 'pathname'
2
- require 'mixlib/shellout'
2
+ require 'shellwords'
3
3
 
4
4
  require "minigit/version"
5
5
 
@@ -29,7 +29,7 @@ class MiniGit
29
29
  class GitError < RuntimeError
30
30
  attr_reader :command, :status, :info
31
31
  def initialize(command, status, info={})
32
- @status = status.dup
32
+ @status = status.dup rescue status.to_s
33
33
  @command = command
34
34
  @info = info
35
35
  super("Failed to run git #{command.join(' ')}: #{@status}")
@@ -47,14 +47,11 @@ class MiniGit
47
47
  path = Pathname.new(where)
48
48
  raise ArgumentError, "#{where} does not seem to exist" unless path.exist?
49
49
  path = path.dirname unless path.directory?
50
- grp = Mixlib::ShellOut.new(
51
- git_command, 'rev-parse', '--git-dir', '--show-toplevel',
52
- :cwd => path.to_s)
53
- grp.run_command
54
- grp.error!
55
- grp.stdout.lines.map { |ln| path.join(Pathname.new(ln.strip)).realpath.to_s }
56
- rescue Mixlib::ShellOut::ShellCommandFailed
57
- raise ArgumentError, "Invalid repository path #{where}; Git said: #{grp.stderr.inspect}"
50
+ Dir.chdir(path.to_s) do
51
+ out = `#{git_command} rev-parse --git-dir --show-toplevel`
52
+ raise ArgumentError, "Invalid repository path #{where}" unless $?.success?
53
+ out
54
+ end.lines.map { |ln| path.join(Pathname.new(ln.strip)).realpath.to_s }
58
55
  end
59
56
 
60
57
  def initialize(where=nil, opts={})
@@ -70,10 +67,11 @@ class MiniGit
70
67
 
71
68
  def git(*args)
72
69
  argv = switches_for(*args)
73
- system(
74
- {'GIT_DIR' => git_dir, 'GIT_WORK_TREE' => git_work_tree},
75
- git_command, *argv)
76
- raise GitError.new(argv, $?) unless $?.success?
70
+ with_git_env do
71
+ rv = system(git_command, *argv)
72
+ raise GitError.new(argv, $?) unless $?.success?
73
+ rv
74
+ end
77
75
  end
78
76
 
79
77
  def method_missing(meth, *args, &block)
@@ -122,30 +120,11 @@ class MiniGit
122
120
  self
123
121
  end
124
122
 
125
- if RUBY_VERSION =~ /^1\.8\./
126
- def system(*args)
127
- return Kernel.system(*args) unless args.first.is_a?(Hash)
128
- begin
129
- env, oenv = args.shift, {}
130
- env.keys.each { |k| oenv[k], ENV[k] = ENV[k], env[k] }
131
- Kernel.system(*args)
132
- ensure
133
- oenv.each { |k,v| if v.nil? then ENV.delete(k) else ENV[k] = v end }
134
- end
135
- end
136
- end
137
-
138
123
  class Capturing < MiniGit
139
- attr_reader :shellout
124
+ attr_reader :process
140
125
 
141
- def git(*args)
142
- argv = switches_for(*args)
143
- argv << { :environment => { 'GIT_DIR' => git_dir, 'GIT_WORK_TREE' => git_work_tree } }
144
- @shellout = Mixlib::ShellOut.new(git_command, *argv)
145
- @shellout.run_command.error!
146
- @shellout.stdout
147
- rescue Mixlib::ShellOut::ShellCommandFailed
148
- raise GitError.new(argv, @shellout.status, :shellout => @shellout)
126
+ def system(*args)
127
+ `#{Shellwords.join(args)}`
149
128
  end
150
129
 
151
130
  def capturing
@@ -158,4 +137,16 @@ class MiniGit
158
137
  :git_work_tree => @git_work_tree)
159
138
  end
160
139
  end
140
+
141
+ private
142
+
143
+ def with_git_env
144
+ dir, work_tree = ENV['GIT_DIR'], ENV['GIT_WORK_TREE']
145
+ ENV['GIT_DIR'] = git_dir
146
+ ENV['GIT_WORK_TREE'] = git_work_tree
147
+ yield
148
+ ensure
149
+ if dir then ENV['GIT_DIR'] = dir else ENV.delete('GIT_DIR') end
150
+ if work_tree then ENV['GIT_WORK_TREE'] = work_tree else ENV.delete('GIT_WORK_TREE') end
151
+ end
161
152
  end
@@ -1,3 +1,3 @@
1
1
  class MiniGit
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -17,8 +17,6 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency 'mixlib-shellout'
21
-
22
20
  gem.add_development_dependency 'wrong', '>= 0.7.0'
23
21
  gem.add_development_dependency 'rake'
24
22
  gem.add_development_dependency 'minitest'
@@ -13,33 +13,39 @@ describe MiniGit do
13
13
  end
14
14
 
15
15
  describe '#find_git_dir' do
16
+ BACKTICK = :` # for broken syntax highlighting: `
16
17
  let(:git) { MiniGit.new }
17
18
 
18
19
  before :each do
19
- Mixlib::ShellOut.any_instance.stubs(:run_command)
20
- Mixlib::ShellOut.any_instance.stubs(:error!)
20
+ MiniGit.stubs(BACKTICK)
21
+ end
22
+
23
+ def rev_parse_returns(*rv)
24
+ git.expects(BACKTICK).
25
+ with('git rev-parse --git-dir --show-toplevel').
26
+ returns( rv.map{|v| "#{v}\n"}.join )
21
27
  end
22
28
 
23
29
  it "Returns a pair of pathnames by running `git rev-parse`" do
24
- Mixlib::ShellOut.any_instance.stubs(:stdout).returns("#{git_dir}\n#{work_tree}\n")
30
+ rev_parse_returns(git_dir, work_tree)
25
31
  assert { git.find_git_dir('.') == [ git_dir.realpath.to_s, work_tree.realpath.to_s ] }
26
32
  end
27
33
 
28
34
  it "returns only a single pathname when only one pathname returned" do
29
- Mixlib::ShellOut.any_instance.stubs(:stdout).returns("#{bare_git_dir}\n")
35
+ rev_parse_returns(bare_git_dir)
30
36
  assert { git.find_git_dir('.') == [ bare_git_dir.realpath.to_s ] }
31
37
  end
32
38
 
33
39
  it 'works fine with relative pathnames' do
34
- Mixlib::ShellOut.any_instance.stubs(:stdout).returns(".git\n")
40
+ rev_parse_returns('.git')
35
41
  assert { git.find_git_dir(work_tree.to_s) == [ git_dir.realpath.to_s ] }
36
42
 
37
- Mixlib::ShellOut.any_instance.stubs(:stdout).returns(".git\n")
43
+ rev_parse_returns('.git')
38
44
  assert { git.find_git_dir(work_tree.relative_path_from(Pathname.getwd).to_s) == [ git_dir.realpath.to_s ] }
39
45
  end
40
46
 
41
47
  it 'works fine when given a file' do
42
- Mixlib::ShellOut.any_instance.stubs(:stdout).returns(".git\n.\n")
48
+ rev_parse_returns('.git', '.')
43
49
  assert { git.find_git_dir(file_in_work_tree.to_s) == [ git_dir.realpath.to_s, work_tree.realpath.to_s ] }
44
50
  end
45
51
 
@@ -48,7 +54,7 @@ describe MiniGit do
48
54
  end
49
55
 
50
56
  it "throws an error when git returns error code" do
51
- Mixlib::ShellOut.any_instance.stubs(:error!).raises(Mixlib::ShellOut::ShellCommandFailed)
57
+ Process::Status.any_instance.expects(:success?).returns(false)
52
58
  assert { ArgumentError === rescuing { git.find_git_dir('.') } }
53
59
  end
54
60
  end
@@ -77,21 +83,35 @@ describe MiniGit do
77
83
  end
78
84
 
79
85
  describe '#git' do
80
- it 'Calls system() with GIT_DIR and GIT_WORK_TREE environment variables set' do
81
- git = MiniGit.new
82
- git.expects(:system).with({'GIT_DIR' => nil, 'GIT_WORK_TREE' => nil}, 'git', 'status')
83
- git.status
84
-
85
- MiniGit.any_instance.expects(:find_git_dir).once.returns( [ bare_git_dir.realpath.to_s ] )
86
- git = MiniGit.new('.')
87
- git.expects(:system).with({'GIT_DIR' => bare_git_dir.realpath.to_s, 'GIT_WORK_TREE' => nil}, 'git', 'status')
88
- git.status
89
-
90
- MiniGit.any_instance.expects(:find_git_dir).once.returns( [ git_dir.realpath.to_s, work_tree.realpath.to_s ] )
91
- git = MiniGit.new('.')
92
- git.expects(:system).with({'GIT_DIR' => git_dir.realpath.to_s, 'GIT_WORK_TREE' => work_tree.realpath.to_s}, 'git', 'status')
93
- git.status
86
+ class MiniGitEnvPeek < MiniGit
87
+ def system(*args)
88
+ Hash[ENV]
89
+ end
90
+ end
94
91
 
92
+ it 'Calls system() with GIT_DIR and GIT_WORK_TREE environment variables set' do
93
+ assert { ENV['GIT_DIR'].nil? }
94
+ assert { ENV['GIT_WORK_TREE'].nil? }
95
+
96
+ MiniGitEnvPeek.any_instance.expects(:find_git_dir).once.returns( [ git_dir.realpath.to_s, work_tree.realpath.to_s ] )
97
+ git = MiniGitEnvPeek.new('.')
98
+ env = git.status
99
+ assert { env['GIT_DIR'] == git_dir.realpath.to_s }
100
+ assert { env['GIT_WORK_TREE'] == work_tree.realpath.to_s }
101
+
102
+ MiniGitEnvPeek.any_instance.expects(:find_git_dir).once.returns( [ bare_git_dir.realpath.to_s ] )
103
+ git = MiniGitEnvPeek.new('.')
104
+ env = git.status
105
+ assert { env['GIT_DIR'] == bare_git_dir.realpath.to_s }
106
+ assert { env['GIT_WORK_TREE'].nil? }
107
+
108
+ git = MiniGitEnvPeek.new
109
+ env = git.status
110
+ assert { env['GIT_DIR'].nil? }
111
+ assert { env['GIT_WORK_TREE'].nil? }
112
+
113
+ assert { ENV['GIT_DIR'].nil? }
114
+ assert { ENV['GIT_WORK_TREE'].nil? }
95
115
  end
96
116
  end
97
117
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe MiniGit do
4
- GIT_ENV = { 'GIT_DIR' => nil, 'GIT_WORK_TREE' => nil }
5
4
  let(:git) { MiniGit.new }
6
5
 
7
6
  describe '#git_command' do
@@ -15,7 +14,7 @@ describe MiniGit do
15
14
  end
16
15
 
17
16
  it 'specifies how git is run' do
18
- git.expects(:system).with(GIT_ENV, 'other', 'whatever', '--foo=bar')
17
+ git.expects(:system).with('other', 'whatever', '--foo=bar')
19
18
  git.git_command = 'other'
20
19
  git.whatever :foo => 'bar'
21
20
  end
@@ -62,10 +61,10 @@ describe MiniGit do
62
61
 
63
62
  describe '#git' do
64
63
  it 'calls git with given options' do
65
- git.expects(:system).with(GIT_ENV, 'git', 'status')
64
+ git.expects(:system).with('git', 'status')
66
65
  git.git(:status)
67
66
 
68
- git.expects(:system).with(GIT_ENV, 'git', 'log', '--oneline').once
67
+ git.expects(:system).with('git', 'log', '--oneline').once
69
68
  git.git(:log, :oneline => true)
70
69
  end
71
70
 
@@ -127,14 +126,14 @@ describe MiniGit do
127
126
 
128
127
  describe '.method_missing' do
129
128
  it 'calls out to a hidden instance of self' do
130
- MiniGit.any_instance.expects(:system).with(GIT_ENV, 'git', 'status')
129
+ MiniGit.any_instance.expects(:system).with('git', 'status')
131
130
  MiniGit.status
132
131
  end
133
132
  end
134
133
 
135
134
  describe '.git' do
136
135
  it 'also calls out to a hidden instance of self' do
137
- MiniGit.any_instance.expects(:system).with(GIT_ENV, 'git', 'status')
136
+ MiniGit.any_instance.expects(:system).with('git', 'status')
138
137
  MiniGit.git :status
139
138
  end
140
139
  end
@@ -6,7 +6,10 @@ require 'fileutils'
6
6
  require 'pathname'
7
7
 
8
8
  require 'simplecov'
9
- SimpleCov.start
9
+ SimpleCov.start do
10
+ command_name 'MiniTest::Spec'
11
+ minimum_coverage 95
12
+ end
10
13
 
11
14
  require 'minitest/spec'
12
15
  require 'minitest/autorun'
metadata CHANGED
@@ -1,112 +1,104 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minigit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ prerelease:
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Maciej Pasternacki
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-11 00:00:00.000000000 Z
12
+ date: 2013-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: mixlib-shellout
16
- requirement: !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: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
14
  - !ruby/object:Gem::Dependency
31
15
  name: wrong
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
16
+ version_requirements: !ruby/object:Gem::Requirement
34
17
  requirements:
35
- - - ! '>='
18
+ - - ">="
36
19
  - !ruby/object:Gem::Version
37
20
  version: 0.7.0
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
21
  none: false
22
+ requirement: !ruby/object:Gem::Requirement
42
23
  requirements:
43
- - - ! '>='
24
+ - - ">="
44
25
  - !ruby/object:Gem::Version
45
26
  version: 0.7.0
27
+ none: false
28
+ prerelease: false
29
+ type: :development
46
30
  - !ruby/object:Gem::Dependency
47
31
  name: rake
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
32
+ version_requirements: !ruby/object:Gem::Requirement
50
33
  requirements:
51
- - - ! '>='
34
+ - - ">="
52
35
  - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
36
+ version: !binary |-
37
+ MA==
57
38
  none: false
39
+ requirement: !ruby/object:Gem::Requirement
58
40
  requirements:
59
- - - ! '>='
41
+ - - ">="
60
42
  - !ruby/object:Gem::Version
61
- version: '0'
43
+ version: !binary |-
44
+ MA==
45
+ none: false
46
+ prerelease: false
47
+ type: :development
62
48
  - !ruby/object:Gem::Dependency
63
49
  name: minitest
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
50
+ version_requirements: !ruby/object:Gem::Requirement
66
51
  requirements:
67
- - - ! '>='
52
+ - - ">="
68
53
  - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
54
+ version: !binary |-
55
+ MA==
73
56
  none: false
57
+ requirement: !ruby/object:Gem::Requirement
74
58
  requirements:
75
- - - ! '>='
59
+ - - ">="
76
60
  - !ruby/object:Gem::Version
77
- version: '0'
61
+ version: !binary |-
62
+ MA==
63
+ none: false
64
+ prerelease: false
65
+ type: :development
78
66
  - !ruby/object:Gem::Dependency
79
67
  name: mocha
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
68
+ version_requirements: !ruby/object:Gem::Requirement
82
69
  requirements:
83
- - - ! '>='
70
+ - - ">="
84
71
  - !ruby/object:Gem::Version
85
- version: '0'
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
72
+ version: !binary |-
73
+ MA==
89
74
  none: false
75
+ requirement: !ruby/object:Gem::Requirement
90
76
  requirements:
91
- - - ! '>='
77
+ - - ">="
92
78
  - !ruby/object:Gem::Version
93
- version: '0'
79
+ version: !binary |-
80
+ MA==
81
+ none: false
82
+ prerelease: false
83
+ type: :development
94
84
  - !ruby/object:Gem::Dependency
95
85
  name: simplecov
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
86
+ version_requirements: !ruby/object:Gem::Requirement
98
87
  requirements:
99
- - - ! '>='
88
+ - - ">="
100
89
  - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
90
+ version: !binary |-
91
+ MA==
105
92
  none: false
93
+ requirement: !ruby/object:Gem::Requirement
106
94
  requirements:
107
- - - ! '>='
95
+ - - ">="
108
96
  - !ruby/object:Gem::Version
109
- version: '0'
97
+ version: !binary |-
98
+ MA==
99
+ none: false
100
+ prerelease: false
101
+ type: :development
110
102
  description: A simple Ruby interface for Git
111
103
  email:
112
104
  - maciej@pasternacki.net
@@ -114,8 +106,8 @@ executables: []
114
106
  extensions: []
115
107
  extra_rdoc_files: []
116
108
  files:
117
- - .gitignore
118
- - .travis.yml
109
+ - ".gitignore"
110
+ - ".travis.yml"
119
111
  - Gemfile
120
112
  - LICENSE.txt
121
113
  - README.md
@@ -131,32 +123,34 @@ files:
131
123
  - spec/spec_helper.rb~
132
124
  homepage: https://github.com/3ofcoins/minigit
133
125
  licenses: []
134
- post_install_message:
126
+ post_install_message:
135
127
  rdoc_options: []
136
128
  require_paths:
137
129
  - lib
138
130
  required_ruby_version: !ruby/object:Gem::Requirement
139
- none: false
140
131
  requirements:
141
- - - ! '>='
132
+ - - ">="
142
133
  - !ruby/object:Gem::Version
143
- version: '0'
144
134
  segments:
145
135
  - 0
146
- hash: 1654588845628700009
147
- required_rubygems_version: !ruby/object:Gem::Requirement
136
+ hash: 2
137
+ version: !binary |-
138
+ MA==
148
139
  none: false
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
141
  requirements:
150
- - - ! '>='
142
+ - - ">="
151
143
  - !ruby/object:Gem::Version
152
- version: '0'
153
144
  segments:
154
145
  - 0
155
- hash: 1654588845628700009
146
+ hash: 2
147
+ version: !binary |-
148
+ MA==
149
+ none: false
156
150
  requirements: []
157
- rubyforge_project:
158
- rubygems_version: 1.8.25
159
- signing_key:
151
+ rubyforge_project:
152
+ rubygems_version: 1.8.24
153
+ signing_key:
160
154
  specification_version: 3
161
155
  summary: A simple Ruby interface for Git
162
156
  test_files: