Skip to content

Commit

Permalink
As described in 417592f git outputs to both STDERR and STDOUT in norm…
Browse files Browse the repository at this point in the history
…al use so we can't use the presence of STDERR output as indication that an error has occurred.

Instead, just log all output with a more verbose log level.
  • Loading branch information
koppen committed Mar 10, 2010
1 parent 417592f commit c41e85b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
10 changes: 3 additions & 7 deletions app/controllers/github_hook_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@ def exec(command)
output = stdout.readlines.collect(&:strip)
errors = stderr.readlines.collect(&:strip)

unless errors.empty?
error_message = []
error_message << "Error occurred running git"
error_message += errors
error_message += output
logger.error error_message
end
logger.debug { "GithubHook: Output from git:" }
logger.debug { "GithubHook: * STDOUT: #{output}"}
logger.debug { "GithubHook: * STDERR: #{output}"}
end

end
12 changes: 2 additions & 10 deletions test/functional/github_hook_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,13 @@ def test_should_not_require_login
do_post
end

def test_exec_should_log_errors_from_git
def test_exec_should_log_output_from_git_as_debug
stdout = mock_descriptor('STDOUT', ["output 1\n", "output 2\n"])
stderr = mock_descriptor('STDERR', ["error 1\n", "error 2\n"])
Open3.expects(:popen3).returns(['STDIN', stdout, stderr])

@controller.logger.expects(:error).with(['Error occurred running git', 'error 1', 'error 2', 'output 1', 'output 2'])
@controller.logger.expects(:debug).at_least(4)
do_post
end

def test_exec_should_not_log_errors_if_none_occurred
stdout = mock_descriptor('STDOUT', ["output 1\n", "output 2\n"])
stderr = mock_descriptor('STDOUT', [])
Open3.expects(:popen3).returns(['STDIN', stdout, stderr])

@controller.logger.expects(:error).never
do_post
end
end

0 comments on commit c41e85b

Please sign in to comment.