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

Commit 59c2a01

Browse files
committed
Make sure grit restores old timeout value even if exception occured
Signed-off-by: Dmitriy Zaporozhets <[email protected]>
1 parent 4a1ccd0 commit 59c2a01

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/grit/git.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,13 @@ def git_binary
9090

9191
def self.with_timeout(timeout = 10)
9292
old_timeout = Grit::Git.git_timeout
93-
Grit::Git.git_timeout = timeout
94-
yield
95-
Grit::Git.git_timeout = old_timeout
93+
94+
begin
95+
Grit::Git.git_timeout = timeout
96+
yield
97+
ensure
98+
Grit::Git.git_timeout = old_timeout
99+
end
96100
end
97101

98102
attr_accessor :git_dir, :bytes_read, :work_tree

test/test_git.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ def test_uses_native_command_execution
4343
@git.something
4444
end
4545

46+
def test_with_timeout_restored
47+
begin
48+
Grit::Git.with_timeout(4) do
49+
raise 'wow'
50+
end
51+
rescue
52+
nil
53+
end
54+
55+
assert_equal Grit::Git.git_timeout, 5
56+
end
57+
4658
def test_can_skip_timeout
4759
Timeout.expects(:timeout).never
4860
@git.something(:timeout => false)

0 commit comments

Comments
 (0)