Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add general purpose git call to gitrepo

  • Loading branch information...
commit 998631409039dd2d132bf10a2f75627295f39414 1 parent 7a6416a
@bronson bronson authored
Showing with 26 additions and 1 deletion.
  1. +22 −0 lib/gitrepo.rb
  2. +4 −1 spec/gitrepo_spec.rb
View
22 lib/gitrepo.rb
@@ -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) {
View
5 spec/gitrepo_spec.rb
@@ -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.
Something went wrong with that request. Please try again.