Sha256: 4143d15f51e2301f24f6e01734ad17a7bfd74c5e3197abf4eb30d71650b3a9c8

Contents?: true

Size: 832 Bytes

Versions: 3

Compression:

Stored size: 832 Bytes

Contents

require 'git/duet'
require 'fileutils'
require 'git/duet/command_methods'

class Git::Duet::InstallHookCommand
  include Git::Duet::CommandMethods

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

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

  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
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
git-duet-0.1.3 lib/git/duet/install_hook_command.rb
git-duet-0.1.2 lib/git/duet/install_hook_command.rb
git-duet-0.1.1 lib/git/duet/install_hook_command.rb