git-hooks 0.5.0 → 0.6.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +18 -1
- data/lib/git_hooks/cli.rb +3 -1
- data/lib/git_hooks/exceptions/unknown_hook_present.rb +5 -2
- data/lib/git_hooks/installer.rb +23 -12
- data/lib/git_hooks/version.rb +1 -1
- data/spec/git_hooks/installer_spec.rb +34 -54
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75034e9d934e19aee6f2737af93677be3aff90cd
|
4
|
+
data.tar.gz: a619eaf1a0d4e4b67b13c14537ec937592ee29bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5695f03af3ffbde6a7991a0f9845fca7d5184b329485a9c2e66254eebf339f13c8905c6c3d7b882cff61d6fc6ba7e5be3e8fb2a9ac7d337f5cef56d362db30c0
|
7
|
+
data.tar.gz: 43154d5d0cb3f0ca6efcf6ab6c205f749f128034fc2386039efc6cfb4a4fdc0d18815861c7fa31ede8e15654079c6615b3e4a8d8f4dad54d710aa008c1993be4
|
data/README.md
CHANGED
@@ -63,7 +63,24 @@ application's start-up code (e.g. `config/environments/development.rb` or
|
|
63
63
|
GitHooks.validate_hooks!
|
64
64
|
```
|
65
65
|
|
66
|
-
This will force `git_hooks` installation before your application
|
66
|
+
This will force `git_hooks` installation before you can run your application. Be
|
67
|
+
sure not to call `GitHooks#validate_hooks!` on production environments though!
|
68
|
+
|
69
|
+
### Problems with ruby version
|
70
|
+
|
71
|
+
If you run `git` under other systems such as `gitk` or Emacs' `Magit`, you may
|
72
|
+
encounter problems with the ruby version being used to run `GitHooks`. This
|
73
|
+
happens because those applications don't source the `~/.bashrc` file, which is
|
74
|
+
required by ruby version managers such as `Rbenv` and `Rvm`.
|
75
|
+
|
76
|
+
In order to fix this problem, you can install the hooks by passing your ruby
|
77
|
+
path to the `--ruby_path` option. For example:
|
78
|
+
|
79
|
+
```sh
|
80
|
+
$ git_hooks install pre-commit --ruby_path `which ruby`
|
81
|
+
```
|
82
|
+
|
83
|
+
You can also manually edit the `.git/hooks/{hook-name}` file though.
|
67
84
|
|
68
85
|
## Contributing
|
69
86
|
|
data/lib/git_hooks/cli.rb
CHANGED
@@ -6,13 +6,15 @@ module GitHooks
|
|
6
6
|
class CLI < Thor
|
7
7
|
desc 'install HOOK', 'Install some hook'
|
8
8
|
option :force, type: :boolean
|
9
|
+
option :ruby_path, type: :string
|
9
10
|
long_desc <<-LONGDESC
|
10
11
|
Install some hook:
|
11
12
|
|
12
13
|
$ git_hooks install pre-commit
|
13
14
|
LONGDESC
|
14
15
|
def install(hook)
|
15
|
-
GitHooks::Installer.new(hook
|
16
|
+
GitHooks::Installer.new(hook, options[:ruby_path])
|
17
|
+
.install(options[:force])
|
16
18
|
end
|
17
19
|
|
18
20
|
desc 'Init GitHooks on current folder', 'Create a configuration file'
|
@@ -1,8 +1,11 @@
|
|
1
1
|
module GitHooks
|
2
2
|
module Exceptions
|
3
|
-
class
|
3
|
+
class UnknownHookPresent < RuntimeError
|
4
4
|
def initialize(hook)
|
5
|
-
super
|
5
|
+
super <<-HEREDOC
|
6
|
+
There is already a #{hook} hook installed.
|
7
|
+
If you want to override it, use the --force option.
|
8
|
+
HEREDOC
|
6
9
|
end
|
7
10
|
end
|
8
11
|
end
|
data/lib/git_hooks/installer.rb
CHANGED
@@ -1,33 +1,44 @@
|
|
1
1
|
module GitHooks
|
2
2
|
class Installer
|
3
|
-
attr_accessor :hook
|
4
|
-
|
5
3
|
HOOK_SAMPLE_FILE = 'hook.sample'
|
6
4
|
|
7
|
-
def initialize(hook)
|
5
|
+
def initialize(hook, ruby_path = nil)
|
8
6
|
@hook = hook
|
7
|
+
@ruby_path = ruby_path
|
9
8
|
end
|
10
9
|
|
11
10
|
def install(force = false)
|
12
|
-
|
11
|
+
throw Exceptions::UnknownHookPresent.new(hook) if !force && installed?
|
12
|
+
|
13
|
+
hook_script = hook_template
|
14
|
+
hook_script.gsub!('/usr/bin/env ruby', ruby_path) if ruby_path
|
15
|
+
|
16
|
+
File
|
17
|
+
.open(hook_path, 'w')
|
18
|
+
.write(hook_script)
|
13
19
|
|
14
|
-
FileUtils.
|
15
|
-
hook_template_path, File.join('.git', 'hooks', hook), force: force
|
16
|
-
)
|
17
|
-
rescue Errno::EEXIST
|
18
|
-
raise GitHooks::Exceptions::UnknowHookPresent, hook
|
20
|
+
FileUtils.chmod(0775, hook_path)
|
19
21
|
end
|
20
22
|
|
21
23
|
def installed?
|
22
|
-
|
23
|
-
|
24
|
-
File.symlink?(hook_file) && File.realpath(hook_file) == hook_template_path
|
24
|
+
File.exist?(hook_path) &&
|
25
|
+
File.read(hook_path).match(/GitHooks.execute_pre_commits/)
|
25
26
|
end
|
26
27
|
|
27
28
|
private
|
28
29
|
|
30
|
+
attr_accessor :hook, :ruby_path
|
31
|
+
|
32
|
+
def hook_template
|
33
|
+
File.read(hook_template_path)
|
34
|
+
end
|
35
|
+
|
29
36
|
def hook_template_path
|
30
37
|
File.join(GitHooks.base_path, HOOK_SAMPLE_FILE)
|
31
38
|
end
|
39
|
+
|
40
|
+
def hook_path
|
41
|
+
File.join('.git', 'hooks', hook)
|
42
|
+
end
|
32
43
|
end
|
33
44
|
end
|
data/lib/git_hooks/version.rb
CHANGED
@@ -3,68 +3,55 @@ describe GitHooks::Installer do
|
|
3
3
|
|
4
4
|
let(:hook) { 'pre-commit' }
|
5
5
|
|
6
|
-
let(:
|
6
|
+
let(:hook_template_path) do
|
7
7
|
File.join(GitHooks.base_path, 'hook.sample')
|
8
8
|
end
|
9
9
|
|
10
|
-
let(:
|
11
|
-
File.join(
|
10
|
+
let(:hook_path) do
|
11
|
+
File.join('.git', 'hooks', hook)
|
12
12
|
end
|
13
13
|
|
14
14
|
let(:git_hook_path) { ".git/hooks/#{hook}" }
|
15
|
+
let(:file) { instance_double(File, write: true) }
|
16
|
+
|
17
|
+
before do
|
18
|
+
allow(File).to receive(:open).and_return(file)
|
19
|
+
allow(FileUtils).to receive(:chmod).and_return(true)
|
20
|
+
end
|
15
21
|
|
16
22
|
describe '#install' do
|
17
23
|
subject(:install) { installer.install }
|
18
24
|
|
25
|
+
let(:installed?) { false }
|
26
|
+
|
19
27
|
before do
|
20
|
-
allow(installer).to receive(:installed?)
|
21
|
-
|
28
|
+
allow(installer).to receive(:installed?)
|
29
|
+
.and_return(installed?)
|
22
30
|
end
|
23
31
|
|
24
|
-
it 'creates
|
25
|
-
expect(
|
26
|
-
.
|
27
|
-
|
32
|
+
it 'creates a new file' do
|
33
|
+
expect(File).to receive(:open)
|
34
|
+
.with(hook_path, 'w')
|
35
|
+
|
36
|
+
expect(file).to receive(:write)
|
37
|
+
.with(/GitHooks.execute_pre_commits/)
|
28
38
|
|
29
39
|
install
|
30
40
|
end
|
31
41
|
|
32
42
|
it { is_expected.to be_truthy }
|
33
43
|
|
34
|
-
context 'when there is a unknown hook' do
|
35
|
-
before do
|
36
|
-
allow(FileUtils).to receive(:symlink).and_raise(Errno::EEXIST)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'raises an error' do
|
40
|
-
expect { install }.to raise_error(
|
41
|
-
GitHooks::Exceptions::UnknowHookPresent
|
42
|
-
)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
44
|
context 'when there is a unknown hook but I want to force installation' do
|
47
|
-
subject(:install) { installer.install
|
45
|
+
subject(:install) { installer.install(true) }
|
48
46
|
|
49
|
-
|
50
|
-
expect(FileUtils)
|
51
|
-
.to receive(:symlink)
|
52
|
-
.with(hook_real_path, git_hook_path, force: true)
|
53
|
-
|
54
|
-
install
|
55
|
-
end
|
47
|
+
let(:installed?) { true }
|
56
48
|
|
57
|
-
it
|
58
|
-
|
59
|
-
|
60
|
-
context 'when hook is already installed' do
|
61
|
-
before do
|
62
|
-
allow(installer).to receive(:installed?).and_return(true)
|
63
|
-
end
|
49
|
+
it 'creates symlink with force option' do
|
50
|
+
expect(File).to receive(:open)
|
51
|
+
.with(hook_path, 'w')
|
64
52
|
|
65
|
-
|
66
|
-
|
67
|
-
.to_not receive(:symlink)
|
53
|
+
expect(file).to receive(:write)
|
54
|
+
.with(/GitHooks.execute_pre_commits/)
|
68
55
|
|
69
56
|
install
|
70
57
|
end
|
@@ -76,29 +63,22 @@ describe GitHooks::Installer do
|
|
76
63
|
describe '#installed?' do
|
77
64
|
subject(:installed?) { installer.installed? }
|
78
65
|
|
79
|
-
let(:symlink?) { true }
|
80
|
-
|
81
66
|
before do
|
82
|
-
allow(File).to receive(:
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'validates file is a symlink' do
|
87
|
-
expect(File).to receive(:symlink?).with(absolute_path)
|
88
|
-
installed?
|
67
|
+
allow(File).to receive(:read)
|
68
|
+
.and_return('GitHooks.execute_pre_commits')
|
89
69
|
end
|
90
70
|
|
91
71
|
it { is_expected.to be_truthy }
|
92
72
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
it { is_expected.to be_falsy }
|
73
|
+
it do
|
74
|
+
expect(File).to receive(:exist?).with(hook_path)
|
75
|
+
installed?
|
97
76
|
end
|
98
77
|
|
99
|
-
context 'when
|
78
|
+
context 'when the hook does not validate pre_commits' do
|
100
79
|
before do
|
101
|
-
allow(File).to receive(:
|
80
|
+
allow(File).to receive(:read)
|
81
|
+
.and_return('echo yolo')
|
102
82
|
end
|
103
83
|
|
104
84
|
it { is_expected.to be_falsy }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-hooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael da Silva Almeida
|
@@ -193,9 +193,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
193
193
|
version: '0'
|
194
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
195
|
requirements:
|
196
|
-
- - "
|
196
|
+
- - ">"
|
197
197
|
- !ruby/object:Gem::Version
|
198
|
-
version:
|
198
|
+
version: 1.3.1
|
199
199
|
requirements: []
|
200
200
|
rubyforge_project:
|
201
201
|
rubygems_version: 2.2.2
|