Method: Codeqa.install

Defined in:
lib/codeqa.rb

.install(root = '.') ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/codeqa.rb', line 10

def install(root='.')
  require 'fileutils'
  git_root = Pathname.new "#{root}/.git"
  if File.exist?(git_root)
    pre_commit_path = git_root.join 'hooks', 'pre-commit'
    if File.exist?(pre_commit_path)
      # $stdout.puts 'moving away the old pre-commit hook -> pre-commit.bkp'
      FileUtils.mv(pre_commit_path,
                   git_root.join('hooks', 'pre-commit.bkp'),
                   :force => true)
    end
    pre_commit_template_path = Codeqa.root.join('lib', 'templates', 'pre-commit')
    # $stdout.puts 'placing new pre-commit hook'
    FileUtils.cp(pre_commit_template_path, pre_commit_path)
    FileUtils.chmod('+x', pre_commit_path)
    true
  else
    # $stderr.puts "#{root} is not in a git root"
    false
  end
end