|
4 | 4 | let(:logger) { Overcommit::Logger.silent }
|
5 | 5 | let(:installer) { described_class.new(logger) }
|
6 | 6 |
|
| 7 | + def hook_files_installed?(hooks_dir) |
| 8 | + Overcommit::Utils.supported_hook_types.all? do |hook_type| |
| 9 | + hook_file = File.join(hooks_dir, hook_type) |
| 10 | + master_hook = File.join(hooks_dir, 'overcommit-hook') |
| 11 | + File.exist?(hook_file) && File.exist?(master_hook) && |
| 12 | + File.read(hook_file) == File.read(master_hook) |
| 13 | + end |
| 14 | + end |
| 15 | + |
7 | 16 | describe '#run' do
|
8 | 17 | let(:options) { { action: :install } }
|
9 | 18 | subject { installer.run(target.to_s, options) }
|
|
28 | 37 | let(:target) { repo }
|
29 | 38 | let(:hooks_dir) { File.join(target, '.git', 'hooks') }
|
30 | 39 | let(:old_hooks_dir) { File.join(hooks_dir, 'old-hooks') }
|
| 40 | + let(:master_hook) { File.join(hooks_dir, 'overcommit-hook') } |
31 | 41 |
|
32 | 42 | context 'and an install is requested' do
|
33 | 43 | context 'and Overcommit hooks were not previously installed' do
|
34 | 44 | it 'installs the master hook into the hooks directory' do
|
35 | 45 | expect { subject }.to change {
|
36 |
| - File.file?(File.join(hooks_dir, 'overcommit-hook')) |
| 46 | + File.file?(master_hook) |
37 | 47 | }.from(false).to(true)
|
38 | 48 | end
|
39 | 49 |
|
40 |
| - it 'symlinks all supported hooks to the master hook' do |
| 50 | + it 'copies all supported hooks from the master hook' do |
41 | 51 | expect { subject }.to change {
|
42 |
| - Overcommit::Utils.supported_hook_types.all? do |hook_type| |
43 |
| - hook_file = File.join(hooks_dir, hook_type) |
44 |
| - Overcommit::Utils::FileUtils.symlink?(hook_file) && |
45 |
| - Overcommit::Utils::FileUtils.readlink(hook_file) == 'overcommit-hook' |
46 |
| - end |
| 52 | + hook_files_installed?(hooks_dir) |
47 | 53 | }.from(false).to(true)
|
48 | 54 | end
|
49 | 55 | end
|
|
55 | 61 |
|
56 | 62 | it 'keeps the master hook' do
|
57 | 63 | expect { subject }.to_not change {
|
58 |
| - File.file?(File.join(hooks_dir, 'overcommit-hook')) |
| 64 | + File.file?(master_hook) |
59 | 65 | }.from(true)
|
60 | 66 | end
|
61 | 67 |
|
62 |
| - it 'maintains all symlinks to the master hook' do |
| 68 | + it 'maintains all copies of the master hook' do |
63 | 69 | expect { subject }.to_not change {
|
64 |
| - Overcommit::Utils.supported_hook_types.all? do |hook_type| |
65 |
| - hook_file = File.join(hooks_dir, hook_type) |
66 |
| - Overcommit::Utils::FileUtils.symlink?(hook_file) && |
67 |
| - Overcommit::Utils::FileUtils.readlink(hook_file) == 'overcommit-hook' |
68 |
| - end |
| 70 | + hook_files_installed?(hooks_dir) |
69 | 71 | }.from(true)
|
70 | 72 | end
|
71 | 73 | end
|
|
99 | 101 | expect { subject }.to_not raise_error
|
100 | 102 | end
|
101 | 103 |
|
102 |
| - it 'symlinks all supported hooks to the master hook' do |
| 104 | + it 'copies all supported hooks from the master hook' do |
103 | 105 | expect { subject }.to change {
|
104 |
| - Overcommit::Utils.supported_hook_types.all? do |hook_type| |
105 |
| - hook_file = File.join(hooks_dir, hook_type) |
106 |
| - Overcommit::Utils::FileUtils.symlink?(hook_file) && |
107 |
| - Overcommit::Utils::FileUtils.readlink(hook_file) == 'overcommit-hook' |
108 |
| - end |
| 106 | + hook_files_installed?(hooks_dir) |
109 | 107 | }.from(false).to(true)
|
110 | 108 | end
|
111 | 109 | end
|
|
156 | 154 |
|
157 | 155 | it 'removes the master hook from the hooks directory' do
|
158 | 156 | expect { subject }.to change {
|
159 |
| - File.exist?(File.join(hooks_dir, 'overcommit-hook')) |
| 157 | + File.exist?(master_hook) |
160 | 158 | }.from(true).to(false)
|
161 | 159 | end
|
162 | 160 |
|
163 |
| - it 'removes all symlinks from the hooks directory' do |
| 161 | + it 'removes all hook files from the hooks directory' do |
164 | 162 | expect { subject }.to change {
|
165 |
| - Overcommit::Utils.supported_hook_types.all? do |hook_type| |
166 |
| - hook_file = File.join(hooks_dir, hook_type) |
167 |
| - Overcommit::Utils::FileUtils.symlink?(hook_file) && |
168 |
| - Overcommit::Utils::FileUtils.readlink(hook_file) == 'overcommit-hook' |
169 |
| - end |
| 163 | + hook_files_installed?(hooks_dir) |
170 | 164 | }.from(true).to(false)
|
171 | 165 | end
|
172 | 166 | end
|
|
0 commit comments