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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: acfe4df3b3c7627d8693978e4504b1127ffeb8bf
4
- data.tar.gz: 8d2cab43d97f941b44071fe3dd8bdf013321832b
3
+ metadata.gz: b09222b9f58a5dc0c78e9acc48b498a176f1944d
4
+ data.tar.gz: 840f13b5ff3c45a1db4d4b63812a589320528c30
5
5
  SHA512:
6
- metadata.gz: 8f6732cf83f70c5d929e77de6061c5a93e1be6f3a2ff5892b7db3cd6d86ab1d9a4ef9c56b4f0b5f0bf524144c347bea9f181df9ab138025c7e2eeb31026f21c4
7
- data.tar.gz: 4865fba333a36ce0bf48791387a15d36d822c664f5861841c32ce4b3fa02a214f7823871a684b1d8372fc269106d14b1dda31a1a663922bbcb1e728c17df0b00
6
+ metadata.gz: 8e44c2651e935ef444a1b097264a14a3667ea4dee4361843bd8fa9e8dbd979d6f31e276558f55c46b5ab1fb102da32b2594700d0151d19866be4c9ea0c504e33
7
+ data.tar.gz: 6590c2eedbe4a97fa9f4a131b548b9c2b07d38ab278f6e2504ad7bc0110edefed71766b1b7771783709e5ab16aa6a511c1f52b04ee1068a1fedfb7dfd1869511
data/.git-catch.yaml CHANGED
@@ -1,4 +1,7 @@
1
1
  ---
2
- pre-commit:
3
- - test/pre-commit-1
4
- - test/pre-commit-2
2
+ dir: utils/git/hooks
3
+
4
+ hooks:
5
+ pre-commit:
6
+ - test/pre-commit-1
7
+ - test/pre-commit-2
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 "==> Init"
14
- Runner.new.init()
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 init
12
- hooks = [
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
- config = YAML.load_file("./.git-catch.yaml")
24
- config.each do |name, files|
25
- if !hooks.include? name
26
- puts "==> Hook #{name} is not known"
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 -eu
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
- puts "==> File #{file} written"
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
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Catch
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
4
4
  end
5
5
  end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env bash
2
+ set -eu
3
+
4
+ echo "==> HELLO!"
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
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