hookup 1.2.0 → 1.2.1

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.
Files changed (4) hide show
  1. data/README.markdown +9 -1
  2. data/hookup.gemspec +1 -1
  3. data/lib/hookup.rb +27 -7
  4. metadata +3 -3
@@ -30,7 +30,15 @@ migrations have been added, deleted, or modified. Deleted and modified
30
30
  migrations are given the `rake db:migrate:down` treatment, then `rake
31
31
  db:migrate` is invoked to bring everything else up to date.
32
32
 
33
- To force reloading the database if migrating fails, Add
33
+ Hookup provides a `-C` option to change to a specified directory prior to
34
+ running `bundle` or `rake`. This should be used if your `Gemfile` and
35
+ `Rakefile` are in a non-standard location.
36
+
37
+ To use a non-standard `db` directory (where `schema.rb` and `migrate/`
38
+ live), add `--schema-dir="database/path"` to the `hookup post-checkout`
39
+ line in `.git/hooks/post-checkout`.
40
+
41
+ To force reloading the database if migrating fails, add
34
42
  `--load-schema="rake db:reset"` to the `hookup post-checkout` line in
35
43
  `.git/hooks/post-checkout`.
36
44
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "hookup"
5
- s.version = "1.2.0"
5
+ s.version = "1.2.1"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Tim Pope"]
8
8
  s.email = ["code@tp"+'ope.net']
@@ -78,11 +78,25 @@ class Hookup
78
78
  @partial
79
79
  end
80
80
 
81
+ def schema_dir
82
+ File.expand_path(env['HOOKUP_SCHEMA_DIR'], working_dir)
83
+ end
84
+
85
+ def working_dir
86
+ env['HOOKUP_WORKING_DIR'] || '.'
87
+ end
88
+
81
89
  def initialize(environment, *args)
82
90
  @env ||= environment.to_hash.dup
83
91
  require 'optparse'
84
92
  opts = OptionParser.new
85
93
  opts.banner = "Usage: hookup post-checkout <old> <new> <full>"
94
+ opts.on('-Cdirectory', 'cd to directory') do |directory|
95
+ env['HOOKUP_WORKING_DIR'] = directory
96
+ end
97
+ opts.on('--schema-dir=DIRECTORY', 'Path to DIRECTORY containing schema.rb and migrate/') do |directory|
98
+ env['HOOKUP_SCHEMA_DIR'] = directory
99
+ end
86
100
  opts.on('--load-schema=COMMAND', 'Run COMMAND on migration failure') do |command|
87
101
  env['HOOKUP_LOAD_SCHEMA'] = command
88
102
  end
@@ -96,6 +110,8 @@ class Hookup
96
110
  end
97
111
  @new = args.shift || 'HEAD'
98
112
  @partial = (args.shift == '0')
113
+
114
+ env['HOOKUP_SCHEMA_DIR'] = 'db' unless schema_dir && File.directory?(schema_dir)
99
115
  end
100
116
 
101
117
  def run
@@ -119,7 +135,9 @@ class Hookup
119
135
  %x{bundle check}
120
136
  unless $?.success?
121
137
  puts "Bundling..."
122
- system("bundle | grep -v '^Using ' | grep -v ' is complete'")
138
+ Dir.chdir(working_dir) do
139
+ system("bundle | grep -v '^Using ' | grep -v ' is complete'")
140
+ end
123
141
  end
124
142
  ensure
125
143
  ENV['GIT_DIR'] = git_dir
@@ -128,7 +146,7 @@ class Hookup
128
146
  end
129
147
 
130
148
  def migrate
131
- schemas = %w(db/schema.rb db/development_structure.sql).select do |schema|
149
+ schemas = %W(#{schema_dir}/schema.rb #{schema_dir}/development_structure.sql).select do |schema|
132
150
  status = %x{git diff --name-status #{old} #{new} -- #{schema}}.chomp
133
151
  rake 'db:create' if status =~ /^A/
134
152
  status !~ /^D/ && !status.empty?
@@ -136,7 +154,7 @@ class Hookup
136
154
 
137
155
  return if schemas.empty?
138
156
 
139
- migrations = %x{git diff --name-status #{old} #{new} -- db/migrate}.scan(/.+/).map {|l| l.split(/\t/) }
157
+ migrations = %x{git diff --name-status #{old} #{new} -- #{schema_dir}/migrate}.scan(/.+/).map {|l| l.split(/\t/) }
140
158
  begin
141
159
  migrations.select {|(t,f)| %w(D M).include?(t)}.reverse.each do |type, file|
142
160
  begin
@@ -175,10 +193,12 @@ class Hookup
175
193
  end
176
194
 
177
195
  def rake(*args)
178
- if bundler?
179
- system 'bundle', 'exec', 'rake', *args
180
- else
181
- system 'rake', *args
196
+ Dir.chdir(working_dir) do
197
+ if bundler?
198
+ system 'bundle', 'exec', 'rake', *args
199
+ else
200
+ system 'rake', *args
201
+ end
182
202
  end
183
203
  end
184
204
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-21 00:00:00.000000000 Z
12
+ date: 2013-01-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Automatically bundle and migrate your Rails app when switching branches,
15
15
  merging upstream changes, and bisecting.
@@ -48,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  version: '0'
49
49
  requirements: []
50
50
  rubyforge_project: hookup
51
- rubygems_version: 1.8.11
51
+ rubygems_version: 1.8.23
52
52
  signing_key:
53
53
  specification_version: 3
54
54
  summary: Automate the bundle/migration tedium of Rails with Git hooks