Skip to content

Commit d1871c2

Browse files
committed
Count lines directly rather than using wc -l
1 parent d1fd7be commit d1871c2

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/overcommit/hook_context/run_all.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def modified_files
1717
# @return [Set]
1818
def modified_lines_in_file(file)
1919
@modified_lines_in_file ||= {}
20-
@modified_lines_in_file[file] ||= Set.new(1..(count_lines(file) + 1))
20+
@modified_lines_in_file[file] ||= Set.new(1..count_lines(file))
2121
end
2222

2323
def hook_class_name
@@ -35,8 +35,9 @@ def hook_script_name
3535
private
3636

3737
def count_lines(file)
38-
result = Overcommit::Utils.execute(%w[wc -l] + [file])
39-
result.success? ? result.stdout.to_i : 0
38+
num_lines = 0
39+
File.new(file).each_line { num_lines += 1 }
40+
num_lines
4041
end
4142
end
4243
end

spec/overcommit/hook_context/run_all_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
end
6868
end
6969

70-
it { should == Set.new(1..4) }
70+
it { should == Set.new(1..3) }
7171
end
7272

7373
context 'when file does not contain a trailing newline' do

0 commit comments

Comments
 (0)