esr-rim 1.3.9 → 1.4.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,126 +1,126 @@
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/dirty_check'
7
- require 'rim/module_info'
8
- require 'rim/sync_module_helper'
9
- require 'test_helper'
10
- require 'fileutils'
11
-
12
- class SyncModuleHelperTest < Minitest::Test
13
- include FileUtils
14
- include TestHelper
15
-
16
- def setup
17
- @logger = Logger.new($stdout)
18
- @logger.level = Logger::ERROR unless ARGV.include? "debug"
19
- RIM::GitSession.logger = @logger
20
- test_dir = empty_test_dir("module_sync_helper_test")
21
- @remote_git_dir = File.join(test_dir, "remote_git")
22
- @remote_git_dir_url = "file://" + @remote_git_dir
23
- FileUtils.mkdir(@remote_git_dir)
24
- RIM::git_session(@remote_git_dir) do |s|
25
- s.execute("git init")
26
- s.execute("git checkout -B testbr")
27
- write_file(@remote_git_dir, "readme.txt")
28
- s.execute("git add .")
29
- s.execute("git commit -m \"Initial commit\"")
30
- end
31
- @ws_dir = File.join(test_dir, "ws")
32
- FileUtils.mkdir(@ws_dir)
33
- RIM::git_session(@ws_dir) do |s|
34
- s.execute("git clone #{@remote_git_dir_url} .")
35
- end
36
- end
37
-
38
- def teardown
39
- remove_test_dirs
40
- end
41
-
42
- def test_files_are_copied_to_working_dir
43
- info = RIM::ModuleInfo.new(@remote_git_dir_url, "test", "testbr")
44
- cut = RIM::SyncModuleHelper.new(@ws_dir, @ws_dir, info, @logger)
45
- cut.sync
46
- assert File.exists?(File.join(@ws_dir, "test/readme.txt"))
47
- assert File.exists?(File.join(@ws_dir, "test/.riminfo"))
48
- end
49
-
50
- def test_files_ignored_by_gitignore_of_workspace_are_copied_to_working_dir
51
- RIM::git_session(@remote_git_dir) do |s|
52
- write_file(@remote_git_dir, 'ignored_file.txt')
53
- s.execute("git add .")
54
- s.execute("git commit -m \"Add a single file\"")
55
- end
56
- RIM::git_session(@ws_dir) do |s|
57
- write_file(@ws_dir, '.gitignore', 'ignored*\n')
58
- s.execute("git add .")
59
- s.execute("git commit -m \"Ignore a single file\"")
60
- end
61
- info = RIM::ModuleInfo.new(@remote_git_dir_url, "test", "testbr")
62
- cut = RIM::SyncModuleHelper.new(@ws_dir, @ws_dir, info, @logger)
63
- cut.sync
64
- assert File.exists?(File.join(@ws_dir, "test/readme.txt"))
65
- assert File.exists?(File.join(@ws_dir, "test/.riminfo"))
66
- assert File.exists?(File.join(@ws_dir, "test/ignored_file.txt"))
67
- # Add a single ignored file afterwards and sync again
68
- RIM::git_session(@remote_git_dir) do |s|
69
- write_file(@remote_git_dir, 'ignored_file_2.txt')
70
- s.execute("git add .")
71
- s.execute("git commit -m \"Add a second ignored file\"")
72
- end
73
- cut.sync
74
- assert File.exists?(File.join(@ws_dir, "test/readme.txt"))
75
- assert File.exists?(File.join(@ws_dir, "test/.riminfo"))
76
- assert File.exists?(File.join(@ws_dir, "test/ignored_file.txt"))
77
- assert File.exists?(File.join(@ws_dir, "test/ignored_file_2.txt"))
78
- end
79
-
80
- def test_files_of_ignore_list_are_not_removed_when_copying
81
- test_folder = File.join(@ws_dir, "test")
82
- write_file(test_folder, "file1")
83
- write_file(test_folder, "file2")
84
- write_file(File.join(test_folder, "folder"), "file1")
85
- write_file(File.join(test_folder, "folder"), "file2")
86
- write_file(File.join(test_folder, "folder2"), "file1")
87
- info = RIM::ModuleInfo.new(@remote_git_dir_url, "test", "testbr", "**/file2")
88
- cut = RIM::SyncModuleHelper.new(@ws_dir, @ws_dir, info, @logger)
89
- cut.sync
90
- assert File.exists?(File.join(test_folder, "readme.txt"))
91
- assert File.exists?(File.join(test_folder, ".riminfo"))
92
- assert !File.exists?(File.join(test_folder, "file1"))
93
- assert File.exists?(File.join(test_folder, "file2"))
94
- assert !File.exists?(File.join(test_folder, "folder/file1"))
95
- assert File.exists?(File.join(test_folder, "folder/file2"))
96
- assert File.exists?(File.join(test_folder, "folder/file2"))
97
- end
98
-
99
- def test_commit_message_is_set_by_default
100
- info = RIM::ModuleInfo.new(@remote_git_dir_url, "test", "testbr")
101
- cut = RIM::SyncModuleHelper.new(@ws_dir, @ws_dir, info, @logger)
102
- cut.sync
103
- RIM::git_session(@ws_dir) do |s|
104
- out = s.execute("git log HEAD~1..HEAD")
105
- assert out.include?("rim sync: module")
106
- end
107
- end
108
-
109
- def test_commit_message_can_be_changed
110
- info = RIM::ModuleInfo.new(@remote_git_dir_url, "test", "testbr")
111
- cut = RIM::SyncModuleHelper.new(@ws_dir, @ws_dir, info, @logger)
112
- cut.sync("This is the commit header.")
113
- RIM::git_session(@ws_dir) do |s|
114
- out = s.execute("git log HEAD~1..HEAD")
115
- assert out.include?("This is the commit header.\n")
116
- end
117
- end
118
-
119
- def write_file(dir, name, content = nil)
120
- FileUtils.mkdir_p(dir)
121
- File.open(File.join(dir, name), "w") do |f|
122
- f.write(content || "Content of #{name}\n")
123
- end
124
- end
125
-
126
- 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/dirty_check'
7
+ require 'rim/module_info'
8
+ require 'rim/sync_module_helper'
9
+ require 'test_helper'
10
+ require 'fileutils'
11
+
12
+ class SyncModuleHelperTest < Minitest::Test
13
+ include FileUtils
14
+ include TestHelper
15
+
16
+ def setup
17
+ @logger = Logger.new($stdout)
18
+ @logger.level = Logger::ERROR unless ARGV.include? "debug"
19
+ RIM::GitSession.logger = @logger
20
+ test_dir = empty_test_dir("module_sync_helper_test")
21
+ @remote_git_dir = File.join(test_dir, "remote_git")
22
+ @remote_git_dir_url = "file://" + @remote_git_dir
23
+ FileUtils.mkdir(@remote_git_dir)
24
+ RIM::git_session(@remote_git_dir) do |s|
25
+ s.execute("git init")
26
+ s.execute("git checkout -B testbr")
27
+ write_file(@remote_git_dir, "readme.txt")
28
+ s.execute("git add .")
29
+ s.execute("git commit -m \"Initial commit\"")
30
+ end
31
+ @ws_dir = File.join(test_dir, "ws")
32
+ FileUtils.mkdir(@ws_dir)
33
+ RIM::git_session(@ws_dir) do |s|
34
+ s.execute("git clone #{@remote_git_dir_url} .")
35
+ end
36
+ end
37
+
38
+ def teardown
39
+ remove_test_dirs
40
+ end
41
+
42
+ def test_files_are_copied_to_working_dir
43
+ info = RIM::ModuleInfo.new(@remote_git_dir_url, "test", "testbr")
44
+ cut = RIM::SyncModuleHelper.new(@ws_dir, @ws_dir, info, @logger)
45
+ cut.sync
46
+ assert File.exists?(File.join(@ws_dir, "test/readme.txt"))
47
+ assert File.exists?(File.join(@ws_dir, "test/.riminfo"))
48
+ end
49
+
50
+ def test_files_ignored_by_gitignore_of_workspace_are_copied_to_working_dir
51
+ RIM::git_session(@remote_git_dir) do |s|
52
+ write_file(@remote_git_dir, 'ignored_file.txt')
53
+ s.execute("git add .")
54
+ s.execute("git commit -m \"Add a single file\"")
55
+ end
56
+ RIM::git_session(@ws_dir) do |s|
57
+ write_file(@ws_dir, '.gitignore', 'ignored*\n')
58
+ s.execute("git add .")
59
+ s.execute("git commit -m \"Ignore a single file\"")
60
+ end
61
+ info = RIM::ModuleInfo.new(@remote_git_dir_url, "test", "testbr")
62
+ cut = RIM::SyncModuleHelper.new(@ws_dir, @ws_dir, info, @logger)
63
+ cut.sync
64
+ assert File.exists?(File.join(@ws_dir, "test/readme.txt"))
65
+ assert File.exists?(File.join(@ws_dir, "test/.riminfo"))
66
+ assert File.exists?(File.join(@ws_dir, "test/ignored_file.txt"))
67
+ # Add a single ignored file afterwards and sync again
68
+ RIM::git_session(@remote_git_dir) do |s|
69
+ write_file(@remote_git_dir, 'ignored_file_2.txt')
70
+ s.execute("git add .")
71
+ s.execute("git commit -m \"Add a second ignored file\"")
72
+ end
73
+ cut.sync
74
+ assert File.exists?(File.join(@ws_dir, "test/readme.txt"))
75
+ assert File.exists?(File.join(@ws_dir, "test/.riminfo"))
76
+ assert File.exists?(File.join(@ws_dir, "test/ignored_file.txt"))
77
+ assert File.exists?(File.join(@ws_dir, "test/ignored_file_2.txt"))
78
+ end
79
+
80
+ def test_files_of_ignore_list_are_not_removed_when_copying
81
+ test_folder = File.join(@ws_dir, "test")
82
+ write_file(test_folder, "file1")
83
+ write_file(test_folder, "file2")
84
+ write_file(File.join(test_folder, "folder"), "file1")
85
+ write_file(File.join(test_folder, "folder"), "file2")
86
+ write_file(File.join(test_folder, "folder2"), "file1")
87
+ info = RIM::ModuleInfo.new(@remote_git_dir_url, "test", "testbr", "**/file2")
88
+ cut = RIM::SyncModuleHelper.new(@ws_dir, @ws_dir, info, @logger)
89
+ cut.sync
90
+ assert File.exists?(File.join(test_folder, "readme.txt"))
91
+ assert File.exists?(File.join(test_folder, ".riminfo"))
92
+ assert !File.exists?(File.join(test_folder, "file1"))
93
+ assert File.exists?(File.join(test_folder, "file2"))
94
+ assert !File.exists?(File.join(test_folder, "folder/file1"))
95
+ assert File.exists?(File.join(test_folder, "folder/file2"))
96
+ assert File.exists?(File.join(test_folder, "folder/file2"))
97
+ end
98
+
99
+ def test_commit_message_is_set_by_default
100
+ info = RIM::ModuleInfo.new(@remote_git_dir_url, "test", "testbr")
101
+ cut = RIM::SyncModuleHelper.new(@ws_dir, @ws_dir, info, @logger)
102
+ cut.sync
103
+ RIM::git_session(@ws_dir) do |s|
104
+ out = s.execute("git log HEAD~1..HEAD")
105
+ assert out.include?("rim sync: module")
106
+ end
107
+ end
108
+
109
+ def test_commit_message_can_be_changed
110
+ info = RIM::ModuleInfo.new(@remote_git_dir_url, "test", "testbr")
111
+ cut = RIM::SyncModuleHelper.new(@ws_dir, @ws_dir, info, @logger)
112
+ cut.sync("This is the commit header.")
113
+ RIM::git_session(@ws_dir) do |s|
114
+ out = s.execute("git log HEAD~1..HEAD")
115
+ assert out.include?("This is the commit header.\n")
116
+ end
117
+ end
118
+
119
+ def write_file(dir, name, content = nil)
120
+ FileUtils.mkdir_p(dir)
121
+ File.open(File.join(dir, name), "w") do |f|
122
+ f.write(content || "Content of #{name}\n")
123
+ end
124
+ end
125
+
126
+ end
@@ -1,403 +1,403 @@
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/rim_info'
8
- require 'rim/status_builder'
9
- require 'rim/sync_helper'
10
- require 'rim/upload_helper'
11
- require 'test_helper'
12
- require 'fileutils'
13
-
14
- class UploadHelperTest < Minitest::Test
15
- include FileUtils
16
- include TestHelper
17
-
18
- def setup
19
- test_dir = empty_test_dir("upload_helper_test")
20
- @remote_git_dir = File.join(test_dir, "remote_git")
21
- @ws_remote_dir = File.join(test_dir, "remote_ws")
22
- @ws_dir = File.join(test_dir, "ws")
23
- @logger = Logger.new($stdout)
24
- @logger.level = Logger::ERROR unless ARGV.include? "debug"
25
- RIM::GitSession.logger = @logger
26
- end
27
-
28
- def teardown
29
- remove_test_dirs
30
- end
31
-
32
- def test_no_files_are_uploaded_if_not_dirty
33
- mod1_info = create_module_git("mod1")
34
- sha1 = nil
35
- module_session(mod1_info) do |s|
36
- sha1 = s.rev_sha1("HEAD")
37
- end
38
- mod2_info = create_module_git("mod2")
39
- create_ws_git("testbr")
40
- sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info, mod2_info])
41
- sync_helper.sync
42
- RIM::git_session(@ws_dir) do |s|
43
- s.execute("git rebase rim/testbr")
44
- end
45
- cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod1_info, mod2_info])
46
- cut.upload
47
- module_session(mod1_info) do |s|
48
- assert s.rev_sha1("master") == sha1
49
- end
50
- end
51
-
52
- def test_files_of_new_commits_are_uploaded
53
- mod1_info = create_module_git("mod1")
54
- create_ws_git("testbr")
55
- sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
56
- sync_helper.sync
57
- RIM::git_session(@ws_dir) do |s|
58
- s.execute("git rebase rim/testbr")
59
- end
60
- shas = []
61
- # make two changes to module
62
- RIM::git_session(@ws_dir) do |s|
63
- `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
64
- s.execute("git commit . -m \"First change\"")
65
- shas.push(s.rev_sha1("HEAD"))
66
- `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
67
- s.execute("git add .")
68
- s.execute("git commit . -m \"Second change\"")
69
- shas.push(s.rev_sha1("HEAD"))
70
- end
71
- cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod1_info])
72
- cut.upload
73
- module_session(mod1_info) do |s|
74
- s.execute("git checkout master")
75
- assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
76
- assert File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
77
- assert s.execute("git show -s --format=%B HEAD").start_with?("Second change")
78
- assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
79
- end
80
- end
81
-
82
- def test_files_of_new_commits_are_uploaded_subdir
83
- mod_git_dir = create_all_module_git("mod_all")
84
- mod_a_info = RIM::ModuleInfo.new("file://" + mod_git_dir, "modules/a", "master", nil, nil, "mod_a")
85
- create_ws_git("testbr")
86
- sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod_a_info])
87
- sync_helper.sync
88
- RIM::git_session(@ws_dir) do |s|
89
- s.execute("git rebase rim/testbr")
90
- end
91
- shas = []
92
- # make two changes to module
93
- RIM::git_session(@ws_dir) do |s|
94
- `echo ' appended' >> #{File.join(@ws_dir, "modules/a/file_a.c")}`
95
- s.execute("git commit . -m \"First change\"")
96
- shas.push(s.rev_sha1("HEAD"))
97
- `echo 'Test' > #{File.join(@ws_dir, "modules/a/new_file.txt")}`
98
- s.execute("git add .")
99
- s.execute("git commit . -m \"Second change\"")
100
- shas.push(s.rev_sha1("HEAD"))
101
- end
102
- cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod_a_info])
103
-
104
- module_session(mod_a_info) do |s|
105
- s.execute("git checkout --detach master")
106
- assert File.exist?(File.join(mod_git_dir, "mod_a", "file_a.c"))
107
- assert !File.exist?(File.join(mod_git_dir, "mod_a", "new_file.txt"))
108
- assert File.exist?(File.join(mod_git_dir, "mod_b", "src", "file_b.c"))
109
- end
110
-
111
- cut.upload
112
-
113
- module_session(mod_a_info) do |s|
114
- s.execute("git checkout --detach master")
115
- assert File.exist?(File.join(mod_git_dir, "mod_a", "file_a.c"))
116
- assert File.exist?(File.join(mod_git_dir, "mod_a", "new_file.txt"))
117
- assert File.exist?(File.join(mod_git_dir, "mod_b", "src", "file_b.c"))
118
- assert s.execute("git show -s --format=%B HEAD").start_with?("Second change")
119
- assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
120
- end
121
- end
122
-
123
- def test_files_of_new_commits_are_uploaded_to_push_branch
124
- mod1_info = create_module_git("mod1", "master", "for/%s")
125
- create_ws_git("testbr")
126
- sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
127
- sync_helper.sync
128
- RIM::git_session(@ws_dir) do |s|
129
- s.execute("git rebase rim/testbr")
130
- end
131
- shas = []
132
- # make two changes to module
133
- RIM::git_session(@ws_dir) do |s|
134
- `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
135
- s.execute("git commit . -m \"First change\"")
136
- shas.push(s.rev_sha1("HEAD"))
137
- `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
138
- s.execute("git add .")
139
- s.execute("git commit . -m \"Second change\"")
140
- shas.push(s.rev_sha1("HEAD"))
141
- end
142
- cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod1_info])
143
- cut.upload
144
- module_session(mod1_info) do |s|
145
- s.execute("git checkout for/master")
146
- assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
147
- assert File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
148
- assert s.execute("git show -s --format=%B HEAD").start_with?("Second change")
149
- assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
150
- end
151
- end
152
-
153
- def test_files_of_new_commits_are_uploaded_to_direct_branch
154
- mod1_info = create_module_git("mod1", "master", "for/%s")
155
- create_ws_git("testbr")
156
- sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
157
- sync_helper.sync
158
- RIM::git_session(@ws_dir) do |s|
159
- s.execute("git rebase rim/testbr")
160
- end
161
- shas = []
162
- # make two changes to module
163
- RIM::git_session(@ws_dir) do |s|
164
- `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
165
- s.execute("git commit . -m \"First change\"")
166
- shas.push(s.rev_sha1("HEAD"))
167
- `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
168
- s.execute("git add .")
169
- s.execute("git commit . -m \"Second change\"")
170
- shas.push(s.rev_sha1("HEAD"))
171
- end
172
- cut = RIM::UploadHelper.new(@ws_dir, false, @logger, [mod1_info])
173
- cut.upload
174
- module_session(mod1_info) do |s|
175
- s.execute("git checkout master")
176
- assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
177
- assert File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
178
- assert s.execute("git show -s --format=%B HEAD").start_with?("Second change")
179
- assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
180
- end
181
- end
182
-
183
- def test_files_of_new_commits_are_uploaded_without_ignores
184
- mod1_info = create_module_git("mod1")
185
- create_ws_git("testbr")
186
- sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
187
- sync_helper.sync
188
- RIM::git_session(@ws_dir) do |s|
189
- s.execute("git rebase rim/testbr")
190
- end
191
- shas = []
192
- # make two changes to module
193
- RIM::git_session(@ws_dir) do |s|
194
- `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
195
- s.execute("git commit . -m \"First change\"")
196
- shas.push(s.rev_sha1("HEAD"))
197
- `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
198
- # Adjust rim_info to contain the file as ignored file
199
- rim_info = RIM::RimInfo.from_dir(File.join(@ws_dir, "mod1"))
200
- rim_info.ignores = "new_file.txt"
201
- rim_info.to_dir(File.join(@ws_dir, "mod1"))
202
- `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file2.txt")}`
203
- s.execute("git add .")
204
- s.execute("git commit . -m \"Second change\"")
205
- shas.push(s.rev_sha1("HEAD"))
206
- end
207
- cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod1_info])
208
- cut.upload
209
- module_session(mod1_info) do |s|
210
- s.execute("git checkout master")
211
- assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
212
- assert !File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
213
- assert File.exist?(File.join(@remote_git_dir, "mod1/new_file2.txt"))
214
- assert s.execute("git show -s --format=%B HEAD").start_with?("Second change")
215
- assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
216
- end
217
- end
218
-
219
- def test_files_of_amended_commits_are_uploaded
220
- mod1_info = create_module_git("mod1")
221
- create_ws_git("testbr")
222
- sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
223
- sync_helper.sync
224
- RIM::git_session(@ws_dir) do |s|
225
- s.execute("git rebase rim/testbr")
226
- end
227
- shas = []
228
- # make two changes to module
229
- RIM::git_session(@ws_dir) do |s|
230
- `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
231
- s.execute("git commit . -m \"First change\"")
232
- shas.push(s.rev_sha1("HEAD"))
233
- `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
234
- `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file2.txt")}`
235
- s.execute("git add .")
236
- s.execute("git commit . -m \"Second change\"")
237
- shas.push(s.rev_sha1("HEAD"))
238
- end
239
- cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod1_info])
240
- cut.upload
241
- module_session(mod1_info) do |s|
242
- s.execute("git checkout master")
243
- assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
244
- assert File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
245
- assert File.exist?(File.join(@remote_git_dir, "mod1/new_file2.txt"))
246
- assert s.execute("git show -s --format=%B HEAD").start_with?("Second change")
247
- assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
248
- s.execute("git checkout --detach master")
249
- s.execute("git branch -D master")
250
- end
251
- # reset testbr now on previous commit and commit new change
252
- RIM::git_session(@ws_dir) do |s|
253
- s.execute("git checkout -B testbr HEAD~1")
254
- `echo 'Test' > #{File.join(@ws_dir, "mod1/test_file.txt")}`
255
- s.execute("git add .")
256
- s.execute("git commit . -m \"Third change\"")
257
- end
258
- cut.upload
259
- module_session(mod1_info) do |s|
260
- s.execute("git checkout master")
261
- assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
262
- assert File.exist?(File.join(@remote_git_dir, "mod1/test_file.txt"))
263
- assert !File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
264
- assert !File.exist?(File.join(@remote_git_dir, "mod1/new_file2.txt"))
265
- assert s.execute("git show -s --format=%B HEAD").start_with?("Third change")
266
- assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
267
- end
268
- end
269
-
270
- def test_files_of_merged_commits_are_uploaded
271
- mod1_info = create_module_git("mod1")
272
- create_ws_git("testbr")
273
- sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
274
- sync_helper.sync
275
- RIM::git_session(@ws_dir) do |s|
276
- s.execute("git rebase rim/testbr")
277
- end
278
- shas = []
279
- # make two changes to module
280
- RIM::git_session(@ws_dir) do |s|
281
- `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
282
- s.execute("git commit . -m \"First change\"")
283
- #shas.push(s.rev_sha1("HEAD"))
284
- `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
285
- `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file2.txt")}`
286
- s.execute("git add .")
287
- s.execute("git commit . -m \"Second change\"")
288
- shas.push(s.rev_sha1("HEAD"))
289
- end
290
- cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod1_info])
291
- cut.upload
292
- module_session(mod1_info) do |s|
293
- s.execute("git checkout --detach master")
294
- s.execute("git branch -D master")
295
- end
296
- # reset testbr now on previous commit and commit new change
297
- RIM::git_session(@ws_dir) do |s|
298
- s.execute("git checkout -B testbr HEAD~2")
299
- `echo 'Test' > #{File.join(@ws_dir, "mod1/test_file.txt")}`
300
- s.execute("git add .")
301
- s.execute("git commit . -m \"Third change\"")
302
- end
303
- cut.upload
304
- module_session(mod1_info) do |s|
305
- s.execute("git checkout --detach master")
306
- s.execute("git branch -D master")
307
- end
308
- # now merge the commits
309
- RIM::git_session(@ws_dir) do |s|
310
- s.execute("git merge #{shas[0]} --commit")
311
- end
312
- cut.upload
313
- module_session(mod1_info) do |s|
314
- s.execute("git checkout master")
315
- assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
316
- assert File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
317
- assert File.exist?(File.join(@remote_git_dir, "mod1/new_file2.txt"))
318
- assert File.exist?(File.join(@remote_git_dir, "mod1/test_file.txt"))
319
- assert s.execute("git show -s --format=%B HEAD").start_with?("Merge commit")
320
- assert s.execute("git show -s --format=%B HEAD~1").start_with?("Third change")
321
- end
322
- end
323
-
324
- private
325
- def create_ws_git(branch = "master")
326
- FileUtils.mkdir_p(@ws_remote_dir)
327
- RIM::git_session(@ws_remote_dir) do |s|
328
- s.execute("git init")
329
- s.execute("git checkout -B #{branch}")
330
- File.open(File.join(@ws_remote_dir, ".gitignore"), "w") do |f|
331
- f.write(".rim")
332
- end
333
- File.open(File.join(@ws_remote_dir, "readme"), "w") do |f|
334
- f.write("Content")
335
- end
336
- s.execute("git add .")
337
- s.execute("git commit -m \"Initial commit\"")
338
- s.execute("git checkout --detach #{branch}")
339
- end
340
- FileUtils.mkdir_p(@ws_dir)
341
- RIM::git_session(@ws_dir) do |s|
342
- s.execute("git clone #{@ws_remote_dir} #{@ws_dir}")
343
- end
344
- end
345
-
346
- def create_module_git(name, branch = "master", remote_branch_format = nil)
347
- git_dir = File.join(@remote_git_dir, name)
348
- FileUtils.mkdir_p(git_dir)
349
- RIM::git_session(git_dir) do |s|
350
- s.execute("git init")
351
- s.execute("git checkout -B #{branch}")
352
- File.open(File.join(git_dir, "readme.txt"), "w") do |f|
353
- f.write("Content.")
354
- end
355
- s.execute("git add .")
356
- s.execute("git commit -m \"Initial commit\"")
357
- s.execute("git checkout --detach #{branch}")
358
- end
359
- return RIM::ModuleInfo.new("file://" + git_dir, name, branch, nil, remote_branch_format)
360
- end
361
-
362
- def create_all_module_git(name, branch = "master")
363
- git_dir = File.join(@remote_git_dir, name)
364
- FileUtils.mkdir_p(File.join(git_dir,"mod_a"))
365
- FileUtils.mkdir_p(File.join(git_dir,"mod_b","src"))
366
- RIM::git_session(git_dir) do |s|
367
- s.execute("git init")
368
- s.execute("git checkout -B #{branch}")
369
- File.open(File.join(git_dir, "readme.txt"), "w") do |f|
370
- f.write("Content.")
371
- end
372
- File.open(File.join(git_dir, "mod_a", "file_a.c"), "w") do |f|
373
- f.write("Content.")
374
- end
375
- File.open(File.join(git_dir, "mod_b", "src", "file_b.c"), "w") do |f|
376
- f.write("Content.")
377
- end
378
- s.execute("git add .")
379
- s.execute("git commit -m \"Initial commit\"")
380
- s.execute("git checkout --detach #{branch}")
381
- end
382
- return git_dir
383
- end
384
-
385
-
386
- def module_session(module_info)
387
- RIM::git_session(module_info.remote_url.gsub(/^file:\/\//, "")) do |s|
388
- yield s
389
- end
390
- end
391
-
392
- def check_not_dirty(session)
393
- status = RIM::StatusBuilder.new.rev_status(session, "HEAD")
394
- status.modules.each do |m|
395
- assert !m.dirty?
396
- end
397
- end
398
-
399
- def has_ancestor?(session, rev, ancestor)
400
- rev = session.execute("git rev-list #{rev}").include?(session.rev_sha1(ancestor))
401
- end
402
-
403
- 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/rim_info'
8
+ require 'rim/status_builder'
9
+ require 'rim/sync_helper'
10
+ require 'rim/upload_helper'
11
+ require 'test_helper'
12
+ require 'fileutils'
13
+
14
+ class UploadHelperTest < Minitest::Test
15
+ include FileUtils
16
+ include TestHelper
17
+
18
+ def setup
19
+ test_dir = empty_test_dir("upload_helper_test")
20
+ @remote_git_dir = File.join(test_dir, "remote_git")
21
+ @ws_remote_dir = File.join(test_dir, "remote_ws")
22
+ @ws_dir = File.join(test_dir, "ws")
23
+ @logger = Logger.new($stdout)
24
+ @logger.level = Logger::ERROR unless ARGV.include? "debug"
25
+ RIM::GitSession.logger = @logger
26
+ end
27
+
28
+ def teardown
29
+ remove_test_dirs
30
+ end
31
+
32
+ def test_no_files_are_uploaded_if_not_dirty
33
+ mod1_info = create_module_git("mod1")
34
+ sha1 = nil
35
+ module_session(mod1_info) do |s|
36
+ sha1 = s.rev_sha1("HEAD")
37
+ end
38
+ mod2_info = create_module_git("mod2")
39
+ create_ws_git("testbr")
40
+ sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info, mod2_info])
41
+ sync_helper.sync
42
+ RIM::git_session(@ws_dir) do |s|
43
+ s.execute("git rebase rim/testbr")
44
+ end
45
+ cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod1_info, mod2_info])
46
+ cut.upload
47
+ module_session(mod1_info) do |s|
48
+ assert s.rev_sha1("master") == sha1
49
+ end
50
+ end
51
+
52
+ def test_files_of_new_commits_are_uploaded
53
+ mod1_info = create_module_git("mod1")
54
+ create_ws_git("testbr")
55
+ sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
56
+ sync_helper.sync
57
+ RIM::git_session(@ws_dir) do |s|
58
+ s.execute("git rebase rim/testbr")
59
+ end
60
+ shas = []
61
+ # make two changes to module
62
+ RIM::git_session(@ws_dir) do |s|
63
+ `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
64
+ s.execute("git commit . -m \"First change\"")
65
+ shas.push(s.rev_sha1("HEAD"))
66
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
67
+ s.execute("git add .")
68
+ s.execute("git commit . -m \"Second change\"")
69
+ shas.push(s.rev_sha1("HEAD"))
70
+ end
71
+ cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod1_info])
72
+ cut.upload
73
+ module_session(mod1_info) do |s|
74
+ s.execute("git checkout master")
75
+ assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
76
+ assert File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
77
+ assert s.execute("git show -s --format=%B HEAD").start_with?("Second change")
78
+ assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
79
+ end
80
+ end
81
+
82
+ def test_files_of_new_commits_are_uploaded_subdir
83
+ mod_git_dir = create_all_module_git("mod_all")
84
+ mod_a_info = RIM::ModuleInfo.new("file://" + mod_git_dir, "modules/a", "master", nil, nil, "mod_a")
85
+ create_ws_git("testbr")
86
+ sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod_a_info])
87
+ sync_helper.sync
88
+ RIM::git_session(@ws_dir) do |s|
89
+ s.execute("git rebase rim/testbr")
90
+ end
91
+ shas = []
92
+ # make two changes to module
93
+ RIM::git_session(@ws_dir) do |s|
94
+ `echo ' appended' >> #{File.join(@ws_dir, "modules/a/file_a.c")}`
95
+ s.execute("git commit . -m \"First change\"")
96
+ shas.push(s.rev_sha1("HEAD"))
97
+ `echo 'Test' > #{File.join(@ws_dir, "modules/a/new_file.txt")}`
98
+ s.execute("git add .")
99
+ s.execute("git commit . -m \"Second change\"")
100
+ shas.push(s.rev_sha1("HEAD"))
101
+ end
102
+ cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod_a_info])
103
+
104
+ module_session(mod_a_info) do |s|
105
+ s.execute("git checkout --detach master")
106
+ assert File.exist?(File.join(mod_git_dir, "mod_a", "file_a.c"))
107
+ assert !File.exist?(File.join(mod_git_dir, "mod_a", "new_file.txt"))
108
+ assert File.exist?(File.join(mod_git_dir, "mod_b", "src", "file_b.c"))
109
+ end
110
+
111
+ cut.upload
112
+
113
+ module_session(mod_a_info) do |s|
114
+ s.execute("git checkout --detach master")
115
+ assert File.exist?(File.join(mod_git_dir, "mod_a", "file_a.c"))
116
+ assert File.exist?(File.join(mod_git_dir, "mod_a", "new_file.txt"))
117
+ assert File.exist?(File.join(mod_git_dir, "mod_b", "src", "file_b.c"))
118
+ assert s.execute("git show -s --format=%B HEAD").start_with?("Second change")
119
+ assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
120
+ end
121
+ end
122
+
123
+ def test_files_of_new_commits_are_uploaded_to_push_branch
124
+ mod1_info = create_module_git("mod1", "master", "for/%s")
125
+ create_ws_git("testbr")
126
+ sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
127
+ sync_helper.sync
128
+ RIM::git_session(@ws_dir) do |s|
129
+ s.execute("git rebase rim/testbr")
130
+ end
131
+ shas = []
132
+ # make two changes to module
133
+ RIM::git_session(@ws_dir) do |s|
134
+ `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
135
+ s.execute("git commit . -m \"First change\"")
136
+ shas.push(s.rev_sha1("HEAD"))
137
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
138
+ s.execute("git add .")
139
+ s.execute("git commit . -m \"Second change\"")
140
+ shas.push(s.rev_sha1("HEAD"))
141
+ end
142
+ cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod1_info])
143
+ cut.upload
144
+ module_session(mod1_info) do |s|
145
+ s.execute("git checkout for/master")
146
+ assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
147
+ assert File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
148
+ assert s.execute("git show -s --format=%B HEAD").start_with?("Second change")
149
+ assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
150
+ end
151
+ end
152
+
153
+ def test_files_of_new_commits_are_uploaded_to_direct_branch
154
+ mod1_info = create_module_git("mod1", "master", "for/%s")
155
+ create_ws_git("testbr")
156
+ sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
157
+ sync_helper.sync
158
+ RIM::git_session(@ws_dir) do |s|
159
+ s.execute("git rebase rim/testbr")
160
+ end
161
+ shas = []
162
+ # make two changes to module
163
+ RIM::git_session(@ws_dir) do |s|
164
+ `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
165
+ s.execute("git commit . -m \"First change\"")
166
+ shas.push(s.rev_sha1("HEAD"))
167
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
168
+ s.execute("git add .")
169
+ s.execute("git commit . -m \"Second change\"")
170
+ shas.push(s.rev_sha1("HEAD"))
171
+ end
172
+ cut = RIM::UploadHelper.new(@ws_dir, false, @logger, [mod1_info])
173
+ cut.upload
174
+ module_session(mod1_info) do |s|
175
+ s.execute("git checkout master")
176
+ assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
177
+ assert File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
178
+ assert s.execute("git show -s --format=%B HEAD").start_with?("Second change")
179
+ assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
180
+ end
181
+ end
182
+
183
+ def test_files_of_new_commits_are_uploaded_without_ignores
184
+ mod1_info = create_module_git("mod1")
185
+ create_ws_git("testbr")
186
+ sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
187
+ sync_helper.sync
188
+ RIM::git_session(@ws_dir) do |s|
189
+ s.execute("git rebase rim/testbr")
190
+ end
191
+ shas = []
192
+ # make two changes to module
193
+ RIM::git_session(@ws_dir) do |s|
194
+ `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
195
+ s.execute("git commit . -m \"First change\"")
196
+ shas.push(s.rev_sha1("HEAD"))
197
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
198
+ # Adjust rim_info to contain the file as ignored file
199
+ rim_info = RIM::RimInfo.from_dir(File.join(@ws_dir, "mod1"))
200
+ rim_info.ignores = "new_file.txt"
201
+ rim_info.to_dir(File.join(@ws_dir, "mod1"))
202
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file2.txt")}`
203
+ s.execute("git add .")
204
+ s.execute("git commit . -m \"Second change\"")
205
+ shas.push(s.rev_sha1("HEAD"))
206
+ end
207
+ cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod1_info])
208
+ cut.upload
209
+ module_session(mod1_info) do |s|
210
+ s.execute("git checkout master")
211
+ assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
212
+ assert !File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
213
+ assert File.exist?(File.join(@remote_git_dir, "mod1/new_file2.txt"))
214
+ assert s.execute("git show -s --format=%B HEAD").start_with?("Second change")
215
+ assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
216
+ end
217
+ end
218
+
219
+ def test_files_of_amended_commits_are_uploaded
220
+ mod1_info = create_module_git("mod1")
221
+ create_ws_git("testbr")
222
+ sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
223
+ sync_helper.sync
224
+ RIM::git_session(@ws_dir) do |s|
225
+ s.execute("git rebase rim/testbr")
226
+ end
227
+ shas = []
228
+ # make two changes to module
229
+ RIM::git_session(@ws_dir) do |s|
230
+ `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
231
+ s.execute("git commit . -m \"First change\"")
232
+ shas.push(s.rev_sha1("HEAD"))
233
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
234
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file2.txt")}`
235
+ s.execute("git add .")
236
+ s.execute("git commit . -m \"Second change\"")
237
+ shas.push(s.rev_sha1("HEAD"))
238
+ end
239
+ cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod1_info])
240
+ cut.upload
241
+ module_session(mod1_info) do |s|
242
+ s.execute("git checkout master")
243
+ assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
244
+ assert File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
245
+ assert File.exist?(File.join(@remote_git_dir, "mod1/new_file2.txt"))
246
+ assert s.execute("git show -s --format=%B HEAD").start_with?("Second change")
247
+ assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
248
+ s.execute("git checkout --detach master")
249
+ s.execute("git branch -D master")
250
+ end
251
+ # reset testbr now on previous commit and commit new change
252
+ RIM::git_session(@ws_dir) do |s|
253
+ s.execute("git checkout -B testbr HEAD~1")
254
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/test_file.txt")}`
255
+ s.execute("git add .")
256
+ s.execute("git commit . -m \"Third change\"")
257
+ end
258
+ cut.upload
259
+ module_session(mod1_info) do |s|
260
+ s.execute("git checkout master")
261
+ assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
262
+ assert File.exist?(File.join(@remote_git_dir, "mod1/test_file.txt"))
263
+ assert !File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
264
+ assert !File.exist?(File.join(@remote_git_dir, "mod1/new_file2.txt"))
265
+ assert s.execute("git show -s --format=%B HEAD").start_with?("Third change")
266
+ assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
267
+ end
268
+ end
269
+
270
+ def test_files_of_merged_commits_are_uploaded
271
+ mod1_info = create_module_git("mod1")
272
+ create_ws_git("testbr")
273
+ sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
274
+ sync_helper.sync
275
+ RIM::git_session(@ws_dir) do |s|
276
+ s.execute("git rebase rim/testbr")
277
+ end
278
+ shas = []
279
+ # make two changes to module
280
+ RIM::git_session(@ws_dir) do |s|
281
+ `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
282
+ s.execute("git commit . -m \"First change\"")
283
+ #shas.push(s.rev_sha1("HEAD"))
284
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
285
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file2.txt")}`
286
+ s.execute("git add .")
287
+ s.execute("git commit . -m \"Second change\"")
288
+ shas.push(s.rev_sha1("HEAD"))
289
+ end
290
+ cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod1_info])
291
+ cut.upload
292
+ module_session(mod1_info) do |s|
293
+ s.execute("git checkout --detach master")
294
+ s.execute("git branch -D master")
295
+ end
296
+ # reset testbr now on previous commit and commit new change
297
+ RIM::git_session(@ws_dir) do |s|
298
+ s.execute("git checkout -B testbr HEAD~2")
299
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/test_file.txt")}`
300
+ s.execute("git add .")
301
+ s.execute("git commit . -m \"Third change\"")
302
+ end
303
+ cut.upload
304
+ module_session(mod1_info) do |s|
305
+ s.execute("git checkout --detach master")
306
+ s.execute("git branch -D master")
307
+ end
308
+ # now merge the commits
309
+ RIM::git_session(@ws_dir) do |s|
310
+ s.execute("git merge #{shas[0]} --commit")
311
+ end
312
+ cut.upload
313
+ module_session(mod1_info) do |s|
314
+ s.execute("git checkout master")
315
+ assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
316
+ assert File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
317
+ assert File.exist?(File.join(@remote_git_dir, "mod1/new_file2.txt"))
318
+ assert File.exist?(File.join(@remote_git_dir, "mod1/test_file.txt"))
319
+ assert s.execute("git show -s --format=%B HEAD").start_with?("Merge commit")
320
+ assert s.execute("git show -s --format=%B HEAD~1").start_with?("Third change")
321
+ end
322
+ end
323
+
324
+ private
325
+ def create_ws_git(branch = "master")
326
+ FileUtils.mkdir_p(@ws_remote_dir)
327
+ RIM::git_session(@ws_remote_dir) do |s|
328
+ s.execute("git init")
329
+ s.execute("git checkout -B #{branch}")
330
+ File.open(File.join(@ws_remote_dir, ".gitignore"), "w") do |f|
331
+ f.write(".rim")
332
+ end
333
+ File.open(File.join(@ws_remote_dir, "readme"), "w") do |f|
334
+ f.write("Content")
335
+ end
336
+ s.execute("git add .")
337
+ s.execute("git commit -m \"Initial commit\"")
338
+ s.execute("git checkout --detach #{branch}")
339
+ end
340
+ FileUtils.mkdir_p(@ws_dir)
341
+ RIM::git_session(@ws_dir) do |s|
342
+ s.execute("git clone #{@ws_remote_dir} #{@ws_dir}")
343
+ end
344
+ end
345
+
346
+ def create_module_git(name, branch = "master", remote_branch_format = nil)
347
+ git_dir = File.join(@remote_git_dir, name)
348
+ FileUtils.mkdir_p(git_dir)
349
+ RIM::git_session(git_dir) do |s|
350
+ s.execute("git init")
351
+ s.execute("git checkout -B #{branch}")
352
+ File.open(File.join(git_dir, "readme.txt"), "w") do |f|
353
+ f.write("Content.")
354
+ end
355
+ s.execute("git add .")
356
+ s.execute("git commit -m \"Initial commit\"")
357
+ s.execute("git checkout --detach #{branch}")
358
+ end
359
+ return RIM::ModuleInfo.new("file://" + git_dir, name, branch, nil, remote_branch_format)
360
+ end
361
+
362
+ def create_all_module_git(name, branch = "master")
363
+ git_dir = File.join(@remote_git_dir, name)
364
+ FileUtils.mkdir_p(File.join(git_dir,"mod_a"))
365
+ FileUtils.mkdir_p(File.join(git_dir,"mod_b","src"))
366
+ RIM::git_session(git_dir) do |s|
367
+ s.execute("git init")
368
+ s.execute("git checkout -B #{branch}")
369
+ File.open(File.join(git_dir, "readme.txt"), "w") do |f|
370
+ f.write("Content.")
371
+ end
372
+ File.open(File.join(git_dir, "mod_a", "file_a.c"), "w") do |f|
373
+ f.write("Content.")
374
+ end
375
+ File.open(File.join(git_dir, "mod_b", "src", "file_b.c"), "w") do |f|
376
+ f.write("Content.")
377
+ end
378
+ s.execute("git add .")
379
+ s.execute("git commit -m \"Initial commit\"")
380
+ s.execute("git checkout --detach #{branch}")
381
+ end
382
+ return git_dir
383
+ end
384
+
385
+
386
+ def module_session(module_info)
387
+ RIM::git_session(module_info.remote_url.gsub(/^file:\/\//, "")) do |s|
388
+ yield s
389
+ end
390
+ end
391
+
392
+ def check_not_dirty(session)
393
+ status = RIM::StatusBuilder.new.rev_status(session, "HEAD")
394
+ status.modules.each do |m|
395
+ assert !m.dirty?
396
+ end
397
+ end
398
+
399
+ def has_ancestor?(session, rev, ancestor)
400
+ rev = session.execute("git rev-list #{rev}").include?(session.rev_sha1(ancestor))
401
+ end
402
+
403
+ end