Sha256: ad879d0aa39aa8d9630b075708b5dc6d6a8e48f691a40427f55c2d704c3a384f

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

# vim:fileencoding=utf-8
require 'git/duet'
require 'fileutils'
require 'git/duet/command_methods'

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

      HOOK = <<-EOF.gsub(/^ {8}/, '')
        #!/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')
          return error_hook_exists(dest) if File.exist?(dest)
          File.open(dest, 'w') { |f| f.puts HOOK }
          FileUtils.chmod(0755, dest)
          info("git-duet-install-hook: Installed hook to #{dest}")
        end
        0
      end

      private

      def error_hook_exists(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?')
        1
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
git-duet-0.5.1 lib/git/duet/install_hook_command.rb
git-duet-0.5.0 lib/git/duet/install_hook_command.rb
git-duet-0.4.1 lib/git/duet/install_hook_command.rb
git-duet-0.4.0 lib/git/duet/install_hook_command.rb