hookup 1.0.3 → 1.1.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/README.markdown +22 -8
- data/hookup.gemspec +1 -1
- data/lib/hookup.rb +52 -18
- metadata +4 -12
data/README.markdown
CHANGED
@@ -7,27 +7,41 @@ Git hooks. It fires after events like
|
|
7
7
|
* pulling in upstream changes
|
8
8
|
* switching branches
|
9
9
|
* stepping through a bisect
|
10
|
+
* conflict in schema
|
10
11
|
|
11
12
|
Usage
|
12
13
|
-----
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Hooked up!
|
15
|
+
gem install hookup
|
16
|
+
cd yourproject
|
17
|
+
hookup install
|
18
18
|
|
19
|
-
Bundling
|
20
|
-
--------
|
19
|
+
### Bundling
|
21
20
|
|
22
21
|
Each time your current HEAD changes, hookup checks to see if your
|
23
22
|
`Gemfile`, `Gemfile.lock`, or gem spec has changed. If so, it runs
|
24
23
|
`bundle check`, and if that indicates any dependencies are unsatisfied,
|
25
24
|
it runs `bundle install`.
|
26
25
|
|
27
|
-
Migrating
|
28
|
-
---------
|
26
|
+
### Migrating
|
29
27
|
|
30
28
|
Each time your current HEAD changes, hookup checks to see if any
|
31
29
|
migrations have been added, deleted, or modified. Deleted and modified
|
32
30
|
migrations are given the `rake db:migrate:down` treatment, then `rake
|
33
31
|
db:migrate` is invoked to bring everything else up to date.
|
32
|
+
|
33
|
+
### Schema Resolving
|
34
|
+
|
35
|
+
Each time there's a conflict in `db/schema.rb` on the
|
36
|
+
`Rails::Schema.define` line, hookup resolves it in favor of the newer of
|
37
|
+
the two versions.
|
38
|
+
|
39
|
+
ChangeLog
|
40
|
+
---------
|
41
|
+
|
42
|
+
[See it on the wiki](https://github.com/tpope/hookup/wiki/ChangeLog)
|
43
|
+
|
44
|
+
License
|
45
|
+
-------
|
46
|
+
|
47
|
+
Copyright (c) Tim Pope. MIT License.
|
data/hookup.gemspec
CHANGED
data/lib/hookup.rb
CHANGED
@@ -3,10 +3,16 @@ class Hookup
|
|
3
3
|
class Error < RuntimeError
|
4
4
|
end
|
5
5
|
|
6
|
+
class Failure < Error
|
7
|
+
end
|
8
|
+
|
6
9
|
EMPTY_DIR = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
|
7
10
|
|
8
11
|
def self.run(*argv)
|
9
12
|
new.run(*argv)
|
13
|
+
rescue Failure => e
|
14
|
+
puts e
|
15
|
+
exit 1
|
10
16
|
rescue Error => e
|
11
17
|
puts e
|
12
18
|
exit
|
@@ -27,24 +33,38 @@ class Hookup
|
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
36
|
+
def git_dir
|
37
|
+
unless @git_dir
|
38
|
+
@git_dir = %x{git rev-parse --git-dir}.chomp
|
39
|
+
raise Error, dir unless $?.success?
|
40
|
+
end
|
41
|
+
@git_dir
|
42
|
+
end
|
43
|
+
|
30
44
|
def install
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
unless File.exist?(hook)
|
35
|
-
File.open(hook, 'w', 0777) do |f|
|
36
|
-
f.puts "#!/bin/bash"
|
37
|
-
end
|
45
|
+
append(File.join(git_dir, 'hooks', 'post-checkout'), 0777) do |body, f|
|
46
|
+
f.puts "#!/bin/bash" unless body
|
47
|
+
f.puts %(hookup post-checkout "$@") if body !~ /hookup/
|
38
48
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
49
|
+
|
50
|
+
append(File.join(git_dir, 'info', 'attributes')) do |body, f|
|
51
|
+
map = 'db/schema.rb merge=railsschema'
|
52
|
+
f.puts map unless body.to_s.include?(map)
|
53
|
+
end
|
54
|
+
|
55
|
+
system 'git', 'config', 'merge.railsschema.driver', 'hookup resolve-schema %A %O %B %L'
|
56
|
+
|
57
|
+
puts "Hooked up!"
|
58
|
+
end
|
59
|
+
|
60
|
+
def append(file, *args)
|
61
|
+
Dir.mkdir(File.dirname(file)) unless File.directory?(File.dirname(file))
|
62
|
+
body = File.read(file) if File.exist?(file)
|
63
|
+
File.open(file, 'a', *args) do |f|
|
64
|
+
yield body, f
|
46
65
|
end
|
47
66
|
end
|
67
|
+
protected :append
|
48
68
|
|
49
69
|
def post_checkout(*args)
|
50
70
|
old, new = args.shift, args.shift || 'HEAD'
|
@@ -79,9 +99,10 @@ class Hookup
|
|
79
99
|
def migrate(old, new, *args)
|
80
100
|
return if args.first == '0'
|
81
101
|
|
82
|
-
|
83
|
-
|
84
|
-
system 'rake', 'db:create'
|
102
|
+
schemas = %w(db/schema.rb db/development_structure.sql).select do |schema|
|
103
|
+
status = %x{git diff --name-status #{old} #{new} -- #{schema}}.chomp
|
104
|
+
system 'rake', 'db:create' if status =~ /^A/
|
105
|
+
status !~ /^D/ && !status.empty?
|
85
106
|
end
|
86
107
|
|
87
108
|
migrations = %x{git diff --name-status #{old} #{new} -- db/migrate}.scan(/.+/).map {|l| l.split(/\t/) }
|
@@ -106,7 +127,20 @@ class Hookup
|
|
106
127
|
end
|
107
128
|
|
108
129
|
ensure
|
109
|
-
system 'git', 'checkout', '--',
|
130
|
+
system 'git', 'checkout', '--', *schemas if schemas.any?
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def resolve_schema(a, o, b, marker_size = 7)
|
135
|
+
system 'git', 'merge-file', "--marker-size=#{marker_size}", a, o, b
|
136
|
+
body = File.read(a)
|
137
|
+
asd = "ActiveRecord::Schema.define"
|
138
|
+
x = body.sub!(/^<+ .*\n#{asd}\(:version => (\d+)\) do\n=+\n#{asd}\(:version => (\d+)\) do\n>+ .*/) do
|
139
|
+
"#{asd}(:version => #{[$1, $2].max}) do"
|
140
|
+
end
|
141
|
+
File.open(a, 'w') { |f| f.write(body) }
|
142
|
+
if body.include?('<' * marker_size.to_i)
|
143
|
+
raise Failure, 'Failed to automatically resolve schema conflict'
|
110
144
|
end
|
111
145
|
end
|
112
146
|
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hookup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
version: 1.0.3
|
4
|
+
prerelease:
|
5
|
+
version: 1.1.0
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Tim Pope
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-08-24 00:00:00 -04:00
|
18
14
|
default_executable:
|
19
15
|
dependencies: []
|
20
16
|
|
@@ -50,21 +46,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
46
|
requirements:
|
51
47
|
- - ">="
|
52
48
|
- !ruby/object:Gem::Version
|
53
|
-
segments:
|
54
|
-
- 0
|
55
49
|
version: "0"
|
56
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
51
|
none: false
|
58
52
|
requirements:
|
59
53
|
- - ">="
|
60
54
|
- !ruby/object:Gem::Version
|
61
|
-
segments:
|
62
|
-
- 0
|
63
55
|
version: "0"
|
64
56
|
requirements: []
|
65
57
|
|
66
58
|
rubyforge_project: hookup
|
67
|
-
rubygems_version: 1.
|
59
|
+
rubygems_version: 1.6.2
|
68
60
|
signing_key:
|
69
61
|
specification_version: 3
|
70
62
|
summary: Automate the bundle/migration tedium of Rails with Git hooks
|