Skip to content

Commit cec0f60

Browse files
author
JR Richardson
committed
Print warning when falling back to git. Raise error if fallback fails
1 parent 1f76831 commit cec0f60

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/code_climate/test_reporter/calculate_blob.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def initialize(file_path)
88
end
99

1010
def blob_id
11-
calculate_with_file || calculate_with_git
11+
calculate_with_file or calculate_with_git
1212
end
1313

1414
private
@@ -22,10 +22,15 @@ def calculate_with_file
2222
return Digest::SHA1.hexdigest(store)
2323
end
2424
rescue EncodingError
25+
puts "WARNING: Unable to read #{@file_path}\nUsing git for blob calculation"
26+
nil
2527
end
2628

2729
def calculate_with_git
28-
Kernel.system("git hash-object -t blob #{@file_path}")
30+
output = `git hash-object -t blob #{@file_path}`.chomp
31+
raise 'ERROR: Failed to calculate blob with git' unless $?.success?
32+
33+
output
2934
end
3035

3136
end

spec/lib/calculate_blob_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ module CodeClimate::TestReporter
1717

1818
it 'falls back to git' do
1919
expect(File).to receive(:open).and_raise(EncodingError)
20-
expect(Kernel).to receive(:system).with("git hash-object -t blob #{fixture}").and_return('123')
21-
expect(subject.blob_id).to eq('123')
20+
expect(subject.blob_id).to eq('eb82c22dadb9c47a7fed87211623f6856e112f46')
2221
end
2322

2423
end

0 commit comments

Comments
 (0)