summaryrefslogtreecommitdiff
path: root/task/git_hooks.rake
blob: 5c5482caa15572919d302e2ac3dc378d42e284f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

directory ".git/hooks"

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, :verbose => false
end

file ".git/hooks/pre-push" => [__FILE__] do |_t|
  Dir.chdir(".git/hooks") do
    safe_ln "pre-commit", "pre-push", :verbose => false
  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, :verbose => false
end

task :git_hooks => Rake::Task.tasks.select {|t| t.name.start_with?(".git/hooks") }