Skip to content

Commit 8f5d9c7

Browse files
committed
Add test for installing overcommit
After fixing an issue with installing overcommit hooks in a repo with hooks installed via template directory in 6d6f853, we add some tests to ensure we don't break this in future. Change-Id: Ic3f31ecc288d1273ef17d3c9e7e12d97e72e0781 Reviewed-on: http://gerrit.causes.com/45271 Tested-by: jenkins <jenkins@brigade.com> Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
1 parent 97a00a7 commit 8f5d9c7

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

lib/overcommit/installer.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
module Overcommit
44
# Manages the installation of Overcommit hooks in a git repository.
55
class Installer # rubocop:disable ClassLength
6-
MASTER_HOOK =
7-
File.join(OVERCOMMIT_HOME, 'template-dir', 'hooks', 'overcommit-hook')
6+
TEMPLATE_DIRECTORY = File.join(OVERCOMMIT_HOME, 'template-dir')
7+
MASTER_HOOK = File.join(TEMPLATE_DIRECTORY, 'hooks', 'overcommit-hook')
88

99
def initialize(logger)
1010
@log = logger
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'spec_helper'
2+
3+
describe 'installing Overcommit' do
4+
context 'when template directory points to the Overcommit template directory' do
5+
around do |example|
6+
repo(:template_dir => Overcommit::Installer::TEMPLATE_DIRECTORY) do
7+
example.run
8+
end
9+
end
10+
11+
it 'automatically installs Overcommit hooks for new repositories' do
12+
Overcommit::Utils.supported_hook_types.each do |hook_type|
13+
hook_file = File.join('.git', 'hooks', hook_type)
14+
File.read(hook_file).should include 'OVERCOMMIT'
15+
end
16+
end
17+
18+
context 'and Overcommit is manually installed' do
19+
before do
20+
`overcommit --install`
21+
end
22+
23+
it 'replaces the hooks with symlinks' do
24+
Overcommit::Utils.supported_hook_types.each do |hook_type|
25+
hook_file = File.join('.git', 'hooks', hook_type)
26+
File.symlink?(hook_file).should == true
27+
end
28+
end
29+
end
30+
end
31+
end

spec/support/git_spec_helpers.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
module GitSpecHelpers
55
module_function
66

7-
def repo(name = 'some-repo', &block)
8-
directory(name) do
9-
`git init --template=""` # Ensure no template directory is applied
7+
def repo(options = {}, &block)
8+
directory('some-repo') do
9+
`git init --template="#{options[:template_dir]}"`
1010

11-
`mkdir -p .git/hooks` # Since we don't specify template, need to create ourselves
11+
`mkdir -p .git/hooks` # Since we may not specify template, need to create ourselves
1212

1313
# Need to define user info since some CI contexts don't have defaults set
1414
`git config --local user.name "Overcommit Tester"`

0 commit comments

Comments
 (0)