eternity 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +22 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +9 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +18 -0
- data/eternity.gemspec +39 -0
- data/lib/eternity.rb +64 -0
- data/lib/eternity/blob.rb +94 -0
- data/lib/eternity/branch.rb +34 -0
- data/lib/eternity/collection_index.rb +47 -0
- data/lib/eternity/collection_tracker.rb +55 -0
- data/lib/eternity/commit.rb +151 -0
- data/lib/eternity/conflict_resolver.rb +40 -0
- data/lib/eternity/delta.rb +45 -0
- data/lib/eternity/index.rb +29 -0
- data/lib/eternity/log.rb +22 -0
- data/lib/eternity/object_tracker.rb +57 -0
- data/lib/eternity/patch.rb +129 -0
- data/lib/eternity/repository.rb +235 -0
- data/lib/eternity/track_flatter.rb +57 -0
- data/lib/eternity/tracker.rb +38 -0
- data/lib/eternity/version.rb +3 -0
- data/spec/blob_spec.rb +83 -0
- data/spec/branch_spec.rb +71 -0
- data/spec/checkout_spec.rb +110 -0
- data/spec/commit_spec.rb +104 -0
- data/spec/coverage_helper.rb +8 -0
- data/spec/delta_spec.rb +110 -0
- data/spec/index_spec.rb +76 -0
- data/spec/locking_spec.rb +122 -0
- data/spec/log_spec.rb +57 -0
- data/spec/minitest_helper.rb +79 -0
- data/spec/patch_spec.rb +213 -0
- data/spec/pull_spec.rb +292 -0
- data/spec/push_spec.rb +72 -0
- data/spec/repository_spec.rb +73 -0
- data/spec/revert_spec.rb +40 -0
- data/spec/tracker_spec.rb +143 -0
- metadata +270 -0
data/spec/log_spec.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
describe Repository, 'Log' do
|
4
|
+
|
5
|
+
let(:repository) { Repository.new :test }
|
6
|
+
|
7
|
+
it 'Without commits' do
|
8
|
+
repository.log.must_be_empty
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'First commit' do
|
12
|
+
repository[:countries].insert 'AR', name: 'Argentina'
|
13
|
+
commit = repository.commit author: 'User', message: 'First commit'
|
14
|
+
|
15
|
+
repository.log.count.must_equal 1
|
16
|
+
repository.log.first.id.must_equal commit.id
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'Commit sequence' do
|
20
|
+
repository[:countries].insert 'AR', name: 'Argentina'
|
21
|
+
commit_1 = repository.commit author: 'User', message: 'Commit 1'
|
22
|
+
|
23
|
+
repository[:countries].insert 'UY', name: 'Uruguay'
|
24
|
+
commit_2 = repository.commit author: 'User', message: 'Commit 2'
|
25
|
+
|
26
|
+
repository.log.count.must_equal 2
|
27
|
+
repository.log[0].id.must_equal commit_2.id
|
28
|
+
repository.log[1].id.must_equal commit_1.id
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'Merge' do
|
32
|
+
time = Time.now
|
33
|
+
repository[:countries].insert 'AR', name: 'Argentina'
|
34
|
+
commit_1 = repository.commit author: 'User', message: 'Commit 1', time: time
|
35
|
+
repository.push
|
36
|
+
|
37
|
+
other_repository = Repository.new :other
|
38
|
+
other_repository.pull
|
39
|
+
|
40
|
+
other_repository[:countries].insert 'UY', name: 'Uruguay'
|
41
|
+
commit_2 = other_repository.commit author: 'User', message: 'Commit 2', time: time + 1
|
42
|
+
|
43
|
+
other_repository.push
|
44
|
+
|
45
|
+
repository[:countries].insert 'BR', name: 'Brasil'
|
46
|
+
commit_3 = repository.commit author: 'User', message: 'Commit 3', time: time + 2
|
47
|
+
|
48
|
+
repository.pull
|
49
|
+
|
50
|
+
repository.log.count.must_equal 4
|
51
|
+
repository.log[0].id.must_equal repository.current_commit.id
|
52
|
+
repository.log[1].id.must_equal commit_3.id
|
53
|
+
repository.log[2].id.must_equal commit_2.id
|
54
|
+
repository.log[3].id.must_equal commit_1.id
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'coverage_helper'
|
2
|
+
require 'eternity'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'timeout'
|
5
|
+
require 'turn'
|
6
|
+
require 'pry-nav'
|
7
|
+
|
8
|
+
include Eternity
|
9
|
+
|
10
|
+
Turn.config do |c|
|
11
|
+
c.format = :pretty
|
12
|
+
c.natural = true
|
13
|
+
c.ansi = true
|
14
|
+
end
|
15
|
+
|
16
|
+
Eternity.configure do |config|
|
17
|
+
config.keyspace = Restruct::Id.new :eternity_test
|
18
|
+
config.blob_path = File.expand_path('../../tmp', __FILE__)
|
19
|
+
config.blob_cache_expiration = 30
|
20
|
+
config.logger.level = Logger::ERROR
|
21
|
+
end
|
22
|
+
|
23
|
+
class Minitest::Spec
|
24
|
+
def redis
|
25
|
+
Eternity.redis
|
26
|
+
end
|
27
|
+
|
28
|
+
def digest(data)
|
29
|
+
Blob.digest(Blob.serialize(data))
|
30
|
+
end
|
31
|
+
|
32
|
+
def print_keys
|
33
|
+
puts Eternity.redis_keys.sort
|
34
|
+
end
|
35
|
+
|
36
|
+
def print_commit(commit)
|
37
|
+
puts "COMMIT: #{commit.author} - #{commit.message}"
|
38
|
+
puts "MERGE: #{commit.merge?}"
|
39
|
+
puts 'DELTA:'
|
40
|
+
puts JSON.pretty_generate(commit.delta)
|
41
|
+
if commit.merge?
|
42
|
+
puts "BASE: #{commit.base.author} - #{commit.base.message}"
|
43
|
+
puts 'BASE DELTA:'
|
44
|
+
puts JSON.pretty_generate(commit.base_delta)
|
45
|
+
end
|
46
|
+
puts 'INDEX:'
|
47
|
+
commit.with_index do |index|
|
48
|
+
index.each do |collection, collection_index|
|
49
|
+
puts collection
|
50
|
+
collection_index.ids.each do |id|
|
51
|
+
puts "#{id} -> #{collection_index[id].data}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
puts '------------------------------------'
|
56
|
+
end
|
57
|
+
|
58
|
+
after do
|
59
|
+
Eternity.clear_redis
|
60
|
+
Eternity.clear_file_system
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
module Minitest::Assertions
|
65
|
+
def assert_equal_index(expected, commit)
|
66
|
+
commit.with_index do |index|
|
67
|
+
index.to_h.must_equal expected
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def assert_have_empty_index(commit)
|
72
|
+
commit.with_index do |index|
|
73
|
+
index.must_be_empty
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
Commit.infect_an_assertion :assert_equal_index, :must_equal_index
|
79
|
+
Commit.infect_an_assertion :assert_have_empty_index, :must_have_empty_index, :unary
|
data/spec/patch_spec.rb
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
describe Patch do
|
4
|
+
|
5
|
+
let(:repo_1) { Repository.new :test_1 }
|
6
|
+
let(:repo_2) { Repository.new :test_2 }
|
7
|
+
let(:repo_3) { Repository.new :test_3 }
|
8
|
+
let(:commits) { Hash.new }
|
9
|
+
|
10
|
+
before do
|
11
|
+
# Repo 1: X---(1)---(2)---(3)---(4)---(5)---(8)---(9)---(12)---(13)---(14)
|
12
|
+
# Repo 2: \ \--(6)---(7)--/ /
|
13
|
+
# Repo 3: \----------(10)-----------------(11)------/
|
14
|
+
|
15
|
+
repo_1[:countries].insert 'AR', name: 'Argentina'
|
16
|
+
commit repo_1, 1
|
17
|
+
|
18
|
+
repo_1[:countries].insert 'UY', name: 'Uruguay'
|
19
|
+
commit repo_1, 2
|
20
|
+
|
21
|
+
repo_1[:countries].insert 'BR', name: 'Brasil'
|
22
|
+
commit repo_1, 3
|
23
|
+
repo_1.push
|
24
|
+
|
25
|
+
repo_1[:countries].update 'UY', name: 'Republica Oriental del Uruguay'
|
26
|
+
commit repo_1, 4
|
27
|
+
|
28
|
+
repo_1[:countries].update 'AR', name: 'Argentina', number: 54
|
29
|
+
commit repo_1, 5
|
30
|
+
|
31
|
+
repo_2.pull
|
32
|
+
repo_2[:countries].insert 'CL', name: 'Chile'
|
33
|
+
commit repo_2, 6
|
34
|
+
|
35
|
+
repo_2[:countries].update 'AR', name: 'Republica Argentina'
|
36
|
+
commit repo_2, 7
|
37
|
+
repo_2.push
|
38
|
+
|
39
|
+
repo_1.pull
|
40
|
+
add_commit repo_1.current_commit, 8
|
41
|
+
|
42
|
+
repo_1[:countries].delete 'CL'
|
43
|
+
commit repo_1, 9
|
44
|
+
repo_1.push
|
45
|
+
|
46
|
+
repo_3[:countries].insert 'CO', name: 'Colombia'
|
47
|
+
commit repo_3, 10
|
48
|
+
|
49
|
+
repo_3[:countries].update 'CO', name: 'Colombia', number: 57
|
50
|
+
commit repo_3, 11
|
51
|
+
|
52
|
+
repo_1.merge commit: commits[11].id
|
53
|
+
add_commit repo_1.current_commit, 12
|
54
|
+
|
55
|
+
repo_1[:countries].update 'BR', name: 'Brasil', number: 55
|
56
|
+
commit repo_1, 13
|
57
|
+
|
58
|
+
repo_1[:countries].delete 'CO'
|
59
|
+
commit repo_1, 14
|
60
|
+
end
|
61
|
+
|
62
|
+
def commit(repo, index)
|
63
|
+
commits[index] = repo.commit author: repo.name, message: "Commit #{index}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def add_commit(commit, index)
|
67
|
+
commits[index] = commit
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'Same commit' do
|
71
|
+
|
72
|
+
it 'Merge' do
|
73
|
+
patch = Patch.merge commits[4], commits[4]
|
74
|
+
|
75
|
+
patch.delta.must_be_empty
|
76
|
+
patch.base_commit.must_equal commits[4]
|
77
|
+
patch.base_delta.must_be_empty
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'Diff' do
|
81
|
+
patch = Patch.diff commits[4], commits[4]
|
82
|
+
|
83
|
+
patch.delta.must_be_empty
|
84
|
+
patch.base_commit.must_equal commits[4]
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'Both initial commits' do
|
90
|
+
|
91
|
+
it 'Merge' do
|
92
|
+
patch = Patch.merge commits[1], commits[11]
|
93
|
+
|
94
|
+
patch.delta.must_equal 'countries' => {
|
95
|
+
'CO' => {'action' => 'insert', 'data' => {'name' => 'Colombia', 'number' => 57}}
|
96
|
+
}
|
97
|
+
patch.base_commit.must_be_nil
|
98
|
+
patch.base_delta.must_equal 'countries' => {
|
99
|
+
'AR' => {'action' => 'insert', 'data' => {'name' => 'Argentina'}},
|
100
|
+
'CO' => {'action' => 'insert', 'data' => {'name' => 'Colombia', 'number' => 57}}
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'Diff' do
|
105
|
+
patch = Patch.diff commits[1], commits[11]
|
106
|
+
|
107
|
+
patch.delta.must_equal 'countries' => {
|
108
|
+
'AR' => {'action' => 'delete'},
|
109
|
+
'CO' => {'action' => 'insert', 'data' => {'name' => 'Colombia', 'number' => 57}}
|
110
|
+
}
|
111
|
+
patch.base_commit.must_be_nil
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
describe 'Fast forward' do
|
117
|
+
|
118
|
+
it 'Merge' do
|
119
|
+
patch = Patch.merge commits[1], commits[3]
|
120
|
+
|
121
|
+
patch.delta.must_be_empty
|
122
|
+
patch.base_commit.must_equal commits[1]
|
123
|
+
patch.base_delta.must_be_empty
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'Diff' do
|
127
|
+
patch = Patch.diff commits[1], commits[3]
|
128
|
+
|
129
|
+
patch.delta.must_equal 'countries' => {
|
130
|
+
'UY' => {'action' => 'insert', 'data' => {'name' => 'Uruguay'}},
|
131
|
+
'BR' => {'action' => 'insert', 'data' => {'name' => 'Brasil'}}
|
132
|
+
}
|
133
|
+
patch.base_commit.must_equal commits[1]
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
describe 'Revert' do
|
139
|
+
|
140
|
+
it 'Merge' do
|
141
|
+
patch = Patch.merge commits[4], commits[2]
|
142
|
+
|
143
|
+
patch.delta.must_be_empty
|
144
|
+
patch.base_commit.must_equal commits[2]
|
145
|
+
patch.base_delta.must_be_empty
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'Diff' do
|
149
|
+
patch = Patch.diff commits[4], commits[2]
|
150
|
+
|
151
|
+
patch.delta.must_equal 'countries' => {
|
152
|
+
'UY' => {'action' => 'update', 'data' => {'name' => 'Uruguay'}},
|
153
|
+
'BR' => {'action' => 'delete'}
|
154
|
+
}
|
155
|
+
patch.base_commit.must_equal commits[2]
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
describe 'Merge' do
|
161
|
+
|
162
|
+
it 'Merge' do
|
163
|
+
patch = Patch.merge commits[5], commits[7]
|
164
|
+
|
165
|
+
patch.delta.must_equal 'countries' => {
|
166
|
+
'AR' => {'action' => 'update', 'data' => {'name' => 'Republica Argentina', 'number' => 54}},
|
167
|
+
'CL' => {'action' => 'insert', 'data' => {'name' => 'Chile'}}
|
168
|
+
}
|
169
|
+
patch.base_commit.must_equal commits[3]
|
170
|
+
patch.base_delta.must_equal 'countries' => {
|
171
|
+
'UY' => {'action' => 'update', 'data' => {'name' => 'Republica Oriental del Uruguay'}},
|
172
|
+
'AR' => {'action' => 'update', 'data' => {'name' => 'Republica Argentina', 'number' => 54}},
|
173
|
+
'CL' => {'action' => 'insert', 'data' => {'name' => 'Chile'}},
|
174
|
+
}
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'Diff' do
|
178
|
+
patch = Patch.diff commits[5], commits[7]
|
179
|
+
|
180
|
+
patch.delta.must_equal 'countries' => {
|
181
|
+
'UY' => {'action' => 'update', 'data' => {'name' => 'Uruguay'}},
|
182
|
+
'AR' => {'action' => 'update', 'data' => {'name' => 'Republica Argentina'}},
|
183
|
+
'CL' => {'action' => 'insert', 'data' => {'name' => 'Chile'}}
|
184
|
+
}
|
185
|
+
patch.base_commit.must_equal commits[3]
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
describe 'Unmerge' do
|
191
|
+
|
192
|
+
it 'Merge' do
|
193
|
+
patch = Patch.merge commits[9], commits[7]
|
194
|
+
|
195
|
+
patch.delta.must_be_empty
|
196
|
+
patch.base_commit.must_equal commits[3]
|
197
|
+
patch.base_delta.must_be_empty
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'Diff' do
|
201
|
+
patch = Patch.diff commits[9], commits[7]
|
202
|
+
|
203
|
+
patch.delta.must_equal 'countries' => {
|
204
|
+
'AR' => {'action' => 'update', 'data' => {'name' => 'Republica Argentina'}},
|
205
|
+
'UY' => {'action' => 'update', 'data' => {'name' => 'Uruguay'}},
|
206
|
+
'CL' => {'action' => 'insert', 'data' => {'name' => 'Chile'}}
|
207
|
+
}
|
208
|
+
patch.base_commit.must_equal commits[3]
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
data/spec/pull_spec.rb
ADDED
@@ -0,0 +1,292 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
describe Repository, 'Pull' do
|
4
|
+
|
5
|
+
let(:repository) { Repository.new :test }
|
6
|
+
|
7
|
+
it 'With uncommitted changes' do
|
8
|
+
repository[:countries].insert 'AR', name: 'Argentina'
|
9
|
+
|
10
|
+
error = proc { repository.pull }.must_raise RuntimeError
|
11
|
+
error.message.must_equal "Can't pull with uncommitted changes"
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'Invalid remote branch' do
|
15
|
+
error = proc { repository.pull }.must_raise RuntimeError
|
16
|
+
error.message.must_equal 'Branch not found: master'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'Without previous commit' do
|
20
|
+
other_repository = Repository.new :other
|
21
|
+
other_repository[:countries].insert 'AR', name: 'Argentina'
|
22
|
+
commit = other_repository.commit author: 'User', message: 'Commit 1'
|
23
|
+
other_repository.push
|
24
|
+
|
25
|
+
delta = repository.pull
|
26
|
+
|
27
|
+
delta.must_equal 'countries' => {'AR' => {'action' => 'insert', 'data' => {'name' => 'Argentina'}}}
|
28
|
+
repository.current_commit.must_equal commit
|
29
|
+
repository.branches[repository.current_branch].must_equal commit.id
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'Up to date' do
|
33
|
+
repository[:countries].insert 'AR', name: 'Argentina'
|
34
|
+
commit_1 = repository.commit author: 'User', message: 'Commit 1'
|
35
|
+
repository.push
|
36
|
+
|
37
|
+
delta = repository.pull
|
38
|
+
|
39
|
+
delta.must_be_empty
|
40
|
+
repository.current_commit.must_equal commit_1
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'Ahead of branch' do
|
44
|
+
repository[:countries].insert 'AR', name: 'Argentina'
|
45
|
+
commit_1 = repository.commit author: 'User', message: 'Commit 1'
|
46
|
+
|
47
|
+
repository.push
|
48
|
+
|
49
|
+
repository[:countries].insert 'UY', name: 'Uruguay'
|
50
|
+
commit_2 = repository.commit author: 'User', message: 'Commit 2'
|
51
|
+
|
52
|
+
delta = repository.pull
|
53
|
+
|
54
|
+
delta.must_be_empty
|
55
|
+
repository.current_commit.must_equal commit_2
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'Fast-forward' do
|
59
|
+
repository[:countries].insert 'AR', name: 'Argentina'
|
60
|
+
commit_1 = repository.commit author: 'User', message: 'Commit 1'
|
61
|
+
repository.push
|
62
|
+
|
63
|
+
other_repository = Repository.new :other
|
64
|
+
delta = other_repository.pull
|
65
|
+
|
66
|
+
delta.must_equal 'countries' => {'AR' => {'action' => 'insert', 'data' => {'name' => 'Argentina'}}}
|
67
|
+
|
68
|
+
repository[:countries].insert 'UY', name: 'Uruguay'
|
69
|
+
commit_2 = repository.commit author: 'User', message: 'Commit 2'
|
70
|
+
repository.push
|
71
|
+
|
72
|
+
other_repository.wont_be :changes?
|
73
|
+
other_repository.current_commit.must_equal commit_1
|
74
|
+
other_repository.branches[other_repository.current_branch].must_equal commit_1.id
|
75
|
+
|
76
|
+
delta = other_repository.pull
|
77
|
+
|
78
|
+
delta.must_equal 'countries' => {'UY' => {'action' => 'insert', 'data' => {'name' => 'Uruguay'}}}
|
79
|
+
|
80
|
+
other_repository.wont_be :changes?
|
81
|
+
other_repository.current_commit.must_equal commit_2
|
82
|
+
other_repository.branches[other_repository.current_branch].must_equal commit_2.id
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'Merge' do
|
86
|
+
repository[:countries].insert 'AR', name: 'Argentina'
|
87
|
+
commit_1 = repository.commit author: 'User', message: 'Commit 1'
|
88
|
+
repository.push
|
89
|
+
|
90
|
+
other_repository = Repository.new :other
|
91
|
+
delta = other_repository.pull
|
92
|
+
|
93
|
+
delta.must_equal 'countries' => {'AR' => {'action' => 'insert', 'data' => {'name' => 'Argentina'}}}
|
94
|
+
|
95
|
+
other_repository[:countries].insert 'UY', name: '...'
|
96
|
+
commit_2 = other_repository.commit author: 'User', message: 'Commit 2'
|
97
|
+
|
98
|
+
other_repository[:countries].update 'UY', name: 'Uruguay'
|
99
|
+
commit_3 = other_repository.commit author: 'User', message: 'Commit 3'
|
100
|
+
|
101
|
+
other_repository.push
|
102
|
+
|
103
|
+
repository[:countries].insert 'BR', name: 'Brasil'
|
104
|
+
commit_4 = repository.commit author: 'User', message: 'Commit 4'
|
105
|
+
|
106
|
+
delta = repository.pull
|
107
|
+
|
108
|
+
delta.must_equal 'countries' => {'UY' => {'action' => 'insert', 'data' => {'name' => 'Uruguay'}}}
|
109
|
+
|
110
|
+
repository.branches[repository.current_branch].must_equal repository.current_commit.id
|
111
|
+
|
112
|
+
repository.current_commit.tap do |commit|
|
113
|
+
commit.must_be :merge?
|
114
|
+
commit.parent_ids.must_equal [commit_4.id, commit_3.id]
|
115
|
+
commit.base.id.must_equal commit_1.id
|
116
|
+
commit.base_delta.must_equal 'countries' => {
|
117
|
+
'BR' => {'action' => 'insert', 'data' => {'name' => 'Brasil'}},
|
118
|
+
'UY' => {'action' => 'insert', 'data' => {'name' => 'Uruguay'}}
|
119
|
+
}
|
120
|
+
commit.delta.must_be_empty
|
121
|
+
commit.must_equal_index 'countries' => {
|
122
|
+
'AR' => digest(name: 'Argentina'),
|
123
|
+
'UY' => digest(name: 'Uruguay'),
|
124
|
+
'BR' => digest(name: 'Brasil')
|
125
|
+
}
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'Merge with conflicts' do
|
130
|
+
repository[:countries].insert 'AR', name: 'Argentina 1'
|
131
|
+
commit_1 = repository.commit author: 'User', message: 'Commit 1'
|
132
|
+
repository.push
|
133
|
+
|
134
|
+
other_repository = Repository.new :other
|
135
|
+
delta = other_repository.pull
|
136
|
+
|
137
|
+
delta.must_equal 'countries' => {'AR' => {'action' => 'insert', 'data' => {'name' => 'Argentina 1'}}}
|
138
|
+
|
139
|
+
other_repository[:countries].update 'AR', name: 'Argentina 2'
|
140
|
+
commit_2 = other_repository.commit author: 'User', message: 'Commit 2'
|
141
|
+
other_repository.push
|
142
|
+
|
143
|
+
repository[:countries].update 'AR', name: 'Argentina 3'
|
144
|
+
commit_3 = repository.commit author: 'User', message: 'Commit 3'
|
145
|
+
delta = repository.pull
|
146
|
+
|
147
|
+
delta.must_equal 'countries' => {'AR' => {'action' => 'update', 'data' => {'name' => 'Argentina 2'}}}
|
148
|
+
|
149
|
+
repository.branches[repository.current_branch].must_equal repository.current_commit.id
|
150
|
+
|
151
|
+
repository.current_commit.tap do |commit|
|
152
|
+
commit.must_be :merge?
|
153
|
+
commit.parent_ids.must_equal [commit_3.id, commit_2.id]
|
154
|
+
commit.base.id.must_equal commit_1.id
|
155
|
+
commit.base_delta.must_equal 'countries' => {'AR' => {'action' => 'update', 'data' => {'name' => 'Argentina 2'}}}
|
156
|
+
commit.delta.must_be_empty
|
157
|
+
commit.must_equal_index 'countries' => {'AR' => digest(name: 'Argentina 2')}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'Merge different changes for same object' do
|
162
|
+
repository[:countries].insert 'AR', name: 'Argentina'
|
163
|
+
commit_1 = repository.commit author: 'User', message: 'Commit 1'
|
164
|
+
repository.push
|
165
|
+
|
166
|
+
other_repository = Repository.new :other
|
167
|
+
delta = other_repository.pull
|
168
|
+
|
169
|
+
delta.must_equal 'countries' => {'AR' => {'action' => 'insert', 'data' => {'name' => 'Argentina'}}}
|
170
|
+
|
171
|
+
other_repository[:countries].update 'AR', name: 'Argentina', number: 54
|
172
|
+
commit_2 = other_repository.commit author: 'User', message: 'Commit 2'
|
173
|
+
other_repository.push
|
174
|
+
|
175
|
+
repository[:countries].update 'AR', name: 'Argentina', code: 'ARG'
|
176
|
+
commit_3 = repository.commit author: 'User', message: 'Commit 3'
|
177
|
+
delta = repository.pull
|
178
|
+
|
179
|
+
delta.must_equal 'countries' => {'AR' => {'action' => 'update', 'data' => {'name' => 'Argentina', 'code' => 'ARG', 'number' => 54}}}
|
180
|
+
|
181
|
+
repository.branches[repository.current_branch].must_equal repository.current_commit.id
|
182
|
+
|
183
|
+
repository.current_commit.tap do |commit|
|
184
|
+
commit.must_be :merge?
|
185
|
+
commit.parent_ids.must_equal [commit_3.id, commit_2.id]
|
186
|
+
commit.base.id.must_equal commit_1.id
|
187
|
+
commit.base_delta.must_equal 'countries' => {'AR' => {'action' => 'update', 'data' => {'name' => 'Argentina', 'code' => 'ARG', 'number' => 54}}}
|
188
|
+
commit.delta.must_be_empty
|
189
|
+
commit.must_equal_index 'countries' => {'AR' => digest(name: 'Argentina', code: 'ARG', number: 54)}
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'Merge added same object in differents repositories' do
|
194
|
+
repository[:countries].insert 'AR', name: 'Argentina'
|
195
|
+
commit_1 = repository.commit author: 'User', message: 'Commit 1'
|
196
|
+
repository.push
|
197
|
+
|
198
|
+
other_repository = Repository.new :other
|
199
|
+
delta = other_repository.pull
|
200
|
+
|
201
|
+
delta.must_equal 'countries' => {'AR' => {'action' => 'insert', 'data' => {'name' => 'Argentina'}}}
|
202
|
+
|
203
|
+
other_repository[:countries].insert 'X', name: 'X1', code: 1
|
204
|
+
commit_2 = other_repository.commit author: 'User', message: 'Commit 2'
|
205
|
+
other_repository.push
|
206
|
+
|
207
|
+
repository[:countries].insert 'X', name: 'X2', number: 2
|
208
|
+
commit_3 = repository.commit author: 'User', message: 'Commit 3'
|
209
|
+
delta = repository.pull
|
210
|
+
|
211
|
+
delta.must_equal 'countries' => {'X' => {'action' => 'update', 'data' => {'name' => 'X1', 'number' => 2, 'code' => 1}}}
|
212
|
+
|
213
|
+
repository.branches[repository.current_branch].must_equal repository.current_commit.id
|
214
|
+
|
215
|
+
repository.current_commit.tap do |commit|
|
216
|
+
commit.must_be :merge?
|
217
|
+
commit.parent_ids.must_equal [commit_3.id, commit_2.id]
|
218
|
+
commit.base.id.must_equal commit_1.id
|
219
|
+
commit.base_delta.must_equal 'countries' => {'X' => {'action' => 'insert', 'data' => {'name' => 'X1', 'number' => 2, 'code' => 1}}}
|
220
|
+
commit.delta.must_be_empty
|
221
|
+
commit.must_equal_index 'countries' => {
|
222
|
+
'AR' => digest(name: 'Argentina'),
|
223
|
+
'X' => digest(name: 'X1', 'number' => 2, 'code' => 1)
|
224
|
+
}
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'Merge removed same object in differents repositories' do
|
229
|
+
repository[:countries].insert 'AR', name: 'Argentina'
|
230
|
+
commit_1 = repository.commit author: 'User', message: 'Commit 1'
|
231
|
+
repository.push
|
232
|
+
|
233
|
+
other_repository = Repository.new :other
|
234
|
+
delta = other_repository.pull
|
235
|
+
|
236
|
+
delta.must_equal 'countries' => {'AR' => {'action' => 'insert', 'data' => {'name' => 'Argentina'}}}
|
237
|
+
|
238
|
+
other_repository[:countries].delete 'AR'
|
239
|
+
commit_2 = other_repository.commit author: 'User', message: 'Commit 2'
|
240
|
+
other_repository.push
|
241
|
+
|
242
|
+
repository[:countries].delete 'AR'
|
243
|
+
commit_3 = repository.commit author: 'User', message: 'Commit 3'
|
244
|
+
delta = repository.pull
|
245
|
+
|
246
|
+
delta.must_be_empty
|
247
|
+
|
248
|
+
repository.branches[repository.current_branch].must_equal repository.current_commit.id
|
249
|
+
|
250
|
+
repository.current_commit.tap do |commit|
|
251
|
+
commit.must_be :merge?
|
252
|
+
commit.parent_ids.must_equal [commit_3.id, commit_2.id]
|
253
|
+
commit.base.id.must_equal commit_1.id
|
254
|
+
commit.base_delta.must_equal 'countries' => {'AR' => {'action' => 'delete'}}
|
255
|
+
commit.delta.must_be_empty
|
256
|
+
commit.must_have_empty_index
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'Merge updated object previously removed' do
|
261
|
+
repository[:countries].insert 'AR', name: 'Argentina'
|
262
|
+
commit_1 = repository.commit author: 'User', message: 'Commit 1'
|
263
|
+
repository.push
|
264
|
+
|
265
|
+
other_repository = Repository.new :other
|
266
|
+
delta = other_repository.pull
|
267
|
+
|
268
|
+
delta.must_equal 'countries' => {'AR' => {'action' => 'insert', 'data' => {'name' => 'Argentina'}}}
|
269
|
+
|
270
|
+
other_repository[:countries].update 'AR', name: 'Argentina', code: 'ARG'
|
271
|
+
commit_2 = other_repository.commit author: 'User', message: 'Commit 2'
|
272
|
+
other_repository.push
|
273
|
+
|
274
|
+
repository[:countries].delete 'AR'
|
275
|
+
commit_3 = repository.commit author: 'User', message: 'Commit 3'
|
276
|
+
delta = repository.pull
|
277
|
+
|
278
|
+
delta.must_equal 'countries' => {'AR' => {'action' => 'insert', 'data' => {'name' => 'Argentina', 'code' => 'ARG'}}}
|
279
|
+
|
280
|
+
repository.branches[repository.current_branch].must_equal repository.current_commit.id
|
281
|
+
|
282
|
+
repository.current_commit.tap do |commit|
|
283
|
+
commit.must_be :merge?
|
284
|
+
commit.parent_ids.must_equal [commit_3.id, commit_2.id]
|
285
|
+
commit.base.id.must_equal commit_1.id
|
286
|
+
commit.base_delta.must_equal 'countries' => {'AR' => {'action' => 'update', 'data' => {'name' => 'Argentina', 'code' => 'ARG'}}}
|
287
|
+
commit.delta.must_be_empty
|
288
|
+
commit.must_equal_index 'countries' => {'AR' => digest(name: 'Argentina', code: 'ARG')}
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
end
|