Skip to content

Commit

Permalink
Merge branch 'release/0.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
mpasternacki committed Jul 18, 2013
2 parents e974fdc + 77827ab commit 7e98d8e
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 36 deletions.
28 changes: 18 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
---
language: ruby
bundler_args: --without development_workstation
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- 2.0.0
- ree
- jruby-18mode
- jruby-19mode
- jruby-head
- rbx-18mode
- rbx-19mode
- 1.8.7
- 1.9.2
- 1.9.3
- 2.0.0
- ree
- jruby-18mode
- jruby-19mode
- jruby-head
- rbx-18mode
- rbx-19mode
notifications:
hipchat:
secure: ! 'bGTLLC9qlBlOktqm1uuOmh1CkBASBxVzeTZrN45goL570X/uNnLXY54tly65
P2KaBzbWvUmBm2sy3sVIv0bOGP04eOP5nl/lvmRrr6GdonErhUqWDklFZBM3
29W4yd8Tr+1rHhCnwSGbhEDN9Q8UGVN+58rTPrwCFXBeidLBtjQ='
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Changes
=======

0.0.4
-----

- Hash-like access to `git config` (Marta Paciorkowska)
- Documentation fixes
- (internal) use Minitest 5

0.0.3
-----

- Debug mode (`MiniGit.debug`)

0.0.2
-----

- JRuby support
- (internal) Refactoring

0.0.1
-----

- Initial release
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# How to contribute
Thank you for wanting to contribute! These are just a few guidelines that we'd like contributors to follow.

## Making changes

