Skip to content

Commit 2c09265

Browse files
detouchedsds
authored andcommitted
PR review - Refactor checking LFS executable on PATH
- Use `in_path` to check LFS binary presence on PATH - Fix newline in the warning message when LFS binary is not on PATH
1 parent 88882f2 commit 2c09265

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

lib/overcommit/hook/pre_push/git_lfs.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ module Overcommit::Hook::PrePush
44
# @see https://git-lfs.github.com/
55
class GitLfs < Base
66
def run
7-
result = execute(['command', '-v', 'git-lfs'])
8-
unless result.success?
7+
unless in_path?('git-lfs')
98
return :warn, 'This repository is configured for Git LFS but \'git-lfs\' ' \
10-
'was not found on your path.\nIf you no longer wish to use Git LFS, ' \
9+
"was not found on your path.\nIf you no longer wish to use Git LFS, " \
1110
'disable this hook by removing or setting \'enabled: false\' for GitLFS ' \
1211
'hook in your .overcommit.yml file'
1312
end

spec/overcommit/hook/pre_push/git_lfs_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
let(:result) { double('result') }
99

1010
before do
11+
subject.stub(in_path?: true)
1112
subject.stub(:execute).and_return(result)
1213
end
1314

1415
context 'when git-lfs is not on path' do
1516
before do
16-
result.stub(success?: false, stderr: '')
17+
subject.stub(in_path?: false)
1718
end
1819

1920
it { should warn }
@@ -29,9 +30,8 @@
2930

3031
context 'when git lfs hook exits unsuccessfully' do
3132
before do
32-
# First for checking that git-lfs is on path, second for calling the hook itself
33-
result.stub(:success?).and_return(true, false)
34-
result.stub(:stderr).and_return('', 'error: failed to push some refs')
33+
result.stub(success?: false)
34+
result.stub(stderr: 'error: failed to push some refs')
3535
end
3636

3737
it { should fail_hook }

0 commit comments

Comments
 (0)