Class: GitPrecommit::PrecommitTasks

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/git-precommit/precommit_tasks.rb

Constant Summary collapse

TEMPLATE_PATH =
File.expand_path(
File.join( File.dirname(__FILE__), '..', '..', 'git-hooks' )
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ PrecommitTasks

Returns a new instance of PrecommitTasks.

Yields:

  • (_self)

Yield Parameters:



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/git-precommit/precommit_tasks.rb', line 12

def initialize( options={} )
  @options = {
    :draconian => false,
    :path      => TEMPLATE_PATH
  }.merge options

  @options[:draconian] = true if options[:path]

  yield self if block_given?
  @template_path ||= @options[:path]

  define
end

Instance Attribute Details

#template_pathObject

Returns the value of attribute template_path.



10
11
12
# File 'lib/git-precommit/precommit_tasks.rb', line 10

def template_path
  @template_path
end

Instance Method Details

#defineObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/git-precommit/precommit_tasks.rb', line 26

def define()
  pre_commit     = ".git/hooks/pre-commit"
  pre_commit_src = "#{template_path}/pre-commit"

  task :overwrite

  deps =  [pre_commit_src]
  deps += [:overwrite] if @options[:draconian]

  desc "Install the git pre-commit hook"
  file pre_commit => deps do |t|
    copy  t.prerequisites.first, t.name
    chmod 0755, t.name
  end

  desc "Install the git post-commit hook"
  file ".git/hooks/post-commit" => "#{template_path}/post-commit" do |t|
    copy t.prerequisites.first, t.name
    chmod 0755, t.name
  end

  namespace :git do
    desc "Install the git pre-commit hook"
    task :precommit => pre_commit

    desc "Install the git post-commit hook"
    task :postcommit => ".git/hooks/post-commit"
  end
end