forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Git LFS installs pre-push hook which: - checks that git-lfs utility is on PATH, and if no, warns that Git LFS hook should probably be removed - calls it by executing `git lfs pre-push <remote_name> <remote_url>` The introduced hook is a Ruby port of the same algorithm modulo hook disabling note in the warning message.
- Loading branch information
Showing
4 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Overcommit::Hook::PrePush | ||
# Invokes Git LFS command that uploads files tracked by Git LFS to the LFS storage | ||
# | ||
# @see https://git-lfs.github.com/ | ||
class GitLfs < Base | ||
def run | ||
result = execute(['command', '-v', 'git-lfs']) | ||
unless result.success? | ||
return :warn, 'This repository is configured for Git LFS but \'git-lfs\' ' \ | ||
'was not found on your path.\nIf you no longer wish to use Git LFS, ' \ | ||
'disable this hook by removing or setting \'enabled: false\' for GitLFS ' \ | ||
'hook in your .overcommit.yml file' | ||
end | ||
|
||
result = execute(['git', 'lfs', 'pre-push', remote_name, remote_url]) | ||
return :fail, result.stderr unless result.success? | ||
|
||
:pass | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'spec_helper' | ||
|
||
describe Overcommit::Hook::PrePush::GitLfs do | ||
let(:config) { Overcommit::ConfigurationLoader.default_configuration } | ||
let(:context) { double('context', remote_name: 'remote_name', remote_url: 'remote_url') } | ||
subject { described_class.new(config, context) } | ||
|
||
let(:result) { double('result') } | ||
|
||
before do | ||
subject.stub(:execute).and_return(result) | ||
end | ||
|
||
context 'when git-lfs is not on path' do | ||
before do | ||
result.stub(success?: false, stderr: '') | ||
end | ||
|
||
it { should warn } | ||
end | ||
|
||
context 'when git lfs hook exits successfully' do | ||
before do | ||
result.stub(success?: true, stderr: '') | ||
end | ||
|
||
it { should pass } | ||
end | ||
|
||
context 'when git lfs hook exits unsuccessfully' do | ||
before do | ||
# First for checking that git-lfs is on path, second for calling the hook itself | ||
result.stub(:success?).and_return(true, false) | ||
result.stub(:stderr).and_return('', 'error: failed to push some refs') | ||
end | ||
|
||
it { should fail_hook } | ||
end | ||
end |