hookup 1.0.0

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.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ /.bundle
2
+ /Gemfile.lock
3
+ /pkg/*
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/README.markdown ADDED
@@ -0,0 +1,33 @@
1
+ Hookup
2
+ ======
3
+
4
+ Hookup takes care of Rails tedium like bundling and migrating through
5
+ Git hooks. It fires after events like
6
+
7
+ * pulling in upstream changes
8
+ * switching branches
9
+ * stepping through a bisect
10
+
11
+ Usage
12
+ -----
13
+
14
+ $ cd yourproject
15
+ $ gem install hookup
16
+ $ hookup install
17
+ Hooked up!
18
+
19
+ Bundling
20
+ --------
21
+
22
+ Each time your current HEAD changes, hookup checks to see if your
23
+ `Gemfile`, `Gemfile.lock`, or gem spec has changed. If so it runs
24
+ `bundle check`, and if that indicates any dependencies are unsatisfied,
25
+ it runs `bundle install`.
26
+
27
+ Migrating
28
+ ---------
29
+
30
+ Each time your current HEAD changes, hookup checks to see if any
31
+ migrations have been added, deleted, or modified. Deleted and modified
32
+ migrations are given the `rake db:migrate:down` treatment, then `rake
33
+ db:migrate` is invoked to bring everything else up to date.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/hookup ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ $:.push File.expand_path("../../lib", __FILE__)
3
+ require 'hookup'
4
+ Hookup.run(*ARGV)
data/hookup.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "hookup"
5
+ s.version = "1.0.0"
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = ["Tim Pope"]
8
+ s.email = ["code@tp"+'ope.net']
9
+ s.homepage = ""
10
+ s.summary = %q{Automate the bundle/migration tedium of Rails with Git hooks}
11
+ s.description = %q{Automatically bundle and migrate your Rails app when switching branches, merging upstream changes, and bisecting.}
12
+
13
+ s.rubyforge_project = "hookup"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+ end
data/lib/hookup.rb ADDED
@@ -0,0 +1,105 @@
1
+ class Hookup
2
+
3
+ class Error < RuntimeError
4
+ end
5
+
6
+ EMPTY_DIR = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
7
+
8
+ def self.run(*argv)
9
+ new.run(*argv)
10
+ rescue Error => e
11
+ puts e
12
+ exit 1
13
+ end
14
+
15
+ def run(*argv)
16
+ if argv.empty?
17
+ install
18
+ else
19
+ command = argv.shift
20
+ begin
21
+ send(command.tr('-', '_'), *argv)
22
+ rescue NoMethodError
23
+ raise Error, "Unknown command #{command}"
24
+ rescue ArgumentError
25
+ raise Error, "Invalid arguments for #{command}"
26
+ end
27
+ end
28
+ end
29
+
30
+ def install
31
+ dir = %x{git rev-parse --git-dir}.chomp
32
+ raise Error, dir unless $?.success?
33
+ hook = File.join(dir, 'hooks', 'post-checkout')
34
+ unless File.exist?(hook)
35
+ File.open(hook, 'w', 0777) do |f|
36
+ f.puts "#!/bin/bash"
37
+ end
38
+ end
39
+ if File.read(hook) =~ /^[^#]*\bhookup\b/
40
+ puts "Already hooked up!"
41
+ else
42
+ File.open(hook, "a") do |f|
43
+ f.puts %(hookup post-checkout "$@")
44
+ end
45
+ puts "Hooked up!"
46
+ end
47
+ end
48
+
49
+ def post_checkout(*args)
50
+ old, new = args.shift, args.shift || 'HEAD'
51
+ if old == '0000000000000000000000000000000000000000'
52
+ old = EMPTY_DIR
53
+ elsif old.nil?
54
+ old = '@{-1}'
55
+ end
56
+ bundle(old, new, *args)
57
+ migrate(old, new, *args)
58
+ end
59
+
60
+ def bundle(old, new, *args)
61
+ return unless File.exist?('Gemfile')
62
+ if %x{git diff --name-only #{old} #{new}} =~ /^Gemfile|\.gemspec$/
63
+ begin
64
+ # If Bundler in turn spawns Git, it can get confused by $GIT_DIR
65
+ git_dir = ENV.delete('GIT_DIR')
66
+ %x{bundle check}
67
+ unless $?.success?
68
+ puts "Bundling..."
69
+ system("bundle | grep -v '^Using ' | grep -v ' is complete'")
70
+ end
71
+ ensure
72
+ ENV['GIT_DIR'] = git_dir
73
+ end
74
+ end
75
+ end
76
+
77
+ def migrate(old, new, *args)
78
+ return if args.first == '0'
79
+
80
+ schema = %x{git diff --name-status #{old} #{new} -- db/schema.rb}
81
+ if schema =~ /^A/
82
+ system 'rake', 'db:create'
83
+ end
84
+
85
+ migrations = %x{git diff --name-status #{old} #{new} -- db/migrate}.scan(/.+/).map {|l| l.split(/\t/) }
86
+
87
+ migrations.select {|(t,f)| %w(D M).include?(t)}.reverse.each do |type, file|
88
+ begin
89
+ system 'git', 'checkout', old, '--', file
90
+ system 'rake', 'db:migrate:down', "VERSION=#{File.basename(file)}"
91
+ ensure
92
+ if type == 'D'
93
+ system 'git', 'rm', '--force', '--quiet', '--', file
94
+ else
95
+ system 'git', 'checkout', new, '--', file
96
+ end
97
+ end
98
+ end
99
+
100
+ if migrations.any? {|(t,f)| %w(A M).include?(t)}
101
+ system 'rake', 'db:migrate'
102
+ end
103
+ end
104
+
105
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hookup
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Tim Pope
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-04-08 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Automatically bundle and migrate your Rails app when switching branches, merging upstream changes, and bisecting.
22
+ email:
23
+ - code@tpope.net
24
+ executables:
25
+ - hookup
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - README.markdown
34
+ - Rakefile
35
+ - bin/hookup
36
+ - hookup.gemspec
37
+ - lib/hookup.rb
38
+ has_rdoc: true
39
+ homepage: ""
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project: hookup
66
+ rubygems_version: 1.3.7
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Automate the bundle/migration tedium of Rails with Git hooks
70
+ test_files: []
71
+