Class: Git::Duet::InstallHookCommand

Inherits:
Object
  • Object
show all
Includes:
CommandMethods
Defined in:
lib/git/duet/install_hook_command.rb

Constant Summary collapse

HOOK =
<<-EOF.gsub(/^  /, '')
#!/bin/bash
exec git duet-pre-commit "$@"
EOF

Instance Method Summary collapse

Constructor Details

#initialize(quiet = false) ⇒ InstallHookCommand

Returns a new instance of InstallHookCommand.



13
14
15
# File 'lib/git/duet/install_hook_command.rb', line 13

def initialize(quiet = false)
  @quiet = quiet
end

Instance Method Details

#execute! ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/git/duet/install_hook_command.rb', line 17

def execute!
  Dir.chdir(`git rev-parse --show-toplevel`.chomp) do
    dest = File.join(Dir.pwd, '.git', 'hooks', 'pre-commit')
    if File.exist?(dest)
      error("git-duet-install-hook: A pre-commit hook already exists at #{dest}!")
      error("git-duet-install-hook: Move it out of the way first, mkay?")
      return 1
    end
    File.open(dest, 'w') do |f|
      f.puts HOOK
    end
    FileUtils.chmod(0755, dest)
    info("git-duet-install-hook: Installed hook to #{dest}")
  end
  return 0
end