* Fork the repo.
* Create a branch from the develop branch and name it 'feature/name-of-feature': `git checkout -b feature/my-new-feature` (We follow [this branching model] (http://nvie.com/posts/a-successful-git-branching-model/))
* Make sure you test your new feature.
* Commit your changes together with specs for them: `git commit -am 'Add some feature'`

## Submitting changes

* Push your changes to your feature branch.
* Submit a pull request to the develop repository. Describe your feature in the pull request. Make sure you commit the specs.
* A pull request does not necessarily need to represent the final, finished feature. Feel free to treat it as a base for discussion.

### Thank you for contributing!
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ gemspec

# Optional development environment
group :development_workstation do
gem "pry-stack_explorer", :require => false
gem "pry", :require => false
gem "minitest-ansi"
end
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ git.capturing.branch # => "* master\n"

```ruby
cgit = MiniGit::Capturing.new
git.branch # => "* master\n"
git.noncapturing.branch # => nil (output shown to the terminal)
cgit.branch # => "* master\n"
cgit.noncapturing.branch # => nil (output shown to the terminal)
```

You can also provide a path specifying the Git repo. It can be:

* a working directory
* a file in or subdirectory of a working directory
* a bare repository
* a `.git` directory (which will be trated as a bare repository)
* a `.git` directory (which will be treated as a bare repository)

MiniGit will find the Git directory and work tree automagically by
calling out to `git rev-parse --git-dir --show-toplevel`, will set
Expand All @@ -113,6 +113,22 @@ MiniGit.new('../vendorificator').log :n => 1, :oneline => true
MiniGit.new('../vendorificator').capturing.log :n => 1, :oneline => true
# => "b485d32 Merge branch 'release/0.1.1' into develop\n"
```
### Git config hash-like access

You can call, modify and create new git config attributes with simple hash-like syntax:

```ruby
git = MiniGit.new
git['user.email'] # => returns the user email assigned to the repository
git['user.email'] = 'foo@bar' # changes the user.email to foo@bar
```

The same works on the class itself:

```ruby
MiniGit['user.email'] # => "foo@bar"
MiniGit['user.email'] = 'foo@bar' # changes the user.email to foo@bar
```

### Git command

Expand Down Expand Up @@ -185,9 +201,4 @@ ENV['GIT_PAGER'] = ''

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`), together
with specs for them
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
See CONTRIBUTING.md
40 changes: 33 additions & 7 deletions lib/minigit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def git(*args)
_myself.git(*args)
end

def [](arg)
_myself[arg]
end

def []=(key, value)
_myself[key] = value
end

protected

def _myself
Expand All @@ -29,7 +37,7 @@ def _myself

class GitError < RuntimeError
attr_reader :command, :status, :info
def initialize(command, status, info={})
def initialize(command=[], status=nil, info={})
@status = status.dup rescue status.to_s
@command = command
@info = info
Expand Down Expand Up @@ -114,9 +122,10 @@ def switches_for(*args)
end

def capturing
@capturing ||= Capturing.new(:git_command => @git_command,
:git_dir => @git_dir,
:git_work_tree => @git_work_tree)
@capturing ||= Capturing.new(
:git_command => @git_command,
:git_dir => @git_dir,
:git_work_tree => @git_work_tree)
end

def noncapturing
Expand All @@ -135,12 +144,29 @@ def capturing
end

def noncapturing
@noncapturing ||= MiniGit.new(:git_command => @git_command,
:git_dir => @git_dir,
:git_work_tree => @git_work_tree)
@noncapturing ||= MiniGit.new(
:git_command => @git_command,
:git_dir => @git_dir,
:git_work_tree => @git_work_tree)
end
end

def [](arg)
begin
self.capturing.config(arg).strip
rescue MiniGit::GitError
nil
end
end

def []=(key, value)
begin
self.noncapturing.config(key, value)
rescue MiniGit::GitError
nil
end
end

private

def with_git_env
Expand Down
2 changes: 1 addition & 1 deletion lib/minigit/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class MiniGit
VERSION = "0.0.3"
VERSION = "0.0.4"
end
2 changes: 1 addition & 1 deletion minigit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |gem|

gem.add_development_dependency 'wrong', '>= 0.7.0'
gem.add_development_dependency 'rake'
gem.add_development_dependency 'minitest'
gem.add_development_dependency 'minitest', '~> 5.0.0'
gem.add_development_dependency 'mocha'
gem.add_development_dependency 'simplecov'
end
57 changes: 57 additions & 0 deletions spec/minigit_hash_access_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require 'spec_helper'

describe MiniGit do
let(:git) { MiniGit::new }

describe '#[]' do
it 'returns nil if the passed in attribute has no value' do
MiniGit::Capturing.any_instance.
expects(:system).with('git', 'config', 'foo.bar').
at_least_once.
raises(MiniGit::GitError)
assert { git['foo.bar'] == nil }
end

it 'returns a stripped configuration value if it exists' do
MiniGit::Capturing.any_instance.
expects(:system).with('git', 'config', 'foo.baz').
at_least_once.
returns("whatever\n")
assert { git['foo.baz'] == "whatever" }
end
end

describe '.[]' do
it 'returns nil if the passed in attribute has no value for class instance' do
MiniGit::Capturing.any_instance.
expects(:system).with('git', 'config', 'foo.bar').
at_least_once.
raises(MiniGit::GitError)
assert { MiniGit['foo.bar'] == nil }
end

it 'returns a stripped configuration value if it exists for class instance' do
MiniGit::Capturing.any_instance.
expects(:system).with('git', 'config', 'foo.baz').
at_least_once.
returns("whatever\n")
assert { MiniGit['foo.baz'] == "whatever" }
end
end

describe '#[]=' do
it 'assigns value to a git config attribute' do
MiniGit.any_instance.
expects(:system).with('git', 'config', 'bar.baz', 'foo')
git['bar.baz'] = 'foo'
end
end

describe '.[]=' do
it 'assigns value to a git config attribute for class instance' do
MiniGit.any_instance.
expects(:system).with('git', 'config', 'bar.baz', 'foo')
MiniGit['bar.baz'] = 'foo'
end
end
end
1 change: 1 addition & 0 deletions spec/minigit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
it 'raises an error if command fails' do
git.git_command = 'false'
assert { MiniGit::GitError === rescuing { git.git(:wrong) } }
system 'true' # to reset $? to a clean value
end
end

Expand Down
21 changes: 14 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@
minimum_coverage 95
end

require 'minitest/spec'
require 'minitest/autorun'
require 'minitest/spec'
require 'mocha/setup'
require 'wrong'
require 'wrong/adapters/minitest'

begin
require 'minitest/ansi'
rescue LoadError # that's fine, we'll live without it
else
MiniTest::ANSI.use! if STDOUT.tty?
class MiniGit
module Spec
module WrongHelper
include Wrong::Assert
include Wrong::Helpers

def increment_assertion_count
self.assertions += 1
end
end
end
end

require 'minigit'
Expand All @@ -34,6 +39,8 @@ def self.to_ary ; to_a ; end
end

class MiniTest::Spec
include MiniGit::Spec::WrongHelper

attr_reader :tmp_path
before do
@tmp_path = Pathname.new(__FILE__).dirname.dirname.join('tmp').expand_path
Expand Down

0 comments on commit 7e98d8e

Please sign in to comment.