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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 976195685caba3b76712236bc1bd6b7d47531ed7313dddfab5f2f3a29d8d8064
4
- data.tar.gz: 8d107ed8fa79b2b0933a6e8916b165518072058ba967c2938de1fbfadfff5e17
3
+ metadata.gz: 17a2b4e038ed614e3fbf2e6e1c1c0d3dcf52823681ec56dfe57d4b39cdf2507c
4
+ data.tar.gz: 8420850fccb365c3c1c71951b408b3f818b3231bbd845ccff99eabebcfd94a83
5
5
  SHA512:
6
- metadata.gz: 87fba99429a671ec0c18ef760864d8668dafe91be0b8597406d27e045d1f4fb362eb55aab0f7b065501cf3f9cd38d8540c425b64b5e80db5fb6be6b506e92183
7
- data.tar.gz: d617440c4336aaece2109608205a23a32abec4a9543142ed5cf517bccceeb31f06575f5e029b9b4c9a6dbd1049c2751e7f537e8a4342158d60b6d666f11b14bd
6
+ metadata.gz: f7feb2af3d584f3ecff09b7cd11b90d51e84bd79ad171d80bc937c534df3ee15f2ec11c0f7f0e0e42f9823f52e94ff03b90d8e85403a85c0b144378fce02bc27
7
+ data.tar.gz: b9c60c54d89746c2405fb9caaca511a1c2a2cb63ece41e829a6fb36bfbf40ffd3b69e1670f98ca8711c3e401636c44f4d6e10586200fc0cc5aee01d41962532f
@@ -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
- SetGitHooksDir.setup '.git-hooks' if installer.spec.name == 'set_git_hooks_dir'
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
@@ -3,9 +3,21 @@
3
3
  require 'pathname'
4
4
 
5
5
  class SetGitHooksDir
6
- class << self
7
- SKIP_ENV_VARS = %w[SET_GIT_HOOKS_DIR_SKIP GITHUB_ACTION CI JENKINS_URL].freeze
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 StandardError.new("Git hooks directory #{hooks_dir} was not found at any root of GitHub repository in #{cwd}") unless dotgit
19
- return if dotgit.directory? && File.read(dotgit + 'config').include?("\n\thooksPath = ")
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 StandardError.new("`#{git} config core.hooksPath #{hooks_dir}` failed with status #{$?.exitstatus}: #{out}") unless $?.success?
36
+ raise GitConfigHooksFailed.new(git, hooks_dir, $?.exitstatus, out) unless $?.success?
25
37
  end
26
38
  end
27
39
  end
data/plugins.rb CHANGED
@@ -14,6 +14,6 @@ require 'set_git_hooks_dir'
14
14
 
15
15
  begin
16
16
  SetGitHooksDir.setup '.git-hooks'
17
- rescue StandardError => exc
18
- raise Bundler::BundlerError.new exc.message
17
+ rescue StandardError => err
18
+ STDERR.puts "set_git_hooks_dir: #{err}"
19
19
  end
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.7
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-06-30 00:00:00.000000000 Z
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://rubygems.org/gems/set_git_hooks_dir
25
+ homepage: https://github.com/rhysd/set-git-hooks-dir
28
26
  licenses:
29
27
  - MIT
30
28
  metadata:
31
- homepage_uri: https://rubygems.org/gems/set_git_hooks_dir
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