set_git_hooks_dir 0.0.1 → 0.0.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/set_git_hooks_dir.rb +14 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c453c927ba91e975f82038f243659bd8ce3e4c3952037f57f157ae17aa61901f
4
- data.tar.gz: 7d9bf653b056ddbc9ca291c96a97b9dde582d97cab7abdc4a13c4331f13af848
3
+ metadata.gz: 728a716834b5a66308df7196b7bff2ed98b519b4835883ff35f85a3fde2e9a9d
4
+ data.tar.gz: 698469d8c9c61fa1afc7313cb6dbae554592fea1abd1f9666cc224351e3edbb4
5
5
  SHA512:
6
- metadata.gz: 8e736702e4bb813a84e5e9cec0c96fd3e8ec57fa5fb7afa0fcbf13636c469d3bc73b8f804c3c79ceda572201fc95e2385b81155eb5695c4c3e54e4a6f48afed7
7
- data.tar.gz: f80be12174ad37609cdb657996c33b50c66dcbc4c3db02f0772a41f909d06f01a7ffba557362fae63bc3313deb91d3da005e5872c730297e488995d428b8b79f
6
+ metadata.gz: 80bcd8b71254f5425f1718bc6cd585cd0ccc12db4cb12b5759fd66f96e2c61a20ede4d87d64cb534cf4b10ba6f8ba3f867f41816009ce9787c84caa930862d58
7
+ data.tar.gz: 61a0f90313a476af665dbba168922b53d92d979c7d425c59e66329aed4d6a1fa6ab0715e6138ba0225c6fa61d8b3d3aa5aa685733640a24e3c2ad119b84b1f5a
@@ -7,7 +7,12 @@ class SetGitHooksDir
7
7
  SKIP_ENV_VARS = %w[SET_GIT_HOOKS_DIR_SKIP GITHUB_ACTION CI JENKINS_URL].freeze
8
8
 
9
9
  def setup(hooks_dir)
10
- return if SKIP_ENV_VARS.lazy.filter_map { |n| ENV[n] }.any? { |v| !v.empty? }
10
+ if SKIP_ENV_VARS.lazy.filter_map { |n| ENV[n] }.any? { |v| !v.empty? }
11
+ puts 'CI environment is detected. Skip setting Git hooks'
12
+ return
13
+ end
14
+
15
+ puts "Start setting hooks directory: #{hooks_dir}"
11
16
 
12
17
  hooks_dir = Pathname.new hooks_dir
13
18
  cwd = Pathname.pwd
@@ -15,13 +20,20 @@ class SetGitHooksDir
15
20
  .filter_map { |dir| dir + '.git' if (dir + hooks_dir).directory? }
16
21
  .find { |dotgit| dotgit.exist? }
17
22
 
23
+ puts "Repository config directory: #{dotgit}"
24
+
18
25
  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 = ")
26
+ if dotgit.directory? && File.read(dotgit + 'config').include?("\n\thooksPath = ")
27
+ puts 'core.hooksPath is already set. Skip setting Git hooks'
28
+ return
29
+ end
20
30
 
21
31
  git = ENV['SET_GIT_HOOKS_DIR_GIT']
22
32
  git = 'git' if git.nil? || git.empty?
33
+ puts "Running `#{git} config core.hooksPath #{hooks_dir}`"
23
34
  out = `#{git} config core.hooksPath #{hooks_dir}`
24
35
  raise StandardError.new("`#{git} config core.hooksPath #{hooks_dir}` failed with status #{$?.exitstatus}: #{out}") unless $?.success?
36
+ puts 'Done!'
25
37
  end
26
38
  end
27
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: set_git_hooks_dir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - rhysd