git-catch 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.git-catch.yaml +6 -3
- data/bin/git-catch +19 -2
- data/lib/git/catch.rb +50 -12
- data/lib/git/catch/version.rb +1 -1
- data/utils/git/hooks/pre-commit/hello +4 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b09222b9f58a5dc0c78e9acc48b498a176f1944d
|
4
|
+
data.tar.gz: 840f13b5ff3c45a1db4d4b63812a589320528c30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e44c2651e935ef444a1b097264a14a3667ea4dee4361843bd8fa9e8dbd979d6f31e276558f55c46b5ab1fb102da32b2594700d0151d19866be4c9ea0c504e33
|
7
|
+
data.tar.gz: 6590c2eedbe4a97fa9f4a131b548b9c2b07d38ab278f6e2504ad7bc0110edefed71766b1b7771783709e5ab16aa6a511c1f52b04ee1068a1fedfb7dfd1869511
|
data/.git-catch.yaml
CHANGED
data/bin/git-catch
CHANGED
@@ -8,10 +8,27 @@ module Git
|
|
8
8
|
module Catch
|
9
9
|
class Cli < Thor
|
10
10
|
|
11
|
+
def initialize(args = [], local_options = {}, config = {})
|
12
|
+
super(args)
|
13
|
+
@runner = Runner.new
|
14
|
+
end
|
15
|
+
|
11
16
|
desc "init", "Hooks up the git hooks"
|
12
17
|
def init
|
13
|
-
puts "==>
|
14
|
-
|
18
|
+
puts "==> Initializing git hooks"
|
19
|
+
@runner.init()
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "ls", "Lists all git hooks"
|
23
|
+
def ls
|
24
|
+
puts "==> Listing all git hooks"
|
25
|
+
@runner.list().each do |hook, files|
|
26
|
+
puts "#{hook}:"
|
27
|
+
files.each do |f|
|
28
|
+
puts "- #{f}"
|
29
|
+
end
|
30
|
+
puts
|
31
|
+
end
|
15
32
|
end
|
16
33
|
|
17
34
|
end
|
data/lib/git/catch.rb
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
require "yaml"
|
2
|
+
require "logger"
|
2
3
|
require "fileutils"
|
3
4
|
|
4
|
-
require "git/catch/version"
|
5
|
-
|
6
|
-
|
7
5
|
module Git
|
8
6
|
module Catch
|
9
7
|
class Runner
|
10
8
|
|
11
|
-
def
|
12
|
-
|
9
|
+
def initialize
|
10
|
+
@logger = Logger.new(STDOUT)
|
11
|
+
@logger.formatter = proc do |type, time, name, message|
|
12
|
+
"[#{time}] #{type.ljust(5)} #{message}\n"
|
13
|
+
end
|
14
|
+
@config = YAML.load_file("./.git-catch.yaml")
|
15
|
+
@dir = @config.fetch("dir", nil)
|
16
|
+
@hooks = [
|
13
17
|
"applypatch-msg",
|
14
18
|
"commit-msg",
|
15
19
|
"post-update",
|
@@ -20,22 +24,44 @@ module Git
|
|
20
24
|
"prepare-commit-msg",
|
21
25
|
"update",
|
22
26
|
]
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
end
|
28
|
+
|
29
|
+
def init
|
30
|
+
@config.fetch("hooks", {}).each do |name, _|
|
31
|
+
if !@hooks.include? name
|
32
|
+
@logger.error "Hook #{name} is not known."
|
27
33
|
next
|
28
34
|
end
|
29
|
-
build name, files
|
35
|
+
build name, files(name)
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
39
|
+
def list
|
40
|
+
data = {}
|
41
|
+
@config.fetch("hooks", {}).each do |name, _|
|
42
|
+
if !@hooks.include? name
|
43
|
+
@logger.error "Hook #{name} is not known."
|
44
|
+
next
|
45
|
+
end
|
46
|
+
|
47
|
+
data[name] = files(name)
|
48
|
+
end
|
49
|
+
|
50
|
+
data
|
51
|
+
end
|
52
|
+
|
33
53
|
private
|
54
|
+
def files(name)
|
55
|
+
files = @config.fetch("hooks", {}).fetch(name, [])
|
56
|
+
files = (files + dir_files(@dir, name)).uniq if @dir
|
57
|
+
files
|
58
|
+
end
|
59
|
+
|
34
60
|
def build(name, files)
|
35
61
|
file = ".git/hooks/#{name}"
|
36
62
|
content = <<~EOS
|
37
63
|
#!/usr/bin/env bash
|
38
|
-
set -
|
64
|
+
set -e
|
39
65
|
|
40
66
|
EOS
|
41
67
|
files.each do |file|
|
@@ -43,7 +69,19 @@ module Git
|
|
43
69
|
end
|
44
70
|
File.write file, content
|
45
71
|
FileUtils.chmod "+x", file
|
46
|
-
|
72
|
+
@logger.info "File #{file} written"
|
73
|
+
end
|
74
|
+
|
75
|
+
def dir_files(dir, hook)
|
76
|
+
files = []
|
77
|
+
Dir["#{dir}/#{hook}/**/*"].each do |f|
|
78
|
+
if not File.executable? f
|
79
|
+
@logger.warn "File #{f} is not executable"
|
80
|
+
next
|
81
|
+
end
|
82
|
+
files << f
|
83
|
+
end
|
84
|
+
files
|
47
85
|
end
|
48
86
|
|
49
87
|
end
|
data/lib/git/catch/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-catch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Barbosa
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- git-catch.gemspec
|
72
72
|
- lib/git/catch.rb
|
73
73
|
- lib/git/catch/version.rb
|
74
|
+
- utils/git/hooks/pre-commit/hello
|
74
75
|
homepage: https://github.com/jpedro/git-catch
|
75
76
|
licenses:
|
76
77
|
- MIT
|