git-hookshot 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 38a586de567df197046bb142aef1928af9e6f49b
4
+ data.tar.gz: 35d0acecec864c5517763e76b4a7d4fea4a95d8f
5
+ SHA512:
6
+ metadata.gz: ab46b3db0ad3b92024245ebebf086ce90cf6bff608e7edc07c714d9c8f52248fc3a76b4ae6a2c945367b0fcdd0c4ab0d93e76bd3fdca14827a8ca87aad32b02d
7
+ data.tar.gz: e0ab3c33a2495720c815151525386a75e3a2815135468e780cb693a5bcf8b2d2c341474e87a934c17f279fbfe9282dbed76c59d2ebd6dd863935ff4ce0609f28
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ /.rubocop-*
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ inherit_from: "https://raw.githubusercontent.com/brandonweiss/rubocop-config/6265b818701ec1d8d91dfc39514c0bd074f3af82/default.yml"
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.3
5
+ Exclude:
6
+ - "bin/*"
7
+ - "exe/*"
8
+ - "vendor/**/*"
9
+
10
+ Layout/EmptyLinesAroundBlockBody:
11
+ Exclude:
12
+ - "test/**/*"
13
+
14
+ Style/FileName:
15
+ Exclude:
16
+ - "lib/git-hookshot.rb"
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.1
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ script:
2
+ - bundle exec rubocop
3
+ - bundle exec rake test
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in git-hookshot.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ git-hookshot (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ansi (1.5.0)
10
+ builder (3.2.3)
11
+ fakefs (0.11.0)
12
+ minitest (5.10.3)
13
+ minitest-reporters (1.1.14)
14
+ ansi
15
+ builder
16
+ minitest (>= 5.0)
17
+ ruby-progressbar
18
+ rake (12.0.0)
19
+ ruby-progressbar (1.8.1)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.13)
26
+ fakefs (~> 0.11.0)
27
+ git-hookshot!
28
+ minitest (~> 5.10.3)
29
+ minitest-reporters (~> 1.1.14)
30
+ rake (~> 12.0.0)
31
+
32
+ BUNDLED WITH
33
+ 1.15.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Brandon Weiss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # git-hookshot
2
+
3
+ <img src="https://cloud.githubusercontent.com/assets/4727/20847858/9d3c4ef8-b884-11e6-8bcc-8c2c493c60b3.png" width="60%">
4
+
5
+ git-hookshot allows you to share git hooks in Ruby projects among all the collaborators _automatically_, without them having to do anything. It automatically symLINKs them to the internal git hooks directory when installing gems with Bundler.
6
+
7
+ There are several other tools somewhat similar to this, but all of them require each collaborator working on a repository to run a specific command that generates the git hooks, and if they don’t then nothing happens. On a large project that can result in an untenable situation where unintentionally everyone has a different development experience.
8
+
9
+ npm has install hooks that can be easily hooked into it but Bundler and RubyGems don’t really. And yet a way has been found…
10
+
11
+ ⚠️ **Caveat emptor** ⚠️
12
+
13
+ This entire gem runs on 🔮 dark magic 🔮. What it does isn’t intended to be possible to do, but it draws on the arcane power of defining gem install hooks _inside_ the gemspec in order to setup the git hooks during bundling and then dynamically overwrite the `post_install_message` in order to surface the explanatory output from the depths of where the gem install hook is called. I wouldn’t think too much about it. _If you gaze long into an abyss, the abyss also gazes into you._
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application’s Gemfile:
18
+
19
+ ```ruby
20
+ gem "git-hookshot"
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ ```shell
26
+ $ bundle
27
+ ```
28
+
29
+ Or install it yourself as:
30
+
31
+ ```shell
32
+ $ gem install git-hookshot
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ git-hookshot is automatically run when bundling and will figure out what the right thing to do is given the state of your git hooks.
38
+
39
+ If you’re the first person to start using git-hookshot and you have no shared hooks, it will create empty shared hooks in `.hooks/` and symlink them to the internal git hook files at `.git/hooks/`. If you have existing internal git hooks they will be safely moved out of the way and a suffix of `.old` will be added to them.
40
+
41
+ You should add whatever logic you want to whatever hooks you want and then commit them to the repository.
42
+
43
+ When another collaborator pulls your changes which add git-hookshot and the shared git hooks Bundler will complain that there are new gems that need to be installed. When they bundle, git-hookshot will see the shared git hooks and create symlinks to the internal git hooks directory, enabling the shared git hooks. Collaborators don’t have to do anything extra—it just works.
44
+
45
+ git-hookshot can also be manually called with `bundle exec git-hookshot` if you need to re-generate a symlink or something.
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/brandonweiss/git-hookshot.
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hookshot"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/git-hookshot ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
4
+ require "git-hookshot"
5
+
6
+ Hookshot.link
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+ # coding: utf-8
3
+
4
+ lib = File.expand_path("../lib", __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require "hookshot/version"
7
+
8
+ Gem.pre_install do |installer|
9
+ require "hookshot"
10
+
11
+ output = Hookshot.with_captured_stdout do
12
+ current_working_directory = `lsof -p #{Process.ppid} | grep cwd`.split(" ").last
13
+ Hookshot.link(current_working_directory: current_working_directory)
14
+ end
15
+
16
+ installer.spec.post_install_message = output
17
+ end
18
+
19
+ Gem::Specification.new do |spec|
20
+ spec.name = "git-hookshot"
21
+ spec.version = Hookshot::VERSION
22
+ spec.authors = ["Brandon Weiss"]
23
+ spec.email = ["desk@brandonweiss.me"]
24
+
25
+ spec.summary = "Share git hooks in Ruby projects among all the collaborators automatically"
26
+ spec.description = "Share git hooks in Ruby projects among all the collaborators automatically, without them having to do anything"
27
+ spec.homepage = "https://github.com/brandonweiss/git-hookshot"
28
+ spec.license = "MIT"
29
+
30
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
31
+ f.match(%r{^(test|spec|features)/})
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_development_dependency "bundler", "~> 1.13"
38
+ spec.add_development_dependency "rake", "~> 12.0.0"
39
+ spec.add_development_dependency "minitest", "~> 5.10.3"
40
+ spec.add_development_dependency "minitest-reporters", "~> 1.1.14"
41
+ spec.add_development_dependency "fakefs", "~> 0.11.0"
42
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hookshot"
data/lib/hookshot.rb ADDED
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hookshot/git_hook"
4
+ require "hookshot/git_hooks_directory"
5
+ require "hookshot/hook"
6
+ require "hookshot/hooks_directory"
7
+ require "hookshot/version"
8
+
9
+ require "pathname"
10
+ require "fileutils"
11
+
12
+ module Hookshot
13
+
14
+ def self.link(current_working_directory: nil)
15
+ @current_working_directory = current_working_directory
16
+
17
+ HooksDirectory.create_with_default_hooks unless HooksDirectory.exists?
18
+
19
+ HooksDirectory.hooks.each do |hook|
20
+ git_hook = GitHook.new(name: hook.name)
21
+
22
+ next if git_hook.symlink?
23
+ git_hook.backup if git_hook.file?
24
+
25
+ git_hook.symlink(to: hook)
26
+ end
27
+ end
28
+
29
+ def self.current_working_directory
30
+ path = @current_working_directory || Dir.pwd
31
+ Pathname.new(path)
32
+ end
33
+
34
+ def self.with_captured_stdout
35
+ old_stdout = $stdout
36
+ $stdout = StringIO.new
37
+ yield
38
+ $stdout.string
39
+ ensure
40
+ $stdout = old_stdout
41
+ end
42
+
43
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hookshot
4
+ class GitHook
5
+
6
+ def initialize(name:)
7
+ @name = name
8
+ end
9
+
10
+ def symlink?
11
+ File.symlink?(path)
12
+ end
13
+
14
+ def file?
15
+ File.exist?(path)
16
+ end
17
+
18
+ def backup
19
+ puts "Existing #{path} found, moving to #{path}.old…"
20
+ FileUtils.move(path, "#{path}.old")
21
+ end
22
+
23
+ def symlink(to:)
24
+ puts "Symlinking #{path} to #{to.path}…"
25
+ File.symlink(to.path.to_s, path.to_s)
26
+ end
27
+
28
+ private def path
29
+ GitHooksDirectory.path.join(@name)
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hookshot
4
+ module GitHooksDirectory
5
+
6
+ def self.path
7
+ Hookshot.current_working_directory.join(".git/hooks")
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hookshot
4
+ class Hook
5
+
6
+ attr_reader :name
7
+
8
+ def initialize(name:)
9
+ @name = name
10
+ end
11
+
12
+ def create
13
+ puts "Creating empty #{@name} hook at #{path}…"
14
+ FileUtils.touch(path)
15
+ end
16
+
17
+ def path
18
+ HooksDirectory.path.join(@name)
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hookshot
4
+ module HooksDirectory
5
+
6
+ DEFAULT_HOOK_NAMES = %w[
7
+ applypatch-msg
8
+ commit-msg
9
+ post-applypatch
10
+ post-checkout
11
+ post-commit
12
+ post-merge
13
+ post-receive
14
+ post-rewrite
15
+ post-update
16
+ pre-applypatch
17
+ pre-auto-gc
18
+ pre-commit
19
+ pre-push
20
+ pre-rebase
21
+ pre-receive
22
+ prepare-commit-msg
23
+ update
24
+ ].freeze
25
+
26
+ def self.exists?
27
+ Dir.exist?(path)
28
+ end
29
+
30
+ def self.create_with_default_hooks
31
+ create
32
+ create_default_hooks
33
+ end
34
+
35
+ private_class_method def self.create
36
+ puts "`.hooks` directory not found. Creating it…"
37
+ Dir.mkdir(path.to_s)
38
+ end
39
+
40
+ private_class_method def self.create_default_hooks
41
+ DEFAULT_HOOK_NAMES.each do |git_hook|
42
+ Hook.new(name: git_hook).create
43
+ end
44
+ end
45
+
46
+ def self.hooks
47
+ Dir.glob("#{path}/*").map do |file|
48
+ Hook.new(name: File.basename(file))
49
+ end
50
+ end
51
+
52
+ def self.path
53
+ Hookshot.current_working_directory.join(".hooks")
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hookshot
4
+
5
+ VERSION = "0.1.0"
6
+
7
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-hookshot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Weiss
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 12.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 12.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 5.10.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 5.10.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-reporters
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.14
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.1.14
69
+ - !ruby/object:Gem::Dependency
70
+ name: fakefs
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.11.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.11.0
83
+ description: Share git hooks in Ruby projects among all the collaborators automatically,
84
+ without them having to do anything
85
+ email:
86
+ - desk@brandonweiss.me
87
+ executables:
88
+ - git-hookshot
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rubocop.yml"
94
+ - ".ruby-version"
95
+ - ".travis.yml"
96
+ - Gemfile
97
+ - Gemfile.lock
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bin/console
102
+ - bin/setup
103
+ - exe/git-hookshot
104
+ - git-hookshot.gemspec
105
+ - lib/git-hookshot.rb
106
+ - lib/hookshot.rb
107
+ - lib/hookshot/git_hook.rb
108
+ - lib/hookshot/git_hooks_directory.rb
109
+ - lib/hookshot/hook.rb
110
+ - lib/hookshot/hooks_directory.rb
111
+ - lib/hookshot/version.rb
112
+ homepage: https://github.com/brandonweiss/git-hookshot
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.6.11
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Share git hooks in Ruby projects among all the collaborators automatically
136
+ test_files: []