hookup 1.2.2 → 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.markdown +10 -0
- data/hookup.gemspec +1 -1
- data/lib/hookup.rb +60 -13
- metadata +8 -11
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a003ee5a9f2e61b570aaf4d4006b37ac6269ced76eee42df20ab78ac930764de
|
4
|
+
data.tar.gz: 2c76b14b8d34af3b719051ca21ff175e9ad1209d99ec1bc3cc2e2123f4f851d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a7f7534b3ee8417f509699c602184156bb5347616c0904fff55245ac8c7a8ab5ce53cd9f64fa7c16d2d4d5b57c03f32d590385fc170fd9db64e5bdee1fd7a812
|
7
|
+
data.tar.gz: 28cfa49a9e6f3c06461ff5c04cc43fb14383812fbb966961e3e70567390cbd099ba5f1bf5067cfca960fc995615011b37f8ff734691be7a2fed2a5bc8ad02d53
|
data/README.markdown
CHANGED
@@ -48,6 +48,16 @@ Each time there's a conflict in `db/schema.rb` on the
|
|
48
48
|
`Rails::Schema.define` line, hookup resolves it in favor of the newer of
|
49
49
|
the two versions.
|
50
50
|
|
51
|
+
### Skip Hookup
|
52
|
+
|
53
|
+
Set the `SKIP_HOOKUP` environment variable to skip hookup.
|
54
|
+
|
55
|
+
SKIP_HOOKUP=1 git checkout master
|
56
|
+
|
57
|
+
### Removing Hookup
|
58
|
+
|
59
|
+
hookup remove
|
60
|
+
|
51
61
|
ChangeLog
|
52
62
|
---------
|
53
63
|
|
data/hookup.gemspec
CHANGED
data/lib/hookup.rb
CHANGED
@@ -36,27 +36,57 @@ class Hookup
|
|
36
36
|
def git_dir
|
37
37
|
unless @git_dir
|
38
38
|
@git_dir = %x{git rev-parse --git-dir}.chomp
|
39
|
-
raise Error
|
39
|
+
raise Error unless $?.success?
|
40
40
|
end
|
41
41
|
@git_dir
|
42
42
|
end
|
43
43
|
|
44
|
+
def bundler?
|
45
|
+
!!ENV['BUNDLE_GEMFILE']
|
46
|
+
end
|
47
|
+
|
48
|
+
def make_command(command)
|
49
|
+
bundler? ? command.insert(0, "bundle exec ") : command
|
50
|
+
end
|
51
|
+
|
52
|
+
def post_checkout_file
|
53
|
+
File.join(git_dir, 'hooks', 'post-checkout')
|
54
|
+
end
|
55
|
+
|
56
|
+
def info_attributes_file
|
57
|
+
File.join(git_dir, 'info', 'attributes')
|
58
|
+
end
|
59
|
+
|
44
60
|
def install
|
45
|
-
append(
|
61
|
+
append(post_checkout_file, 0777) do |body, f|
|
46
62
|
f.puts "#!/bin/bash" unless body
|
47
|
-
f.puts %(hookup post-checkout "$@") if body !~ /hookup/
|
63
|
+
f.puts make_command(%(hookup post-checkout "$@")) if body !~ /hookup/
|
48
64
|
end
|
49
65
|
|
50
|
-
append(
|
66
|
+
append(info_attributes_file) do |body, f|
|
51
67
|
map = 'db/schema.rb merge=railsschema'
|
52
68
|
f.puts map unless body.to_s.include?(map)
|
53
69
|
end
|
54
70
|
|
55
|
-
system 'git', 'config', 'merge.railsschema.driver', 'hookup resolve-schema %A %O %B %L'
|
71
|
+
system 'git', 'config', 'merge.railsschema.driver', make_command('hookup resolve-schema %A %O %B %L')
|
56
72
|
|
57
73
|
puts "Hooked up!"
|
58
74
|
end
|
59
75
|
|
76
|
+
def remove
|
77
|
+
body = IO.readlines(post_checkout_file)
|
78
|
+
body.reject! { |item| item =~ /hookup/ }
|
79
|
+
File.open(post_checkout_file, 'w') { |file| file.puts body.join }
|
80
|
+
|
81
|
+
body = IO.readlines(info_attributes_file)
|
82
|
+
body.reject! { |item| item =~ /railsschema/ }
|
83
|
+
File.open(info_attributes_file, 'w') { |file| file.puts body.join }
|
84
|
+
|
85
|
+
system 'git', 'config', '--unset', 'merge.railsschema.driver'
|
86
|
+
|
87
|
+
puts "Hookup removed!"
|
88
|
+
end
|
89
|
+
|
60
90
|
def append(file, *args)
|
61
91
|
Dir.mkdir(File.dirname(file)) unless File.directory?(File.dirname(file))
|
62
92
|
body = File.read(file) if File.exist?(file)
|
@@ -79,7 +109,13 @@ class Hookup
|
|
79
109
|
end
|
80
110
|
|
81
111
|
def schema_dir
|
82
|
-
File.
|
112
|
+
File.join(working_dir, env['HOOKUP_SCHEMA_DIR'])
|
113
|
+
end
|
114
|
+
|
115
|
+
def possible_schemas
|
116
|
+
%w(development_structure.sql schema.rb structure.sql).map do |file|
|
117
|
+
File.join schema_dir, file
|
118
|
+
end
|
83
119
|
end
|
84
120
|
|
85
121
|
def working_dir
|
@@ -115,7 +151,7 @@ class Hookup
|
|
115
151
|
end
|
116
152
|
|
117
153
|
def run
|
118
|
-
return if env['GIT_REFLOG_ACTION'] =~ /^(?:pull|rebase)/
|
154
|
+
return if skipped? || env['GIT_REFLOG_ACTION'] =~ /^(?:pull|rebase)/
|
119
155
|
unless partial?
|
120
156
|
bundle
|
121
157
|
migrate
|
@@ -146,7 +182,7 @@ class Hookup
|
|
146
182
|
end
|
147
183
|
|
148
184
|
def migrate
|
149
|
-
schemas =
|
185
|
+
schemas = possible_schemas.select do |schema|
|
150
186
|
status = %x{git diff --name-status #{old} #{new} -- #{schema}}.chomp
|
151
187
|
rake 'db:create' if status =~ /^A/
|
152
188
|
status !~ /^D/ && !status.empty?
|
@@ -194,7 +230,9 @@ class Hookup
|
|
194
230
|
|
195
231
|
def rake(*args)
|
196
232
|
Dir.chdir(working_dir) do
|
197
|
-
if
|
233
|
+
if File.executable?('bin/rake')
|
234
|
+
system 'bin/rake', *args
|
235
|
+
elsif bundler?
|
198
236
|
system 'bundle', 'exec', 'rake', *args
|
199
237
|
else
|
200
238
|
system 'rake', *args
|
@@ -202,19 +240,28 @@ class Hookup
|
|
202
240
|
end
|
203
241
|
end
|
204
242
|
|
243
|
+
def skipped?
|
244
|
+
env['SKIP_HOOKUP']
|
245
|
+
end
|
246
|
+
|
205
247
|
end
|
206
248
|
|
207
249
|
def resolve_schema(a, o, b, marker_size = 7)
|
208
250
|
system 'git', 'merge-file', "--marker-size=#{marker_size}", a, o, b
|
209
251
|
body = File.read(a)
|
210
|
-
|
211
|
-
|
212
|
-
"#{asd}(:version => #{[$1, $2].max}) do"
|
213
|
-
end
|
252
|
+
resolve_schema_version body, ":version =>"
|
253
|
+
resolve_schema_version body, "version:"
|
214
254
|
File.open(a, 'w') { |f| f.write(body) }
|
215
255
|
if body.include?('<' * marker_size.to_i)
|
216
256
|
raise Failure, 'Failed to automatically resolve schema conflict'
|
217
257
|
end
|
218
258
|
end
|
219
259
|
|
260
|
+
def resolve_schema_version(body, version)
|
261
|
+
asd = "ActiveRecord::Schema.define"
|
262
|
+
body.sub!(/^<+ .*\n#{asd}\(#{version} ([0-9_]+)\) do\n=+\n#{asd}\(#{version} ([0-9_]+)\) do\n>+ .*/) do
|
263
|
+
"#{asd}(#{version} #{[$1, $2].max}) do"
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
220
267
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hookup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
5
|
-
prerelease:
|
4
|
+
version: 1.2.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Tim Pope
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2022-06-27 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Automatically bundle and migrate your Rails app when switching branches,
|
15
14
|
merging upstream changes, and bisecting.
|
@@ -20,7 +19,7 @@ executables:
|
|
20
19
|
extensions: []
|
21
20
|
extra_rdoc_files: []
|
22
21
|
files:
|
23
|
-
- .gitignore
|
22
|
+
- ".gitignore"
|
24
23
|
- Gemfile
|
25
24
|
- MIT-LICENSE
|
26
25
|
- README.markdown
|
@@ -30,26 +29,24 @@ files:
|
|
30
29
|
- lib/hookup.rb
|
31
30
|
homepage: https://github.com/tpope/hookup
|
32
31
|
licenses: []
|
32
|
+
metadata: {}
|
33
33
|
post_install_message:
|
34
34
|
rdoc_options: []
|
35
35
|
require_paths:
|
36
36
|
- lib
|
37
37
|
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
38
|
requirements:
|
40
|
-
- -
|
39
|
+
- - ">="
|
41
40
|
- !ruby/object:Gem::Version
|
42
41
|
version: '0'
|
43
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
43
|
requirements:
|
46
|
-
- -
|
44
|
+
- - ">="
|
47
45
|
- !ruby/object:Gem::Version
|
48
46
|
version: '0'
|
49
47
|
requirements: []
|
50
|
-
|
51
|
-
rubygems_version: 1.8.23
|
48
|
+
rubygems_version: 3.1.4
|
52
49
|
signing_key:
|
53
|
-
specification_version:
|
50
|
+
specification_version: 4
|
54
51
|
summary: Automate the bundle/migration tedium of Rails with Git hooks
|
55
52
|
test_files: []
|