Skip to content

Commit

Permalink
preserve original hooks when initializing
Browse files Browse the repository at this point in the history
  • Loading branch information
timcharper committed Mar 12, 2010
1 parent fcecd8c commit 27a2011
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
10 changes: 10 additions & 0 deletions features/initialization.feature
Expand Up @@ -23,3 +23,13 @@ Feature: Initialization
| post-checkout |
| post-merge |
| pre-auto-gc |

Scenario: initialization in a repo that already has hooks
Given I have a git repository with some commits
And the file ".git/hooks/post-commit" contains:
"""
echo "You are awesome"
"""
When I run "git hook init"
Then the following folders should exist:
| .git/hooks/local/post-commit.d/original |
6 changes: 4 additions & 2 deletions features/step_definitions/sandbox_steps.rb
Expand Up @@ -114,6 +114,8 @@

Given /^the file "(.+)" contains:$/ do |filename, content|
filename.gsub!("$GITTY_ASSETS", ENV["GITTY_ASSETS"])
FileUtils.mkdir_p(File.dirname(filename))
File.open(filename, "wb") { |f| f << content }
in_current_dir do
FileUtils.mkdir_p(File.dirname(filename))
File.open(filename, "wb") { |f| f << content }
end
end
4 changes: 4 additions & 0 deletions lib/gitty/commands/init.rb
Expand Up @@ -21,6 +21,10 @@ def run
FileUtils.mkdir_p(".git/hooks/local")

CLIENT_HOOKS.each do |hook|
if File.exist?(".git/hooks/#{hook}")
FileUtils.mkdir_p(".git/hooks/local/#{hook}.d")
FileUtils.mv(".git/hooks/#{hook}", ".git/hooks/local/#{hook}.d/original")
end
FileUtils.cp((ASSETS_PATH + "helpers/hookd_wrapper").to_s, ".git/hooks/#{hook}")
FileUtils.chmod(0755, ".git/hooks/#{hook}")
end
Expand Down

0 comments on commit 27a2011

Please sign in to comment.