Class: Rwm::GitHooks

Inherits:
Object
  • Object
show all
Defined in:
lib/rwm/git_hooks.rb

Constant Summary collapse

PRE_PUSH_HOOK =
"#!/bin/bash\nbundle exec rwm check\n"
POST_COMMIT_HOOK =
"#!/bin/bash\n# Only rebuild graph if a Gemfile changed in this commit\nif git diff-tree --no-commit-id --name-only -r HEAD 2>/dev/null | grep -q 'Gemfile'; then\n  bundle exec rwm graph\nfi\n"

Instance Method Summary collapse

Constructor Details

#initialize(workspace_root) ⇒ GitHooks

Returns a new instance of GitHooks.



20
21
22
# File 'lib/rwm/git_hooks.rb', line 20

def initialize(workspace_root)
  @root = workspace_root
end

Instance Method Details

#setupObject



24
25
26
27
28
29
30
31
32
# File 'lib/rwm/git_hooks.rb', line 24

def setup
  hooks_dir = File.join(@root, ".git", "hooks")
  return false unless File.directory?(File.join(@root, ".git"))

  FileUtils.mkdir_p(hooks_dir)
  install_hook(hooks_dir, "pre-push", PRE_PUSH_HOOK)
  install_hook(hooks_dir, "post-commit", POST_COMMIT_HOOK)
  true
end