diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2017-06-12 18:19:30 -0500 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2017-06-12 22:44:05 -0500 |
commit | bf2ba39a58d4f14551900c65676fe70f3c51e1db (patch) | |
tree | 0519535a7deaf956e85bf5c66f1bb700344d9176 | |
parent | d19f6aada25880451086508c98391177a94addfa (diff) | |
download | bundler-bf2ba39a58d4f14551900c65676fe70f3c51e1db.tar.gz |
[Rakefile] Add tasks to setup git hooks
-rw-r--r-- | task/build_metadata.rake | 2 | ||||
-rw-r--r-- | task/git_hooks.rake | 47 |
2 files changed, 48 insertions, 1 deletions
diff --git a/task/build_metadata.rake b/task/build_metadata.rake index f7841ea338..86666384ed 100644 --- a/task/build_metadata.rake +++ b/task/build_metadata.rake @@ -1,5 +1,5 @@ # frozen_string_literal: true -file "lib/bundler/generated/build_metadata.rb" => [".git/HEAD", ".git/logs/HEAD", __FILE__] do |t| +file "lib/bundler/generated/build_metadata.rb" => [".git/HEAD", ".git/logs/HEAD", __FILE__, :git_hooks] do |t| sh "git update-index --assume-unchanged #{t.name}" build_metadata = { diff --git a/task/git_hooks.rake b/task/git_hooks.rake new file mode 100644 index 0000000000..9d41370ba0 --- /dev/null +++ b/task/git_hooks.rake @@ -0,0 +1,47 @@ +# frozen_string_literal: true +directory ".git/hooks" + +file ".git/hooks/post-commit" => [__FILE__] do |t| + File.open(t.name, "w") {|f| f << <<-SH } +#! /usr/bin/env sh + +set -e + +.git/hooks/run-ruby bin/rake generate_files + SH + + chmod 0o755, t.name +end + +file ".git/hooks/pre-commit" => [__FILE__] do |t| + File.open(t.name, "w") {|f| f << <<-SH } +#!/bin/sh + +set -e + +.git/hooks/run-ruby bin/rubocop +.git/hooks/run-ruby bin/rspec spec/quality_spec.rb + SH + + chmod 0o755, t.name +end + +file ".git/hooks/pre-push" => [__FILE__] do |_t| + Dir.chdir(".git/hooks") do + safe_ln "pre-commit", "pre-push" + end +end + +file ".git/hooks/run-ruby" => [__FILE__] do |t| + File.open(t.name, "w") {|f| f << <<-SH } +#!/bin/bash + +ruby="ruby" +command -v chruby-exec >/dev/null 2>&1 && [[ -f ~/.ruby-version ]] && ruby="chruby-exec $(cat ~/.ruby-version) --" +ruby $@ + SH + + chmod 0o755, t.name +end + +task :git_hooks => Rake::Task.tasks.select {|t| t.name.start_with?(".git/hooks") } |