Class: Gitty::HookCommand::Share

Inherits:
Runner show all
Includes:
FileUtils
Defined in:
lib/gitty/commands/share.rb

Instance Attribute Summary

Attributes inherited from Runner

#args, #stderr, #stdout

Instance Method Summary collapse

Methods inherited from Runner

#handle_show_help, run

Constructor Details

#initialize(args, stdout = STDOUT, stderr = STDERR) ⇒ Share

Returns a new instance of Share.



3
4
5
6
# File 'lib/gitty/commands/share.rb', line 3

def initialize(args, stdout = STDOUT, stderr = STDERR)
  super
  @hookname = args.shift
end

Instance Method Details

#option_parserObject



29
30
31
32
33
# File 'lib/gitty/commands/share.rb', line 29

def option_parser
  @option_parser ||= super.tap do |opts|
    opts.banner = "Usage: git hook install [opts] hook-name"
  end
end

#optionsObject



25
26
27
# File 'lib/gitty/commands/share.rb', line 25

def options
  @options ||= super.update(:kind => :local)
end

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gitty/commands/share.rb', line 8

def run
  hook = Gitty::Hook.find(@hookname, :install_kind => :local) || Gitty::Hook.find(@hookname, :installed => false)
  if hook.nil?
    stderr.puts "no hook named '#{@hookname}' is available"
    exit 1
  end
  if hook.install_kind == :shared
    stderr.puts "hook #{@hookname} is already installed"
    exit 1
  end
  unless Gitty.sharing_enabled?
    stderr.puts "WARNING: sharing is disabled on your repository.  Run git hook init --enable-sharing to turn it on."
  end
  hook.share!
  stdout.puts "To propagate this change other developers, run 'git hook publish -m \"added #{hook.name}...\""
end