Created
April 19, 2016 02:59
-
-
Save alexagranov/5492bbd8bf5d6f5869c232b1127cd4a4 to your computer and use it in GitHub Desktop.
Custom Overcommit hook to replace the hook installed by git-lfs (which Overcommit removes)
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
# .git_hooks/pre_push/git_lfs.rb | |
# Be sure to enable this hook in .overcommit.yml like this: | |
# | |
# PrePush: | |
# GitLfs: | |
# enabled: true | |
module Overcommit::Hook::PrePush | |
class GitLfs < Base | |
# Overcommit expects you to override this method which will be called | |
# everytime your pre-commit hook is run. | |
def run | |
# Create two arrays to hold our error and warning messages. | |
error_lines = [] | |
warning_lines = [] | |
# Check if git-lfs executable exists | |
path_to_git_lfs = `command -v git-lfs`.strip | |
error_lines << "This repository is configured for Git LFS but 'git-lfs' was not found "\ | |
"on your path. If you no longer wish to use Git LFS, disable GitLfs in "\ | |
".overcommit.yml." unless File.exist?(path_to_git_lfs) | |
# Run the `git lfs pre-push` with supplied remote_name and remote_url accessors | |
`git lfs pre-push #{remote_name} #{remote_url}` | |
# Overcommit expects 1 of the 3 as return values, `:fail`, `:warn` or `:pass`. | |
# If the hook returns `:fail`, the commit will be aborted with our message | |
# containing the errors. | |
return :fail, error_lines.join("\n") if error_lines.any? | |
:pass | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment