Class: Gitty::HookCommand::Init
- Includes:
- FileUtils, Gitty::Helpers
- Defined in:
- lib/gitty/commands/init.rb
Constant Summary collapse
- CLIENT_HOOKS =
%w[ applypatch-msg commit-msg post-applypatch post-checkout post-commit post-merge pre-applypatch pre-auto-gc pre-commit pre-rebase prepare-commit-msg ]
Instance Attribute Summary
Attributes inherited from Runner
Instance Method Summary collapse
Methods included from Gitty::Helpers
#cmd, #existing_directory!, #file_with_existing_directory!, #search_for_file_in_paths, #with_env_var
Methods inherited from Runner
#handle_show_help, #initialize, #options, run
Constructor Details
This class inherits a constructor from Gitty::Runner
Instance Method Details
#option_parser ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/gitty/commands/init.rb', line 55 def option_parser super.tap do |opts| opts. = "Usage: git hook init" opts.on("-s", "--enable-sharing", "Enable sharing") do [:sharing] = true end end end |
#run ⇒ Object
19 20 21 22 23 24 25 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 |
# File 'lib/gitty/commands/init.rb', line 19 def run puts "Initializing with gitty" # MESSY! mkdir_p(".git/hooks/gitty") mkdir_p(".git/hooks/shared") mkdir_p(".git/hooks/local") cp((ASSETS_PATH + "helpers/hookd_wrapper").to_s, ".git/hooks/gitty/hookd_wrapper") chmod(0755, ".git/hooks/gitty/hookd_wrapper") if [:sharing] cp((ASSETS_PATH + "helpers/update-shared-hooks").to_s, ".git/hooks/gitty/update-shared-hooks") chmod(0755, ".git/hooks/gitty/update-shared-hooks") end CLIENT_HOOKS.each do |hook| if File.exist?(".git/hooks/#{hook}") mkdir_p(".git/hooks/local/#{hook}.d") mv(".git/hooks/#{hook}", ".git/hooks/local/#{hook}.d/original") end ln_sf("gitty/hookd_wrapper", ".git/hooks/#{hook}") end hooks_rev = remote_hooks_rev with_env_var("GIT_OBJECT_DIRECTORY", File.join(Dir.pwd, ".git/objects")) do Dir.chdir(".git/hooks/shared") do unless File.exist?(".git") cmd(*%w[git init]) cmd(*%w[git symbolic-ref HEAD refs/heads/--hooks--]) cmd(*%w[git commit --allow-empty -m initial\ commit]) end cmd("git reset --hard #{hooks_rev}") if hooks_rev end end end |