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.
- checksums.yaml +4 -4
- data/lib/set_git_hooks_dir.rb +14 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 728a716834b5a66308df7196b7bff2ed98b519b4835883ff35f85a3fde2e9a9d
|
4
|
+
data.tar.gz: 698469d8c9c61fa1afc7313cb6dbae554592fea1abd1f9666cc224351e3edbb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80bcd8b71254f5425f1718bc6cd585cd0ccc12db4cb12b5759fd66f96e2c61a20ede4d87d64cb534cf4b10ba6f8ba3f867f41816009ce9787c84caa930862d58
|
7
|
+
data.tar.gz: 61a0f90313a476af665dbba168922b53d92d979c7d425c59e66329aed4d6a1fa6ab0715e6138ba0225c6fa61d8b3d3aa5aa685733640a24e3c2ad119b84b1f5a
|
data/lib/set_git_hooks_dir.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|