Skip to content

Instantly share code, notes, and snippets.

@ro-tex
Created October 29, 2019 17:27
Show Gist options
  • Save ro-tex/d37d0824fd8f854b13158f5537b70577 to your computer and use it in GitHub Desktop.
Save ro-tex/d37d0824fd8f854b13158f5537b70577 to your computer and use it in GitHub Desktop.
pre-push hook for ensuring .env.dist matches .env
#!/usr/bin/ruby
unless(File.exist?('.env'))
# We're not using a .env, so we don't need to check anything
exit 0
end
unless(File.exist?('.env.dist'))
puts 'Cannot commit while you have a .env and not a .env.dist. Please create a descriptive .env.dist.'
exit 1
end
shouldHaveKeys = File.open('.env').map{|line| line.split('=',2)[0]}
haveKeys = File.open('.env.dist').map{|line| line.split('=',2)[0]}
discrepency = shouldHaveKeys - haveKeys
if (discrepency.length > 0)
puts "Some keys are present in .env but not in .env.dist. Please update .env.dist.\nKeys: #{discrepency.join(', ')}"
exit 1
end
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment