Permalink
Browse files

test gitrepo pushing and pulling

  • Loading branch information...
1 parent 9986314 commit 03244ecba187cb20b33b4638a3c135475b64e7be @bronson bronson committed Oct 31, 2011
Showing with 23 additions and 15 deletions.
  1. +8 −14 lib/gitrepo.rb
  2. +15 −1 spec/gitrepo_spec.rb
View
@@ -88,25 +88,19 @@ def commit_all message
}
end
+
def pull *args
- Dir.chdir(@root) do
- retryable(:task => "pulling #{args.join ' '}") do
- # Can we tell the difference between a network error, which we want to retry,
- # and a merge error, which we want to fail immediately?
- output = `git pull --no-rebase #{args.join ' '} 2>&1`
- raise GitError.new("git pull failed: #{output}") unless $?.success?
- end
+ # Can we tell the difference between a network error, which we want to retry,
+ # and a merge error, which we want to fail immediately?
+ retryable(:task => "pulling #{args.join ' '}") do
+ git :pull, '--no-rebase', *args
end
end
- # TODO: how can we differentiate local errors from network errors? We want to retry
- # network errors, we definitely do not want to retry local errors.
def push *args
- Dir.chdir(@root) do
- retryable(:task => "pushing #{args.join ' '}") do
- output = `git push #{args.join ' '} 2>&1`
- raise "generate_docs: git push failed: #{output}" unless $?.success?
- end
+ # like pull, can we tell the difference between a network error and local error?
+ retryable(:task => "pushing #{args.join ' '}") do
+ git :push, *args
end
end
View
@@ -8,7 +8,7 @@
describe 'GitRepo' do
# creates an empty Git repo.
- def with_git_repo args, &block
+ def with_git_repo args={}, &block
stub = lambda { |tmpdir|
options = { :root => "#{tmpdir}/repo", :create => true }
options.merge! args
@@ -42,4 +42,18 @@ def with_git_commit *args
repo.git(:remote).should == ""
end
end
+
+ it "should allow pulling" do
+ with_git_repo do |repo|
+ repo.should_receive(:git).once.with(:pull, '--no-rebase', :origin, :master)
+ repo.pull :origin, :master
+ end
+ end
+
+ it "should allow pushing" do
+ with_git_repo do |repo|
+ repo.should_receive(:git).once.with(:push, :origin, :master)
+ repo.push :origin, :master
+ end
+ end
end

0 comments on commit 03244ec

Please sign in to comment.