class Jigit::GitHookInstaller
Command to setup the git hook for jigit
Public Class Methods
new(git_hooks_folder = nil, git_path = nil)
click to toggle source
# File lib/jigit/git/git_hook_installer.rb, line 6 def initialize(git_hooks_folder = nil, git_path = nil) @git_hooks_folder = git_hooks_folder ? git_hooks_folder : default_git_hooks_folder @git_path = git_path ? git_path : default_git_path @is_git_hook_file_new = false end
Public Instance Methods
install(hook)
click to toggle source
# File lib/jigit/git/git_hook_installer.rb, line 12 def install(hook) @git_hook_name = hook.name @git_hook_file_path = "#{@git_hooks_folder}/#{@git_hook_name}" ensure_git_hook_file_exists ensure_git_hook_file_is_executable write_hook_lines(hook.hook_lines) end
Private Instance Methods
default_git_hooks_folder()
click to toggle source
# File lib/jigit/git/git_hook_installer.rb, line 56 def default_git_hooks_folder "#{default_git_path}/hooks" end
default_git_path()
click to toggle source
# File lib/jigit/git/git_hook_installer.rb, line 52 def default_git_path ".git" end
ensure_git_hook_file_exists()
click to toggle source
# File lib/jigit/git/git_hook_installer.rb, line 23 def ensure_git_hook_file_exists @git_hook_file_path = File.realpath(@git_hook_file_path) if File.symlink?(@git_hook_file_path) return if File.exist?(@git_hook_file_path) raise "Git folder is not found at '#{@git_path}'" unless Dir.exist?(@git_path) FileUtils.mkdir_p(@git_hooks_folder) @git_hook_file_path = "#{@git_hooks_folder}/#{@git_hook_name}" FileUtils.touch(@git_hook_file_path) FileUtils.chmod("u=xwr", @git_hook_file_path) @is_git_hook_file_new = true end
ensure_git_hook_file_is_executable()
click to toggle source
# File lib/jigit/git/git_hook_installer.rb, line 36 def ensure_git_hook_file_is_executable raise "git hook file at '#{@git_hook_file_path}' is not executable by the effective user id of this process" unless File.executable?(@git_hook_file_path) end
git_hook_file_path()
click to toggle source
# File lib/jigit/git/git_hook_installer.rb, line 48 def git_hook_file_path "#{default_git_hooks_folder}/#{@git_hook_name}" end
write_hook_lines(hook_lines)
click to toggle source
# File lib/jigit/git/git_hook_installer.rb, line 40 def write_hook_lines(hook_lines) File.open(@git_hook_file_path, @is_git_hook_file_new ? "r+" : "a") do |f| hook_lines.each do |line| f.puts(line) end end end