Skip to content

Commit

Permalink
Catch GIT errors more gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitrij Denissenko committed Oct 11, 2009
1 parent 6c8d1e0 commit 34833a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 13 additions & 6 deletions vendor/plugins/tiny-git/lib/tiny_git/commands.rb
Expand Up @@ -50,12 +50,8 @@ def run_command(call)
seconds = Benchmark.realtime do
out = `#{call} 2>&1`
end

if $? && $?.exitstatus > 0
return '' if $?.exitstatus == 1 && out == ''
raise TinyGit::GitExecuteError.new(call + ':' + out.to_s)
end

raise_execution_error(call, out) unless success?($?, out)

@logger.debug " TinyGit (#{sprintf("%.1f", seconds * 1000)}ms) #{call}" if @logger
out
end
Expand All @@ -81,5 +77,16 @@ def escape(s)
"'" + s.to_s.gsub('\'', '\'\\\'\'') + "'"
end

def raise_execution_error(call, out)
raise TinyGit::GitExecuteError.new("#{out.strip} (#{call})")
end

def success?(status, out)
return true unless status.is_a?(Process::Status)

s = status.exitstatus.to_i
s.zero? or ( s == 1 and out.blank? )
end

end
end
4 changes: 4 additions & 0 deletions vendor/plugins/tiny-git/spec/repo_spec.rb
Expand Up @@ -51,6 +51,10 @@ def new_repo(path = 'test_rep')
new_repo.cat_file('commit', 'ae62392').size.should == 320
new_repo.cat_file('commit', 'ae62392').should =~ /\n{1}\Z/m
end

it 'should catch and re-raise GIT errors' do
lambda { new_repo.cat_file('9999999', :s => true) }.should raise_error(TinyGit::GitExecuteError)
end

end

0 comments on commit 34833a6

Please sign in to comment.