set_git_hooks_dir 0.0.7 → 1.0.0
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/lib/rubygems_plugin.rb +5 -1
- data/lib/set_git_hooks_dir.rb +17 -5
- data/plugins.rb +2 -2
- metadata +6 -8
- data/README.md +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17a2b4e038ed614e3fbf2e6e1c1c0d3dcf52823681ec56dfe57d4b39cdf2507c
|
4
|
+
data.tar.gz: 8420850fccb365c3c1c71951b408b3f818b3231bbd845ccff99eabebcfd94a83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7feb2af3d584f3ecff09b7cd11b90d51e84bd79ad171d80bc937c534df3ee15f2ec11c0f7f0e0e42f9823f52e94ff03b90d8e85403a85c0b144378fce02bc27
|
7
|
+
data.tar.gz: b9c60c54d89746c2405fb9caaca511a1c2a2cb63ece41e829a6fb36bfbf40ffd3b69e1670f98ca8711c3e401636c44f4d6e10586200fc0cc5aee01d41962532f
|
data/lib/rubygems_plugin.rb
CHANGED
@@ -4,5 +4,9 @@ require 'rubygems/installer'
|
|
4
4
|
require_relative 'set_git_hooks_dir'
|
5
5
|
|
6
6
|
Gem.post_install do |installer|
|
7
|
-
|
7
|
+
begin
|
8
|
+
SetGitHooksDir.setup '.git-hooks' if installer.spec.name == 'set_git_hooks_dir'
|
9
|
+
rescue StandardError => err
|
10
|
+
STDERR.puts "set_git_hooks_dir: #{err}"
|
11
|
+
end
|
8
12
|
end
|
data/lib/set_git_hooks_dir.rb
CHANGED
@@ -3,9 +3,21 @@
|
|
3
3
|
require 'pathname'
|
4
4
|
|
5
5
|
class SetGitHooksDir
|
6
|
-
class
|
7
|
-
|
6
|
+
class GitHooksDirNotFound < StandardError
|
7
|
+
def initialize(dir, cwd)
|
8
|
+
super "Git hooks directory #{dir} was not found at any root of GitHub repository in #{cwd}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class GitConfigHooksFailed < StandardError
|
13
|
+
def initialize(git, dir, status, output)
|
14
|
+
super "`#{git} config core.hooksPath #{dir}` failed with status #{status}: #{output}"
|
15
|
+
end
|
16
|
+
end
|
8
17
|
|
18
|
+
SKIP_ENV_VARS = %w[SET_GIT_HOOKS_DIR_SKIP GITHUB_ACTION CI JENKINS_URL].freeze
|
19
|
+
|
20
|
+
class << self
|
9
21
|
def setup(hooks_dir)
|
10
22
|
return if SKIP_ENV_VARS.lazy.filter_map { |n| ENV[n] }.any? { |v| !v.empty? }
|
11
23
|
|
@@ -15,13 +27,13 @@ class SetGitHooksDir
|
|
15
27
|
.filter_map { |dir| dir + '.git' if (dir + hooks_dir).directory? }
|
16
28
|
.find { |dotgit| dotgit.exist? }
|
17
29
|
|
18
|
-
raise
|
19
|
-
return if dotgit.directory? && File.
|
30
|
+
raise GitHooksDirNotFound.new(hooks_dir, cwd) unless dotgit
|
31
|
+
return if dotgit.directory? && File.foreach(dotgit + 'config').any? { |i| i.start_with? "\thooksPath = " }
|
20
32
|
|
21
33
|
git = ENV['SET_GIT_HOOKS_DIR_GIT']
|
22
34
|
git = 'git' if git.nil? || git.empty?
|
23
35
|
out = `#{git} config core.hooksPath #{hooks_dir}`
|
24
|
-
raise
|
36
|
+
raise GitConfigHooksFailed.new(git, hooks_dir, $?.exitstatus, out) unless $?.success?
|
25
37
|
end
|
26
38
|
end
|
27
39
|
end
|
data/plugins.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: set_git_hooks_dir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rhysd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: set_git_hooks_dir is a deadly simple gem to configure your Git hooks
|
14
14
|
on package installation
|
@@ -16,20 +16,18 @@ email:
|
|
16
16
|
- lin90162@yahoo.co.jp
|
17
17
|
executables: []
|
18
18
|
extensions: []
|
19
|
-
extra_rdoc_files:
|
20
|
-
- README.md
|
19
|
+
extra_rdoc_files: []
|
21
20
|
files:
|
22
21
|
- LICENSE
|
23
|
-
- README.md
|
24
22
|
- lib/rubygems_plugin.rb
|
25
23
|
- lib/set_git_hooks_dir.rb
|
26
24
|
- plugins.rb
|
27
|
-
homepage: https://
|
25
|
+
homepage: https://github.com/rhysd/set-git-hooks-dir
|
28
26
|
licenses:
|
29
27
|
- MIT
|
30
28
|
metadata:
|
31
|
-
homepage_uri: https://
|
32
|
-
source_code_uri: https://github.com/rhysd/set-git-hooks-dir
|
29
|
+
homepage_uri: https://github.com/rhysd/set-git-hooks-dir
|
30
|
+
source_code_uri: https://github.com/rhysd/set-git-hooks-dir/tree/main/ruby
|
33
31
|
post_install_message:
|
34
32
|
rdoc_options: []
|
35
33
|
require_paths:
|
data/README.md
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
`set_git_hooks_dir` Ruby package
|
2
|
-
================================
|
3
|
-
[![gem][gem-badge]][gem]
|
4
|
-
|
5
|
-
## Usage
|
6
|
-
|
7
|
-
See https://github.com/rhysd/set-git-hooks-dir#readme for the usage.
|
8
|
-
|
9
|
-
## Details
|
10
|
-
|
11
|
-
This gem aims to be used as both bundler and rubygems plugins so that this gem can hook the package installation and
|
12
|
-
configure Git hooks properly.
|
13
|
-
|
14
|
-
So why can't this gem be a simple rubygems plugin? The answer is that bundler doesn't run rubygems plugin's install
|
15
|
-
hooks on `bundle install`. bundler downloads gems from rubygems.org and stores the downloaded gems to the
|
16
|
-
[`BUNDLE_PATH`][path] directory and makes them loadable. However, this doesn't mean *installing* the gems. It just
|
17
|
-
*stores*. It is very confusing that `gem install` *installs* a gem but `bundle install` does not *install* a gem. The
|
18
|
-
following issue mentions this behavior:
|
19
|
-
|
20
|
-
https://github.com/rubygems/bundler/issues/5429
|
21
|
-
|
22
|
-
> Running `bundle install` with `path` gems does not install those gems. The `path` feature is a shortcut to add the
|
23
|
-
> path to `$LOAD_PATH`, and does not do any of the usual gem installation procedures.
|
24
|
-
|
25
|
-
The detailed behavior of this gem in each cases are as follows:
|
26
|
-
|
27
|
-
- On `bundle install`, this gem works as a bundler plugin. bundler loads the plugin on installation and it configures
|
28
|
-
Git hooks.
|
29
|
-
- On `gem install`, this gem works as a rubygems plugin. rubygems runs a install hook of the plugin and the hook
|
30
|
-
configures Git hooks.
|
31
|
-
|
32
|
-
## License
|
33
|
-
|
34
|
-
This npm package is distributed under [the MIT license](LICENSE).
|
35
|
-
|
36
|
-
[gem-badge]: https://img.shields.io/gem/v/set_git_hooks_dir
|
37
|
-
[gem]: https://rubygems.org/gems/set_git_hooks_dir
|
38
|
-
[path]: https://bundler.io/v1.12/man/bundle-config.1.html#LIST-OF-AVAILABLE-KEYS
|