-
Notifications
You must be signed in to change notification settings - Fork 280
Add Git LFS pre-push hook #479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,20 @@ | ||
| 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 | ||
| unless in_path?('git-lfs') | ||
| 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 hidden or 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(in_path?: true) | ||
| subject.stub(:execute).and_return(result) | ||
| end | ||
|
|
||
| context 'when git-lfs is not on path' do | ||
| before do | ||
| subject.stub(in_path?: false) | ||
| 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 | ||
| result.stub(success?: false) | ||
| result.stub(stderr: 'error: failed to push some refs') | ||
| end | ||
|
|
||
| it { should fail_hook } | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure: is it possible to output some information in case the hook passes?
In fact, ideally it'd be cool to be able to output something while the hook works cause uploading LFS files might take a while. The original LFS hook reports status interactively, something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know of a good way. Would it make sense to instead of actually uploading just check if there is something to upload? The overcommit hook would then output something like
I'm not a lfs user myself, so this idea might not be possible at all. Or it might just be annoying to have to run the upload manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would require some refactoring of the display logic for Overcommit. In the past we've kicked around the idea of supporting progress bars or similar, but this would require a much more complicated display controller that utilized more advanced cursor features so you could update multiple lines at the same time (since hooks run in parallel).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely open to the idea, but I think it's well outside the scope of what you're trying to accomplish with this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, you'd just want it to be uploaded just with
git push, without additionally callinggit lfs .... Also, I'd not make overcommit behaviour different from standard (meaning what is installed by LFS client by default).I totally agree, I was wondering if there's a way to do that, but if not, it's fine. It might be just mentioned in the doc since GitLfs hook is disabled by default and requires the user to add it in the config yaml.