esr-rim 1.3.8 → 1.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,9 @@
1
- {
2
- "url" : "ssh://gerrit",
3
- "dependencies" : [
4
- {
5
- "unit":"nvStorage", "version": "1.1", "destination": "./bsw/nvStorage",
6
- "unit":"eepromManager", "version": "2.3", "destination": "./bsw/eeprom"
7
- }
8
- ]
9
- }
1
+ {
2
+ "url" : "ssh://gerrit",
3
+ "dependencies" : [
4
+ {
5
+ "unit":"nvStorage", "version": "1.1", "destination": "./bsw/nvStorage",
6
+ "unit":"eepromManager", "version": "2.3", "destination": "./bsw/eeprom"
7
+ }
8
+ ]
9
+ }
@@ -1,32 +1,32 @@
1
- $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
- $:.unshift File.join(File.dirname(__FILE__))
3
-
4
- require 'minitest/autorun'
5
- require 'rim/processor'
6
- require 'test_helper'
7
- require 'fileutils'
8
-
9
- class ProcessorTest < Minitest::Test
10
- include FileUtils
11
- include TestHelper
12
-
13
- def setup
14
- test_dir = empty_test_dir("command_helper_test")
15
- end
16
-
17
- def teardown
18
- remove_test_dirs
19
- end
20
-
21
- def test_get_absolute_remote_url
22
- cut = RIM::Processor.new(".", nil)
23
- assert File.expand_path(".") == cut.get_absolute_remote_url("file://.")
24
- assert File.expand_path("abcd", ".") == cut.get_absolute_remote_url("file://abcd")
25
- assert File.expand_path("abc", ".") == cut.get_absolute_remote_url("file://./abc")
26
- assert "C:/abcdef" == cut.get_absolute_remote_url("file:///C|/abcdef")
27
- assert "/abcdef/defghi" == cut.get_absolute_remote_url("file:///abcdef/defghi")
28
- assert "ssh://gerrit/abcde" == cut.get_absolute_remote_url("abcde")
29
- assert "ssh://gerrit2/abcde" == cut.get_absolute_remote_url("ssh://gerrit2/abcde")
30
- end
31
-
32
- end
1
+ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
+ $:.unshift File.join(File.dirname(__FILE__))
3
+
4
+ require 'minitest/autorun'
5
+ require 'rim/processor'
6
+ require 'test_helper'
7
+ require 'fileutils'
8
+
9
+ class ProcessorTest < Minitest::Test
10
+ include FileUtils
11
+ include TestHelper
12
+
13
+ def setup
14
+ test_dir = empty_test_dir("command_helper_test")
15
+ end
16
+
17
+ def teardown
18
+ remove_test_dirs
19
+ end
20
+
21
+ def test_get_absolute_remote_url
22
+ cut = RIM::Processor.new(".", nil)
23
+ assert File.expand_path(".") == cut.get_absolute_remote_url("file://.")
24
+ assert File.expand_path("abcd", ".") == cut.get_absolute_remote_url("file://abcd")
25
+ assert File.expand_path("abc", ".") == cut.get_absolute_remote_url("file://./abc")
26
+ assert "C:/abcdef" == cut.get_absolute_remote_url("file:///C|/abcdef")
27
+ assert "/abcdef/defghi" == cut.get_absolute_remote_url("file:///abcdef/defghi")
28
+ assert "ssh://gerrit/abcde" == cut.get_absolute_remote_url("abcde")
29
+ assert "ssh://gerrit2/abcde" == cut.get_absolute_remote_url("ssh://gerrit2/abcde")
30
+ end
31
+
32
+ end
@@ -1,296 +1,296 @@
1
- $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
- $:.unshift File.join(File.dirname(__FILE__))
3
-
4
- require 'minitest/autorun'
5
- require 'rim/git'
6
- require 'rim/module_info'
7
- require 'rim/status_builder'
8
- require 'rim/sync_helper'
9
- require 'test_helper'
10
- require 'fileutils'
11
-
12
- class SyncHelperTest < Minitest::Test
13
- include FileUtils
14
- include TestHelper
15
-
16
- def setup
17
- test_dir = empty_test_dir("sync_helper_test")
18
- @remote_git_dir = File.join(test_dir, "remote_git")
19
- @ws_remote_dir = File.join(test_dir, "remote_ws")
20
- @ws_dir = File.join(test_dir, "ws")
21
- @logger = Logger.new($stdout)
22
- @logger.level = Logger::ERROR unless ARGV.include? "debug"
23
- RIM::GitSession.logger = @logger
24
- end
25
-
26
- def teardown
27
- remove_test_dirs
28
- end
29
-
30
- def test_files_are_synchronized
31
- mod1_info = create_module_git("mod1")
32
- mod2_info = create_module_git("mod2")
33
- create_ws_git("testbr")
34
- cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info, mod2_info])
35
- cut.sync
36
- RIM::git_session(@ws_dir) do |s|
37
- assert !File.exist?(File.join(@ws_dir, "mod1"))
38
- assert !File.exist?(File.join(@ws_dir, "mod2"))
39
- s.execute("git checkout rim/testbr")
40
- check_not_dirty(s)
41
- log = s.execute("git log | grep \" module \"").split("\n").sort
42
- assert log.size == 2
43
- assert log[0].include?("mod1")
44
- assert log[1].include?("mod2")
45
- assert File.exist?(File.join(@ws_dir, "mod1"))
46
- assert File.exist?(File.join(@ws_dir, "mod2"))
47
- assert File.exist?(File.join(@ws_dir, "mod1", "readme.txt"))
48
- assert File.exist?(File.join(@ws_dir, "mod2", "readme.txt"))
49
- end
50
- end
51
-
52
- def test_files_are_synchronized_subtree
53
- mod_git_dir = create_all_module_git("mod_all")
54
- mod_a_info = RIM::ModuleInfo.new("file://" + mod_git_dir, "modules/a", "master", nil, nil, "mod_a")
55
- create_ws_git("testbr")
56
- cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod_a_info])
57
- cut.sync
58
- RIM::git_session(@ws_dir) do |s|
59
- assert !File.exist?(File.join(@ws_dir, "modules", "a"))
60
- s.execute("git checkout rim/testbr")
61
- check_not_dirty(s)
62
- log = s.execute("git log | grep \" module \"").split("\n").sort
63
- assert log.size == 1
64
- assert log[0].include?("modules/a")
65
- assert !File.exist?(File.join(@ws_dir, "modules", "b"))
66
- assert File.exist?(File.join(@ws_dir, "modules", "a"))
67
- assert File.exist?(File.join(@ws_dir, "modules", "a", "file_a.c"))
68
- end
69
- end
70
-
71
- def test_files_are_synchronized_subtree_deep
72
- mod_git_dir = create_all_module_git("mod_all")
73
- mod_a_info = RIM::ModuleInfo.new("file://" + mod_git_dir, "modules/b_src", "master", nil, nil, "mod_b/src")
74
- create_ws_git("testbr")
75
- cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod_a_info])
76
- cut.sync
77
- RIM::git_session(@ws_dir) do |s|
78
- assert !File.exist?(File.join(@ws_dir, "modules", "b_src"))
79
- s.execute("git checkout rim/testbr")
80
- check_not_dirty(s)
81
- log = s.execute("git log | grep \" module \"").split("\n").sort
82
- assert log.size == 1
83
- assert log[0].include?("modules/b_src")
84
- assert File.exist?(File.join(@ws_dir, "modules", "b_src", "file_b.c"))
85
- end
86
- end
87
-
88
-
89
- def test_files_are_synchronized_on_existing_branch
90
- mod1_info = create_module_git("mod1")
91
- mod2_info = create_module_git("mod2")
92
- create_ws_git("testbr")
93
- cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info, mod2_info])
94
- cut.sync
95
- `echo ' changed' >> #{File.join(@ws_dir, "readme")}`
96
- RIM::git_session(@ws_dir) do |s|
97
- s.execute("git commit . -m \"Changed ws file\"")
98
- end
99
- remote_path = path_from_module_info(mod1_info)
100
- `echo ' changed' >> #{File.join(remote_path, "readme.txt")}`
101
- RIM::git_session(remote_path) do |f|
102
- f.execute("git commit . -m \"Changed mod1 file\"")
103
- end
104
- cut.sync
105
- RIM::git_session(@ws_dir) do |s|
106
- s.execute("git checkout rim/testbr")
107
- check_not_dirty(s)
108
- log = s.execute("git log | grep \" module \"").split("\n").sort
109
- assert log.size == 3
110
- assert log[0].include?("mod1")
111
- assert log[1].include?("mod1")
112
- assert log[2].include?("mod2")
113
- assert File.exist?(File.join(@ws_dir, "mod1"))
114
- `cat #{File.join(@ws_dir, "mod1/readme.txt")}`.start_with?("Content. changed")
115
- assert File.exist?(File.join(@ws_dir, "mod2"))
116
- end
117
- end
118
-
119
- def test_files_are_synchronized_on_new_branch_if_behind_last_remote_commit
120
- mod1_info = create_module_git("mod1")
121
- mod2_info = create_module_git("mod2")
122
- create_ws_git("testbr")
123
- cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info, mod2_info])
124
- cut.sync
125
- `echo ' changed' >> #{File.join(@ws_remote_dir, "readme")}`
126
- RIM::git_session(@ws_remote_dir) do |s|
127
- s.execute("git commit . -m \"Changed ws file\"")
128
- end
129
- RIM::git_session(@ws_dir) do |s|
130
- s.execute("git pull")
131
- assert !has_ancestor?(s, "rim/testbr", "testbr")
132
- end
133
- cut.sync
134
- RIM::git_session(@ws_dir) do |s|
135
- assert has_ancestor?(s, "rim/testbr", "testbr")
136
- end
137
- end
138
-
139
- def test_existing_non_ignored_files_are_removed_during_sync
140
- mod1_info = create_module_git("mod1")
141
- create_ws_git("testbr") do |s|
142
- FileUtils.mkdir_p(File.join(@ws_remote_dir, "mod1"))
143
- File.open(File.join(@ws_remote_dir, "mod1", "existing.txt"), "w") do |f|
144
- f.write("Content")
145
- end
146
- s.execute("git add --all mod1")
147
- s.execute("git commit -m \"Create existing file within mod1\"")
148
- end
149
- cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
150
- cut.sync
151
- RIM::git_session(@ws_dir) do |s|
152
- s.execute("git rebase rim/testbr")
153
- assert !File.exists?(File.join(@ws_dir, "mod1", "existing.txt"))
154
- end
155
- end
156
-
157
- def test_case_change_in_filename_is_synced_correctly
158
- mod1_info = create_module_git("mod1")
159
- create_ws_git("testbr")
160
- cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
161
- cut.sync
162
- remote_path = path_from_module_info(mod1_info)
163
- RIM::git_session(remote_path) do |s|
164
- FileUtils.mv(File.join(remote_path, "readme.txt"), File.join(remote_path, "readme.tx_"))
165
- s.execute("git add --all .")
166
- s.execute("git commit -m \"Temporary change of filename within mod1\"")
167
- FileUtils.mv(File.join(remote_path, "readme.tx_"), File.join(remote_path, "Readme.txt"))
168
- s.execute("git add --all .")
169
- s.execute("git commit -m \"Changed case in filename within mod1\"")
170
- end
171
- cut.sync
172
- RIM::git_session(@ws_dir) do |s|
173
- s.execute("git rebase rim/testbr")
174
- out = s.execute("git show --name-only")
175
- assert out.include?("readme.txt")
176
- assert out.include?("Readme.txt")
177
- end
178
- end
179
-
180
- def test_sync_on_different_branches
181
- mod1_info = create_module_git("mod1")
182
- create_ws_git("testbr")
183
- cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
184
- cut.sync
185
- remote_path = path_from_module_info(mod1_info)
186
- RIM::git_session(remote_path) do |s|
187
- FileUtils.mv(File.join(remote_path, "readme.txt"), File.join(remote_path, "readme.tx_"))
188
- s.execute("git add --all .")
189
- s.execute("git commit -m \"Temporary change of filename within mod1\"")
190
- FileUtils.mv(File.join(remote_path, "readme.tx_"), File.join(remote_path, "Readme.txt"))
191
- s.execute("git add --all .")
192
- s.execute("git commit -m \"Changed case in filename within mod1\"")
193
- end
194
- RIM::git_session(@ws_dir) do |s|
195
- s.execute("git checkout -b branch2")
196
- end
197
- cut.sync
198
- RIM::git_session(@ws_dir) do |s|
199
- s.execute("git rebase rim/branch2")
200
- out = s.execute("git show --name-only")
201
- assert out.include?("Readme.txt")
202
- end
203
- RIM::git_session(remote_path) do |s|
204
- `echo ' changed' >> #{File.join(remote_path, "Readme.txt")}`
205
- s.execute("git commit . -m \"Changed module file\"")
206
- end
207
- cut.sync
208
- RIM::git_session(@ws_dir) do |s|
209
- s.execute("git rebase rim/branch2")
210
- s.execute("git checkout testbr")
211
- s.execute("git reset --hard branch2~1")
212
- s.execute("git push origin branch2:branch2")
213
- end
214
- cut.sync
215
- RIM::git_session(@ws_dir) do |s|
216
- s.execute("git reset --hard rim/testbr")
217
- out = s.execute("git show --name-only")
218
- assert out.include?("Readme.txt")
219
- end
220
- end
221
-
222
- private
223
- def create_ws_git(branch = "master")
224
- FileUtils.mkdir_p(@ws_remote_dir)
225
- RIM::git_session(@ws_remote_dir) do |s|
226
- s.execute("git init")
227
- s.execute("git checkout -B #{branch}")
228
- File.open(File.join(@ws_remote_dir, ".gitignore"), "w") do |f|
229
- f.write(".rim")
230
- end
231
- File.open(File.join(@ws_remote_dir, "readme"), "w") do |f|
232
- f.write("Content")
233
- end
234
- s.execute("git add .")
235
- s.execute("git commit -m \"Initial commit\"")
236
- yield s if block_given?
237
- end
238
- FileUtils.mkdir_p(@ws_dir)
239
- RIM::git_session(@ws_dir) do |s|
240
- s.execute("git clone #{@ws_remote_dir} #{@ws_dir}")
241
- end
242
- end
243
-
244
- def create_module_git(name, branch = "master")
245
- git_dir = File.join(@remote_git_dir, name)
246
- FileUtils.mkdir_p(git_dir)
247
- RIM::git_session(git_dir) do |s|
248
- s.execute("git init")
249
- s.execute("git checkout -B #{branch}")
250
- File.open(File.join(git_dir, "readme.txt"), "w") do |f|
251
- f.write("Content.")
252
- end
253
- s.execute("git add .")
254
- s.execute("git commit -m \"Initial commit\"")
255
- end
256
- return RIM::ModuleInfo.new("file://" + git_dir, name, branch)
257
- end
258
-
259
- def create_all_module_git(name, branch = "master")
260
- git_dir = File.join(@remote_git_dir, name)
261
- FileUtils.mkdir_p(File.join(git_dir,"mod_a"))
262
- FileUtils.mkdir_p(File.join(git_dir,"mod_b","src"))
263
- RIM::git_session(git_dir) do |s|
264
- s.execute("git init")
265
- s.execute("git checkout -B #{branch}")
266
- File.open(File.join(git_dir, "readme.txt"), "w") do |f|
267
- f.write("Content.")
268
- end
269
- File.open(File.join(git_dir, "mod_a", "file_a.c"), "w") do |f|
270
- f.write("Content.")
271
- end
272
- File.open(File.join(git_dir, "mod_b", "src", "file_b.c"), "w") do |f|
273
- f.write("Content.")
274
- end
275
- s.execute("git add .")
276
- s.execute("git commit -m \"Initial commit\"")
277
- end
278
- return git_dir
279
- end
280
-
281
- def path_from_module_info(module_info)
282
- module_info.remote_url.gsub(/^file:\/\//, "")
283
- end
284
-
285
- def check_not_dirty(session)
286
- status = RIM::StatusBuilder.new.rev_status(session, "HEAD")
287
- status.modules.each do |m|
288
- assert !m.dirty?
289
- end
290
- end
291
-
292
- def has_ancestor?(session, rev, ancestor)
293
- rev = session.execute("git rev-list #{rev}").include?(session.rev_sha1(ancestor))
294
- end
295
-
296
- end
1
+ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
+ $:.unshift File.join(File.dirname(__FILE__))
3
+
4
+ require 'minitest/autorun'
5
+ require 'rim/git'
6
+ require 'rim/module_info'
7
+ require 'rim/status_builder'
8
+ require 'rim/sync_helper'
9
+ require 'test_helper'
10
+ require 'fileutils'
11
+
12
+ class SyncHelperTest < Minitest::Test
13
+ include FileUtils
14
+ include TestHelper
15
+
16
+ def setup
17
+ test_dir = empty_test_dir("sync_helper_test")
18
+ @remote_git_dir = File.join(test_dir, "remote_git")
19
+ @ws_remote_dir = File.join(test_dir, "remote_ws")
20
+ @ws_dir = File.join(test_dir, "ws")
21
+ @logger = Logger.new($stdout)
22
+ @logger.level = Logger::ERROR unless ARGV.include? "debug"
23
+ RIM::GitSession.logger = @logger
24
+ end
25
+
26
+ def teardown
27
+ remove_test_dirs
28
+ end
29
+
30
+ def test_files_are_synchronized
31
+ mod1_info = create_module_git("mod1")
32
+ mod2_info = create_module_git("mod2")
33
+ create_ws_git("testbr")
34
+ cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info, mod2_info])
35
+ cut.sync
36
+ RIM::git_session(@ws_dir) do |s|
37
+ assert !File.exist?(File.join(@ws_dir, "mod1"))
38
+ assert !File.exist?(File.join(@ws_dir, "mod2"))
39
+ s.execute("git checkout rim/testbr")
40
+ check_not_dirty(s)
41
+ log = s.execute("git log | grep \" module \"").split("\n").sort
42
+ assert log.size == 2
43
+ assert log[0].include?("mod1")
44
+ assert log[1].include?("mod2")
45
+ assert File.exist?(File.join(@ws_dir, "mod1"))
46
+ assert File.exist?(File.join(@ws_dir, "mod2"))
47
+ assert File.exist?(File.join(@ws_dir, "mod1", "readme.txt"))
48
+ assert File.exist?(File.join(@ws_dir, "mod2", "readme.txt"))
49
+ end
50
+ end
51
+
52
+ def test_files_are_synchronized_subtree
53
+ mod_git_dir = create_all_module_git("mod_all")
54
+ mod_a_info = RIM::ModuleInfo.new("file://" + mod_git_dir, "modules/a", "master", nil, nil, "mod_a")
55
+ create_ws_git("testbr")
56
+ cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod_a_info])
57
+ cut.sync
58
+ RIM::git_session(@ws_dir) do |s|
59
+ assert !File.exist?(File.join(@ws_dir, "modules", "a"))
60
+ s.execute("git checkout rim/testbr")
61
+ check_not_dirty(s)
62
+ log = s.execute("git log | grep \" module \"").split("\n").sort
63
+ assert log.size == 1
64
+ assert log[0].include?("modules/a")
65
+ assert !File.exist?(File.join(@ws_dir, "modules", "b"))
66
+ assert File.exist?(File.join(@ws_dir, "modules", "a"))
67
+ assert File.exist?(File.join(@ws_dir, "modules", "a", "file_a.c"))
68
+ end
69
+ end
70
+
71
+ def test_files_are_synchronized_subtree_deep
72
+ mod_git_dir = create_all_module_git("mod_all")
73
+ mod_a_info = RIM::ModuleInfo.new("file://" + mod_git_dir, "modules/b_src", "master", nil, nil, "mod_b/src")
74
+ create_ws_git("testbr")
75
+ cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod_a_info])
76
+ cut.sync
77
+ RIM::git_session(@ws_dir) do |s|
78
+ assert !File.exist?(File.join(@ws_dir, "modules", "b_src"))
79
+ s.execute("git checkout rim/testbr")
80
+ check_not_dirty(s)
81
+ log = s.execute("git log | grep \" module \"").split("\n").sort
82
+ assert log.size == 1
83
+ assert log[0].include?("modules/b_src")
84
+ assert File.exist?(File.join(@ws_dir, "modules", "b_src", "file_b.c"))
85
+ end
86
+ end
87
+
88
+
89
+ def test_files_are_synchronized_on_existing_branch
90
+ mod1_info = create_module_git("mod1")
91
+ mod2_info = create_module_git("mod2")
92
+ create_ws_git("testbr")
93
+ cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info, mod2_info])
94
+ cut.sync
95
+ `echo ' changed' >> #{File.join(@ws_dir, "readme")}`
96
+ RIM::git_session(@ws_dir) do |s|
97
+ s.execute("git commit . -m \"Changed ws file\"")
98
+ end
99
+ remote_path = path_from_module_info(mod1_info)
100
+ `echo ' changed' >> #{File.join(remote_path, "readme.txt")}`
101
+ RIM::git_session(remote_path) do |f|
102
+ f.execute("git commit . -m \"Changed mod1 file\"")
103
+ end
104
+ cut.sync
105
+ RIM::git_session(@ws_dir) do |s|
106
+ s.execute("git checkout rim/testbr")
107
+ check_not_dirty(s)
108
+ log = s.execute("git log | grep \" module \"").split("\n").sort
109
+ assert log.size == 3
110
+ assert log[0].include?("mod1")
111
+ assert log[1].include?("mod1")
112
+ assert log[2].include?("mod2")
113
+ assert File.exist?(File.join(@ws_dir, "mod1"))
114
+ `cat #{File.join(@ws_dir, "mod1/readme.txt")}`.start_with?("Content. changed")
115
+ assert File.exist?(File.join(@ws_dir, "mod2"))
116
+ end
117
+ end
118
+
119
+ def test_files_are_synchronized_on_new_branch_if_behind_last_remote_commit
120
+ mod1_info = create_module_git("mod1")
121
+ mod2_info = create_module_git("mod2")
122
+ create_ws_git("testbr")
123
+ cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info, mod2_info])
124
+ cut.sync
125
+ `echo ' changed' >> #{File.join(@ws_remote_dir, "readme")}`
126
+ RIM::git_session(@ws_remote_dir) do |s|
127
+ s.execute("git commit . -m \"Changed ws file\"")
128
+ end
129
+ RIM::git_session(@ws_dir) do |s|
130
+ s.execute("git pull")
131
+ assert !has_ancestor?(s, "rim/testbr", "testbr")
132
+ end
133
+ cut.sync
134
+ RIM::git_session(@ws_dir) do |s|
135
+ assert has_ancestor?(s, "rim/testbr", "testbr")
136
+ end
137
+ end
138
+
139
+ def test_existing_non_ignored_files_are_removed_during_sync
140
+ mod1_info = create_module_git("mod1")
141
+ create_ws_git("testbr") do |s|
142
+ FileUtils.mkdir_p(File.join(@ws_remote_dir, "mod1"))
143
+ File.open(File.join(@ws_remote_dir, "mod1", "existing.txt"), "w") do |f|
144
+ f.write("Content")
145
+ end
146
+ s.execute("git add --all mod1")
147
+ s.execute("git commit -m \"Create existing file within mod1\"")
148
+ end
149
+ cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
150
+ cut.sync
151
+ RIM::git_session(@ws_dir) do |s|
152
+ s.execute("git rebase rim/testbr")
153
+ assert !File.exists?(File.join(@ws_dir, "mod1", "existing.txt"))
154
+ end
155
+ end
156
+
157
+ def test_case_change_in_filename_is_synced_correctly
158
+ mod1_info = create_module_git("mod1")
159
+ create_ws_git("testbr")
160
+ cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
161
+ cut.sync
162
+ remote_path = path_from_module_info(mod1_info)
163
+ RIM::git_session(remote_path) do |s|
164
+ FileUtils.mv(File.join(remote_path, "readme.txt"), File.join(remote_path, "readme.tx_"))
165
+ s.execute("git add --all .")
166
+ s.execute("git commit -m \"Temporary change of filename within mod1\"")
167
+ FileUtils.mv(File.join(remote_path, "readme.tx_"), File.join(remote_path, "Readme.txt"))
168
+ s.execute("git add --all .")
169
+ s.execute("git commit -m \"Changed case in filename within mod1\"")
170
+ end
171
+ cut.sync
172
+ RIM::git_session(@ws_dir) do |s|
173
+ s.execute("git rebase rim/testbr")
174
+ out = s.execute("git show")
175
+ assert out.include?("readme.txt")
176
+ assert out.include?("Readme.txt")
177
+ end
178
+ end
179
+
180
+ def test_sync_on_different_branches
181
+ mod1_info = create_module_git("mod1")
182
+ create_ws_git("testbr")
183
+ cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
184
+ cut.sync
185
+ remote_path = path_from_module_info(mod1_info)
186
+ RIM::git_session(remote_path) do |s|
187
+ FileUtils.mv(File.join(remote_path, "readme.txt"), File.join(remote_path, "readme.tx_"))
188
+ s.execute("git add --all .")
189
+ s.execute("git commit -m \"Temporary change of filename within mod1\"")
190
+ FileUtils.mv(File.join(remote_path, "readme.tx_"), File.join(remote_path, "Readme.txt"))
191
+ s.execute("git add --all .")
192
+ s.execute("git commit -m \"Changed case in filename within mod1\"")
193
+ end
194
+ RIM::git_session(@ws_dir) do |s|
195
+ s.execute("git checkout -b branch2")
196
+ end
197
+ cut.sync
198
+ RIM::git_session(@ws_dir) do |s|
199
+ s.execute("git rebase rim/branch2")
200
+ out = s.execute("git show --name-only")
201
+ assert out.include?("Readme.txt")
202
+ end
203
+ RIM::git_session(remote_path) do |s|
204
+ `echo ' changed' >> #{File.join(remote_path, "Readme.txt")}`
205
+ s.execute("git commit . -m \"Changed module file\"")
206
+ end
207
+ cut.sync
208
+ RIM::git_session(@ws_dir) do |s|
209
+ s.execute("git rebase rim/branch2")
210
+ s.execute("git checkout testbr")
211
+ s.execute("git reset --hard branch2~1")
212
+ s.execute("git push origin branch2:branch2")
213
+ end
214
+ cut.sync
215
+ RIM::git_session(@ws_dir) do |s|
216
+ s.execute("git reset --hard rim/testbr")
217
+ out = s.execute("git show --name-only")
218
+ assert out.include?("Readme.txt")
219
+ end
220
+ end
221
+
222
+ private
223
+ def create_ws_git(branch = "master")
224
+ FileUtils.mkdir_p(@ws_remote_dir)
225
+ RIM::git_session(@ws_remote_dir) do |s|
226
+ s.execute("git init")
227
+ s.execute("git checkout -B #{branch}")
228
+ File.open(File.join(@ws_remote_dir, ".gitignore"), "w") do |f|
229
+ f.write(".rim")
230
+ end
231
+ File.open(File.join(@ws_remote_dir, "readme"), "w") do |f|
232
+ f.write("Content")
233
+ end
234
+ s.execute("git add .")
235
+ s.execute("git commit -m \"Initial commit\"")
236
+ yield s if block_given?
237
+ end
238
+ FileUtils.mkdir_p(@ws_dir)
239
+ RIM::git_session(@ws_dir) do |s|
240
+ s.execute("git clone #{@ws_remote_dir} #{@ws_dir}")
241
+ end
242
+ end
243
+
244
+ def create_module_git(name, branch = "master")
245
+ git_dir = File.join(@remote_git_dir, name)
246
+ FileUtils.mkdir_p(git_dir)
247
+ RIM::git_session(git_dir) do |s|
248
+ s.execute("git init")
249
+ s.execute("git checkout -B #{branch}")
250
+ File.open(File.join(git_dir, "readme.txt"), "w") do |f|
251
+ f.write("Content.")
252
+ end
253
+ s.execute("git add .")
254
+ s.execute("git commit -m \"Initial commit\"")
255
+ end
256
+ return RIM::ModuleInfo.new("file://" + git_dir, name, branch)
257
+ end
258
+
259
+ def create_all_module_git(name, branch = "master")
260
+ git_dir = File.join(@remote_git_dir, name)
261
+ FileUtils.mkdir_p(File.join(git_dir,"mod_a"))
262
+ FileUtils.mkdir_p(File.join(git_dir,"mod_b","src"))
263
+ RIM::git_session(git_dir) do |s|
264
+ s.execute("git init")
265
+ s.execute("git checkout -B #{branch}")
266
+ File.open(File.join(git_dir, "readme.txt"), "w") do |f|
267
+ f.write("Content.")
268
+ end
269
+ File.open(File.join(git_dir, "mod_a", "file_a.c"), "w") do |f|
270
+ f.write("Content.")
271
+ end
272
+ File.open(File.join(git_dir, "mod_b", "src", "file_b.c"), "w") do |f|
273
+ f.write("Content.")
274
+ end
275
+ s.execute("git add .")
276
+ s.execute("git commit -m \"Initial commit\"")
277
+ end
278
+ return git_dir
279
+ end
280
+
281
+ def path_from_module_info(module_info)
282
+ module_info.remote_url.gsub(/^file:\/\//, "")
283
+ end
284
+
285
+ def check_not_dirty(session)
286
+ status = RIM::StatusBuilder.new.rev_status(session, "HEAD")
287
+ status.modules.each do |m|
288
+ assert !m.dirty?
289
+ end
290
+ end
291
+
292
+ def has_ancestor?(session, rev, ancestor)
293
+ rev = session.execute("git rev-list #{rev}").include?(session.rev_sha1(ancestor))
294
+ end
295
+
296
+ end