Last active
December 19, 2015 12:39
-
-
Save textgoeshere/5956134 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
############################################################### | |
# Prevents a commit when Gemfile has references to local gems # | |
############################################################### | |
if | |
test "$(git diff-index --cached HEAD -G'\Wpath(:|\s?=\>)' -- Gemfile)" | |
then | |
echo "Error: you have references to local gems in your Gemfile. Commit aborted." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had this as mine already (stolen from some blog post some where on the internet):
$ #!/usr/bin/env ruby
$ # A pre-commit hook script to ensure that no local gem dependencies (gem 'asdf', path: '~/local')
$ # exist in your Gemfile before commiting.`
$ # Allows gems to be loaded from source within the current project, but not from outside.
$ puts 'Checking for local dependencies in your Gemfile.'
$ ROOT_PATH = File.expand_path('../../..', FILE)
$ NESTED_GEMSPECS = Dir["#{ROOT_PATH}/*/.gemspec"]
$ GEMFILE = ENV['BUNDLE_GEMFILE'] || File.join(ROOT_PATH, 'Gemfile')
$ def local?(gemspec)
$ gemspec.source.instance_of?(Bundler::Source::Path)
$ end
$ def nested?(gemspec)
$ NESTED_GEMSPECS.any? { |filename| filename.include?(gemspec.name) }
$ end
$ if open(GEMFILE) { |gemfile| gemfile.grep(/path/) }
$ require 'rubygems'
$ require 'bundler/setup'
$ local_gems = Gem.loaded_specs.values.select do |gemspec|
$ local?(gemspec) and not nested?(gemspec)
$ end
$ unless local_gems.empty? then raise SyntaxError,
$ "You have local dependencies in your Gemfile:"
$ " #{local_gems.map{|g| g.name + ' is loading from ' + g.source.path.to_s}.join(', ')}."
$ " Remove the :path parameter from this/these gems in your Gemfile before committing." end
$ end