Sha256: d2ed346d83b7765175bd3659baacadf8c115f8e040f81a389e5eedbe2aafc48e
Contents?: true
Size: 967 Bytes
Versions: 3
Compression:
Stored size: 967 Bytes
Contents
require 'fileutils' require 'pre-commit/base' module PreCommit class Cli PRE_COMMIT_HOOK_PATH = '.git/hooks/pre-commit' def answered_yes?(answer) answer =~ /y\n/i || answer == "\n" end def install if File.exists?(PRE_COMMIT_HOOK_PATH) ask_to_overwrite end install_pre_commit_hook end def ask_to_overwrite puts "pre-commit: WARNING There is already a pre-commit hook installed in this git repo." print "Would you like to overwrite it? [Yn] " answer = $stdin.gets if answered_yes?(answer) FileUtils.rm(PRE_COMMIT_HOOK_PATH) else puts "Not overwriting existing hook: #{PRE_COMMIT_HOOK_PATH}" puts exit(1) end end def install_pre_commit_hook hook = File.join(PreCommit.root, 'templates', 'pre-commit-hook') FileUtils.cp(hook, PRE_COMMIT_HOOK_PATH) FileUtils.chmod(0755, PRE_COMMIT_HOOK_PATH) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
pre-commit-0.8.1 | lib/pre-commit/cli.rb |
pre-commit-0.8.0 | lib/pre-commit/cli.rb |
pre-commit-0.7.0 | lib/pre-commit/cli.rb |