Skip to content
This repository has been archived by the owner on Apr 19, 2018. It is now read-only.

Commit

Permalink
Make sure grit restores old timeout value even if exception occured
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
  • Loading branch information
dzaporozhets committed Oct 9, 2014
1 parent 4a1ccd0 commit 59c2a01
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/grit/git.rb
Expand Up @@ -90,9 +90,13 @@ def git_binary

def self.with_timeout(timeout = 10)
old_timeout = Grit::Git.git_timeout
Grit::Git.git_timeout = timeout
yield
Grit::Git.git_timeout = old_timeout

begin
Grit::Git.git_timeout = timeout
yield
ensure
Grit::Git.git_timeout = old_timeout
end
end

attr_accessor :git_dir, :bytes_read, :work_tree
Expand Down
12 changes: 12 additions & 0 deletions test/test_git.rb
Expand Up @@ -43,6 +43,18 @@ def test_uses_native_command_execution
@git.something
end

def test_with_timeout_restored
begin
Grit::Git.with_timeout(4) do
raise 'wow'
end
rescue
nil
end

assert_equal Grit::Git.git_timeout, 5
end

def test_can_skip_timeout
Timeout.expects(:timeout).never
@git.something(:timeout => false)
Expand Down

0 comments on commit 59c2a01

Please sign in to comment.