Skip to content

Commit

Permalink
add general purpose git call to gitrepo
Browse files Browse the repository at this point in the history
  • Loading branch information
bronson committed Oct 31, 2011
1 parent 7a6416a commit 9986314
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
22 changes: 22 additions & 0 deletions lib/gitrepo.rb
Expand Up @@ -39,6 +39,28 @@ def root
@root
end

def git *args
args = args.map { |a| a.to_s }
Dir.chdir(@root) do
out = IO.popen('-', 'r') do |io|
if io
# parent, read the git output
block_given? ? yield(io) : io.read
else
STDERR.reopen STDOUT
exec 'git', *args
end
end

if $?.exitstatus > 0
# return '' if $?.exitstatus == 1 && out == ''
raise GitError.new("git #{args.join(' ')}: #{out}")
end

out
end
end

# i.e. remote_add 'rails', 'http://github.com/rails/rails.git'
def remote_add name, remote
Dir.chdir(@root) {
Expand Down
5 changes: 4 additions & 1 deletion spec/gitrepo_spec.rb
Expand Up @@ -36,7 +36,10 @@ def with_git_commit *args

it "should allow remotes to be added and removed" do
with_git_commit(:bare => true) do |repo|

repo.remote_add :origin, 'http://example.com/'
repo.git(:remote).should == "origin\n"
repo.remote_remove :origin
repo.git(:remote).should == ""
end
end
end

0 comments on commit 9986314

Please sign in to comment.