Skip to content

Commit 5af1219

Browse files
authored
Correctly report command output when there is an error (#658)
Signed-off-by: James Couball <jcouball@yahoo.com>
1 parent b27a15b commit 5af1219

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lib/git/failed_error.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ module Git
1414
class FailedError < Git::GitExecuteError
1515
# Create a FailedError object
1616
#
17+
# Since this gem redirects stderr to stdout, the stdout of the process is used.
18+
#
1719
# @example
1820
# `exit 1` # set $? appropriately for this example
19-
# result = Git::CommandLineResult.new(%w[git status], $?, '', "failed")
21+
# result = Git::CommandLineResult.new(%w[git status], $?, 'stdout', 'stderr')
2022
# error = Git::FailedError.new(result)
2123
# error.message #=>
22-
# "[\"git\", \"status\"]\nstatus: pid 89784 exit 1\nstderr: \"failed\""
24+
# "[\"git\", \"status\"]\nstatus: pid 89784 exit 1\noutput: \"stdout\""
2325
#
2426
# @param result [Git::CommandLineResult] the result of the git command including
2527
# the git command, status, stdout, and stderr
2628
#
2729
def initialize(result)
28-
super("#{result.git_cmd}\nstatus: #{result.status}\nstderr: #{result.stderr.inspect}")
30+
super("#{result.git_cmd}\nstatus: #{result.status}\noutput: #{result.stdout.inspect}")
2931
@result = result
3032
end
3133

@@ -35,14 +37,14 @@ def initialize(result)
3537
#
3638
# @example
3739
# `exit 1` # set $? appropriately for this example
38-
# result = Git::CommandLineResult.new(%w[git status], $?, '', "failed")
40+
# result = Git::CommandLineResult.new(%w[git status], $?, 'stdout', 'stderr')
3941
# error = Git::FailedError.new(result)
4042
# error.result #=>
4143
# #<Git::CommandLineResult:0x00000001046bd488
4244
# @git_cmd=["git", "status"],
4345
# @status=#<Process::Status: pid 89784 exit 1>,
44-
# @stderr="failed",
45-
# @stdout="">
46+
# @stderr="stderr",
47+
# @stdout="stdout">
4648
#
4749
# @return [Git::CommandLineResult]
4850
#

tests/units/test_failed_error.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class TestFailedError < Test::Unit::TestCase
44
def test_initializer
55
status = Struct.new(:to_s).new('pid 89784 exit 1')
6-
result = Git::CommandLineResult.new(%w[git status], status, '', "failed")
6+
result = Git::CommandLineResult.new(%w[git status], status, 'stdout', 'stderr')
77

88
error = Git::FailedError.new(result)
99

@@ -13,11 +13,11 @@ def test_initializer
1313

1414
def test_message
1515
status = Struct.new(:to_s).new('pid 89784 exit 1')
16-
result = Git::CommandLineResult.new(%w[git status], status, '', "failed")
16+
result = Git::CommandLineResult.new(%w[git status], status, 'stdout', 'stderr')
1717

1818
error = Git::FailedError.new(result)
1919

20-
expected_message = "[\"git\", \"status\"]\nstatus: pid 89784 exit 1\nstderr: \"failed\""
20+
expected_message = "[\"git\", \"status\"]\nstatus: pid 89784 exit 1\noutput: \"stdout\""
2121
assert_equal(expected_message, error.message)
2222
end
2323
end

0 commit comments

Comments
 (0)