esr-rim 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +40 -0
  3. data/README.md +3 -0
  4. data/Rakefile +56 -0
  5. data/bin/rim +3 -0
  6. data/lib/rim/command/command.rb +37 -0
  7. data/lib/rim/command/status.rb +110 -0
  8. data/lib/rim/command/sync.rb +69 -0
  9. data/lib/rim/command/upload.rb +33 -0
  10. data/lib/rim/command_helper.rb +119 -0
  11. data/lib/rim/dirty_check.rb +111 -0
  12. data/lib/rim/file_helper.rb +58 -0
  13. data/lib/rim/file_logger.rb +21 -0
  14. data/lib/rim/git.rb +339 -0
  15. data/lib/rim/manifest/helper.rb +82 -0
  16. data/lib/rim/manifest/json_reader.rb +40 -0
  17. data/lib/rim/manifest/manifest.json +7 -0
  18. data/lib/rim/manifest/model.rb +33 -0
  19. data/lib/rim/manifest/repo_reader.rb +61 -0
  20. data/lib/rim/module_helper.rb +52 -0
  21. data/lib/rim/module_info.rb +30 -0
  22. data/lib/rim/processor.rb +126 -0
  23. data/lib/rim/rev_status.rb +61 -0
  24. data/lib/rim/rim.rb +93 -0
  25. data/lib/rim/rim_exception.rb +15 -0
  26. data/lib/rim/rim_info.rb +129 -0
  27. data/lib/rim/status_builder.rb +219 -0
  28. data/lib/rim/sync_helper.rb +121 -0
  29. data/lib/rim/sync_module_helper.rb +115 -0
  30. data/lib/rim/upload_helper.rb +67 -0
  31. data/lib/rim/upload_module_helper.rb +152 -0
  32. data/lib/rim/version.rb +10 -0
  33. data/test/dirty_check_test.rb +210 -0
  34. data/test/file_helper_test.rb +132 -0
  35. data/test/git_test.rb +49 -0
  36. data/test/manifest_helper_test.rb +29 -0
  37. data/test/manifest_test_dir/manifest.rim +9 -0
  38. data/test/manifest_test_dir/subdir/only_to_keep_folder_in_git.txt +0 -0
  39. data/test/processor_test.rb +32 -0
  40. data/test/rim_info_test.rb +93 -0
  41. data/test/status_builder_test.rb +488 -0
  42. data/test/sync_helper_test.rb +193 -0
  43. data/test/sync_module_helper_test.rb +96 -0
  44. data/test/test_helper.rb +39 -0
  45. data/test/unit_tests.rb +14 -0
  46. data/test/upload_helper_test.rb +338 -0
  47. data/test/upload_module_helper_test.rb +92 -0
  48. metadata +110 -0
@@ -0,0 +1,193 @@
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
+ end
48
+ end
49
+
50
+ def test_files_are_synchronized_on_existing_branch
51
+ mod1_info = create_module_git("mod1")
52
+ mod2_info = create_module_git("mod2")
53
+ create_ws_git("testbr")
54
+ cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info, mod2_info])
55
+ cut.sync
56
+ `echo ' changed' >> #{File.join(@ws_dir, "readme")}`
57
+ RIM::git_session(@ws_dir) do |s|
58
+ s.execute("git commit . -m \"Changed ws file\"")
59
+ end
60
+ remote_path = path_from_module_info(mod1_info)
61
+ `echo ' changed' >> #{File.join(remote_path, "readme.txt")}`
62
+ RIM::git_session(remote_path) do |f|
63
+ f.execute("git commit . -m \"Changed mod1 file\"")
64
+ end
65
+ cut.sync
66
+ RIM::git_session(@ws_dir) do |s|
67
+ s.execute("git checkout rim/testbr")
68
+ check_not_dirty(s)
69
+ log = s.execute("git log | grep \" module \"").split("\n").sort
70
+ assert log.size == 3
71
+ assert log[0].include?("mod1")
72
+ assert log[1].include?("mod1")
73
+ assert log[2].include?("mod2")
74
+ assert File.exist?(File.join(@ws_dir, "mod1"))
75
+ `cat #{File.join(@ws_dir, "mod1/readme.txt")}`.start_with?("Content. changed")
76
+ assert File.exist?(File.join(@ws_dir, "mod2"))
77
+ end
78
+ end
79
+
80
+ def test_files_are_synchronized_on_new_branch_if_behind_last_remote_commit
81
+ mod1_info = create_module_git("mod1")
82
+ mod2_info = create_module_git("mod2")
83
+ create_ws_git("testbr")
84
+ cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info, mod2_info])
85
+ cut.sync
86
+ `echo ' changed' >> #{File.join(@ws_remote_dir, "readme")}`
87
+ RIM::git_session(@ws_remote_dir) do |s|
88
+ s.execute("git commit . -m \"Changed ws file\"")
89
+ end
90
+ RIM::git_session(@ws_dir) do |s|
91
+ s.execute("git pull")
92
+ assert !has_ancestor?(s, "rim/testbr", "testbr")
93
+ end
94
+ cut.sync
95
+ RIM::git_session(@ws_dir) do |s|
96
+ assert has_ancestor?(s, "rim/testbr", "testbr")
97
+ end
98
+ end
99
+
100
+ def test_existing_non_ignored_files_are_removed_during_sync
101
+ mod1_info = create_module_git("mod1")
102
+ create_ws_git("testbr") do |s|
103
+ FileUtils.mkdir_p(File.join(@ws_remote_dir, "mod1"))
104
+ File.open(File.join(@ws_remote_dir, "mod1", "existing.txt"), "w") do |f|
105
+ f.write("Content")
106
+ end
107
+ s.execute("git add --all mod1")
108
+ s.execute("git commit -m \"Create existing file within mod1\"")
109
+ end
110
+ cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
111
+ cut.sync
112
+ RIM::git_session(@ws_dir) do |s|
113
+ s.execute("git rebase rim/testbr")
114
+ assert !File.exists?(File.join(@ws_dir, "mod1", "existing.txt"))
115
+ end
116
+ end
117
+
118
+ def test_case_change_in_filename_is_synced_correctly
119
+ mod1_info = create_module_git("mod1")
120
+ create_ws_git("testbr")
121
+ cut = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
122
+ cut.sync
123
+ remote_path = path_from_module_info(mod1_info)
124
+ RIM::git_session(remote_path) do |s|
125
+ FileUtils.mv(File.join(remote_path, "readme.txt"), File.join(remote_path, "readme.tx_"))
126
+ s.execute("git add --all .")
127
+ s.execute("git commit -m \"Temporary change of filename within mod1\"")
128
+ FileUtils.mv(File.join(remote_path, "readme.tx_"), File.join(remote_path, "Readme.txt"))
129
+ s.execute("git add --all .")
130
+ s.execute("git commit -m \"Changed case in filename within mod1\"")
131
+ end
132
+ cut.sync
133
+ RIM::git_session(@ws_dir) do |s|
134
+ s.execute("git rebase rim/testbr")
135
+ out = s.execute("git show --name-only")
136
+ assert out.include?("readme.txt")
137
+ assert out.include?("Readme.txt")
138
+ end
139
+ end
140
+
141
+ private
142
+ def create_ws_git(branch = "master")
143
+ FileUtils.mkdir_p(@ws_remote_dir)
144
+ RIM::git_session(@ws_remote_dir) do |s|
145
+ s.execute("git init")
146
+ s.execute("git checkout -B #{branch}")
147
+ File.open(File.join(@ws_remote_dir, ".gitignore"), "w") do |f|
148
+ f.write(".rim")
149
+ end
150
+ File.open(File.join(@ws_remote_dir, "readme"), "w") do |f|
151
+ f.write("Content")
152
+ end
153
+ s.execute("git add .")
154
+ s.execute("git commit -m \"Initial commit\"")
155
+ yield s if block_given?
156
+ end
157
+ FileUtils.mkdir_p(@ws_dir)
158
+ RIM::git_session(@ws_dir) do |s|
159
+ s.execute("git clone #{@ws_remote_dir} #{@ws_dir}")
160
+ end
161
+ end
162
+
163
+ def create_module_git(name, branch = "master")
164
+ git_dir = File.join(@remote_git_dir, name)
165
+ FileUtils.mkdir_p(git_dir)
166
+ RIM::git_session(git_dir) do |s|
167
+ s.execute("git init")
168
+ s.execute("git checkout -B #{branch}")
169
+ File.open(File.join(git_dir, "readme.txt"), "w") do |f|
170
+ f.write("Content.")
171
+ end
172
+ s.execute("git add .")
173
+ s.execute("git commit -m \"Initial commit\"")
174
+ end
175
+ return RIM::ModuleInfo.new("file://" + git_dir, name, branch)
176
+ end
177
+
178
+ def path_from_module_info(module_info)
179
+ module_info.remote_url.gsub(/^file:\/\//, "")
180
+ end
181
+
182
+ def check_not_dirty(session)
183
+ status = RIM::StatusBuilder.new.rev_status(session, "HEAD")
184
+ status.modules.each do |m|
185
+ assert !m.dirty?
186
+ end
187
+ end
188
+
189
+ def has_ancestor?(session, rev, ancestor)
190
+ rev = session.execute("git rev-list #{rev}").include?(session.rev_sha1(ancestor))
191
+ end
192
+
193
+ end
@@ -0,0 +1,96 @@
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 = "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} .")
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, "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_of_ignore_list_are_not_removed_when_copying
51
+ test_folder = File.join(@ws_dir, "test")
52
+ write_file(test_folder, "file1")
53
+ write_file(test_folder, "file2")
54
+ write_file(File.join(test_folder, "folder"), "file1")
55
+ write_file(File.join(test_folder, "folder"), "file2")
56
+ write_file(File.join(test_folder, "folder2"), "file1")
57
+ info = RIM::ModuleInfo.new(@remote_git_dir, "test", "testbr", "**/file2")
58
+ cut = RIM::SyncModuleHelper.new(@ws_dir, @ws_dir, info, @logger)
59
+ cut.sync
60
+ assert File.exists?(File.join(test_folder, "readme.txt"))
61
+ assert File.exists?(File.join(test_folder, ".riminfo"))
62
+ assert !File.exists?(File.join(test_folder, "file1"))
63
+ assert File.exists?(File.join(test_folder, "file2"))
64
+ assert !File.exists?(File.join(test_folder, "folder/file1"))
65
+ assert File.exists?(File.join(test_folder, "folder/file2"))
66
+ assert File.exists?(File.join(test_folder, "folder/file2"))
67
+ end
68
+
69
+ def test_commit_message_is_set_by_default
70
+ info = RIM::ModuleInfo.new(@remote_git_dir, "test", "testbr")
71
+ cut = RIM::SyncModuleHelper.new(@ws_dir, @ws_dir, info, @logger)
72
+ cut.sync
73
+ RIM::git_session(@ws_dir) do |s|
74
+ out = s.execute("git log HEAD~1..HEAD")
75
+ assert out.include?("rim sync: module")
76
+ end
77
+ end
78
+
79
+ def test_commit_message_can_be_changed
80
+ info = RIM::ModuleInfo.new(@remote_git_dir, "test", "testbr")
81
+ cut = RIM::SyncModuleHelper.new(@ws_dir, @ws_dir, info, @logger)
82
+ cut.sync("This is the commit header.")
83
+ RIM::git_session(@ws_dir) do |s|
84
+ out = s.execute("git log HEAD~1..HEAD")
85
+ assert out.include?("This is the commit header.\n")
86
+ end
87
+ end
88
+
89
+ def write_file(dir, name)
90
+ FileUtils.mkdir_p(dir)
91
+ File.open(File.join(dir, name), "w") do |f|
92
+ f.write("Content of #{name}\n")
93
+ end
94
+ end
95
+
96
+ end
@@ -0,0 +1,39 @@
1
+ require 'fileutils'
2
+
3
+ module TestHelper
4
+
5
+ def create_rim_info(dir, attrs)
6
+ FileUtils.mkdir_p dir
7
+ ri = RIM::RimInfo.new
8
+ attrs.each_pair do |k,v|
9
+ ri.send("#{k}=", v)
10
+ end
11
+ ri.to_dir(dir)
12
+ end
13
+
14
+ def empty_test_dir(dir)
15
+ # create directory in test folder
16
+ dir = File.dirname(__FILE__)+"/"+dir
17
+ rm_rf(dir)
18
+ mkdir_p(dir)
19
+ @test_dirs ||= []
20
+ @test_dirs << dir
21
+ dir
22
+ end
23
+
24
+ def write_file(path, content)
25
+ FileUtils.mkdir_p File.dirname(path)
26
+ File.open(path, "w") do |f|
27
+ f.write content
28
+ end
29
+ end
30
+
31
+ def remove_test_dirs
32
+ @test_dirs ||= []
33
+ @test_dirs.each do |d|
34
+ rm_rf(d)
35
+ end
36
+ @test_dirs = nil
37
+ end
38
+
39
+ end
@@ -0,0 +1,14 @@
1
+ $:.unshift File.join(File.dirname(__FILE__))
2
+
3
+ # include all unit tests here
4
+ require 'manifest_helper_test'
5
+ require 'file_helper_test'
6
+ require 'rim_info_test'
7
+ require 'dirty_check_test'
8
+ require 'status_builder_test'
9
+ require 'processor_test'
10
+ require 'sync_module_helper_test'
11
+ require 'sync_helper_test'
12
+ require 'upload_module_helper_test'
13
+ require 'upload_helper_test'
14
+ require 'git_test'
@@ -0,0 +1,338 @@
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_to_push_branch
83
+ mod1_info = create_module_git("mod1", "master", "for/%s")
84
+ create_ws_git("testbr")
85
+ sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
86
+ sync_helper.sync
87
+ RIM::git_session(@ws_dir) do |s|
88
+ s.execute("git rebase rim/testbr")
89
+ end
90
+ shas = []
91
+ # make two changes to module
92
+ RIM::git_session(@ws_dir) do |s|
93
+ `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
94
+ s.execute("git commit . -m \"First change\"")
95
+ shas.push(s.rev_sha1("HEAD"))
96
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
97
+ s.execute("git add .")
98
+ s.execute("git commit . -m \"Second change\"")
99
+ shas.push(s.rev_sha1("HEAD"))
100
+ end
101
+ cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod1_info])
102
+ cut.upload
103
+ module_session(mod1_info) do |s|
104
+ s.execute("git checkout for/master")
105
+ assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
106
+ assert File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
107
+ assert s.execute("git show -s --format=%B HEAD").start_with?("Second change")
108
+ assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
109
+ end
110
+ end
111
+
112
+ def test_files_of_new_commits_are_uploaded_to_direct_branch
113
+ mod1_info = create_module_git("mod1", "master", "for/%s")
114
+ create_ws_git("testbr")
115
+ sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
116
+ sync_helper.sync
117
+ RIM::git_session(@ws_dir) do |s|
118
+ s.execute("git rebase rim/testbr")
119
+ end
120
+ shas = []
121
+ # make two changes to module
122
+ RIM::git_session(@ws_dir) do |s|
123
+ `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
124
+ s.execute("git commit . -m \"First change\"")
125
+ shas.push(s.rev_sha1("HEAD"))
126
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
127
+ s.execute("git add .")
128
+ s.execute("git commit . -m \"Second change\"")
129
+ shas.push(s.rev_sha1("HEAD"))
130
+ end
131
+ cut = RIM::UploadHelper.new(@ws_dir, false, @logger, [mod1_info])
132
+ cut.upload
133
+ module_session(mod1_info) do |s|
134
+ s.execute("git checkout master")
135
+ assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
136
+ assert File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
137
+ assert s.execute("git show -s --format=%B HEAD").start_with?("Second change")
138
+ assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
139
+ end
140
+ end
141
+
142
+ def test_files_of_new_commits_are_uploaded_without_ignores
143
+ mod1_info = create_module_git("mod1")
144
+ create_ws_git("testbr")
145
+ sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
146
+ sync_helper.sync
147
+ RIM::git_session(@ws_dir) do |s|
148
+ s.execute("git rebase rim/testbr")
149
+ end
150
+ shas = []
151
+ # make two changes to module
152
+ RIM::git_session(@ws_dir) do |s|
153
+ `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
154
+ s.execute("git commit . -m \"First change\"")
155
+ shas.push(s.rev_sha1("HEAD"))
156
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
157
+ # Adjust rim_info to contain the file as ignored file
158
+ rim_info = RIM::RimInfo.from_dir(File.join(@ws_dir, "mod1"))
159
+ rim_info.ignores = "new_file.txt"
160
+ rim_info.to_dir(File.join(@ws_dir, "mod1"))
161
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file2.txt")}`
162
+ s.execute("git add .")
163
+ s.execute("git commit . -m \"Second change\"")
164
+ shas.push(s.rev_sha1("HEAD"))
165
+ end
166
+ cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod1_info])
167
+ cut.upload
168
+ module_session(mod1_info) do |s|
169
+ s.execute("git checkout master")
170
+ assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
171
+ assert !File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
172
+ assert File.exist?(File.join(@remote_git_dir, "mod1/new_file2.txt"))
173
+ assert s.execute("git show -s --format=%B HEAD").start_with?("Second change")
174
+ assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
175
+ end
176
+ end
177
+
178
+ def test_files_of_amended_commits_are_uploaded
179
+ mod1_info = create_module_git("mod1")
180
+ create_ws_git("testbr")
181
+ sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
182
+ sync_helper.sync
183
+ RIM::git_session(@ws_dir) do |s|
184
+ s.execute("git rebase rim/testbr")
185
+ end
186
+ shas = []
187
+ # make two changes to module
188
+ RIM::git_session(@ws_dir) do |s|
189
+ `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
190
+ s.execute("git commit . -m \"First change\"")
191
+ shas.push(s.rev_sha1("HEAD"))
192
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
193
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file2.txt")}`
194
+ s.execute("git add .")
195
+ s.execute("git commit . -m \"Second change\"")
196
+ shas.push(s.rev_sha1("HEAD"))
197
+ end
198
+ cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod1_info])
199
+ cut.upload
200
+ module_session(mod1_info) do |s|
201
+ s.execute("git checkout master")
202
+ assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
203
+ assert File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
204
+ assert File.exist?(File.join(@remote_git_dir, "mod1/new_file2.txt"))
205
+ assert s.execute("git show -s --format=%B HEAD").start_with?("Second change")
206
+ assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
207
+ s.execute("git checkout --detach master")
208
+ s.execute("git branch -D master")
209
+ end
210
+ # reset testbr now on previous commit and commit new change
211
+ RIM::git_session(@ws_dir) do |s|
212
+ s.execute("git checkout -B testbr HEAD~1")
213
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/test_file.txt")}`
214
+ s.execute("git add .")
215
+ s.execute("git commit . -m \"Third change\"")
216
+ end
217
+ cut.upload
218
+ module_session(mod1_info) do |s|
219
+ s.execute("git checkout master")
220
+ assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
221
+ assert File.exist?(File.join(@remote_git_dir, "mod1/test_file.txt"))
222
+ assert !File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
223
+ assert !File.exist?(File.join(@remote_git_dir, "mod1/new_file2.txt"))
224
+ assert s.execute("git show -s --format=%B HEAD").start_with?("Third change")
225
+ assert s.execute("git show -s --format=%B HEAD~1").start_with?("First change")
226
+ end
227
+ end
228
+
229
+ def test_files_of_merged_commits_are_uploaded
230
+ mod1_info = create_module_git("mod1")
231
+ create_ws_git("testbr")
232
+ sync_helper = RIM::SyncHelper.new(@ws_dir, @logger, [mod1_info])
233
+ sync_helper.sync
234
+ RIM::git_session(@ws_dir) do |s|
235
+ s.execute("git rebase rim/testbr")
236
+ end
237
+ shas = []
238
+ # make two changes to module
239
+ RIM::git_session(@ws_dir) do |s|
240
+ `echo ' appended' >> #{File.join(@ws_dir, "mod1/readme.txt")}`
241
+ s.execute("git commit . -m \"First change\"")
242
+ #shas.push(s.rev_sha1("HEAD"))
243
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file.txt")}`
244
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/new_file2.txt")}`
245
+ s.execute("git add .")
246
+ s.execute("git commit . -m \"Second change\"")
247
+ shas.push(s.rev_sha1("HEAD"))
248
+ end
249
+ cut = RIM::UploadHelper.new(@ws_dir, true, @logger, [mod1_info])
250
+ cut.upload
251
+ module_session(mod1_info) do |s|
252
+ s.execute("git checkout --detach master")
253
+ s.execute("git branch -D master")
254
+ end
255
+ # reset testbr now on previous commit and commit new change
256
+ RIM::git_session(@ws_dir) do |s|
257
+ s.execute("git checkout -B testbr HEAD~2")
258
+ `echo 'Test' > #{File.join(@ws_dir, "mod1/test_file.txt")}`
259
+ s.execute("git add .")
260
+ s.execute("git commit . -m \"Third change\"")
261
+ end
262
+ cut.upload
263
+ module_session(mod1_info) do |s|
264
+ s.execute("git checkout --detach master")
265
+ s.execute("git branch -D master")
266
+ end
267
+ # now merge the commits
268
+ RIM::git_session(@ws_dir) do |s|
269
+ s.execute("git merge #{shas[0]} --commit")
270
+ end
271
+ cut.upload
272
+ module_session(mod1_info) do |s|
273
+ s.execute("git checkout master")
274
+ assert File.exist?(File.join(@remote_git_dir, "mod1/readme.txt"))
275
+ assert File.exist?(File.join(@remote_git_dir, "mod1/new_file.txt"))
276
+ assert File.exist?(File.join(@remote_git_dir, "mod1/new_file2.txt"))
277
+ assert File.exist?(File.join(@remote_git_dir, "mod1/test_file.txt"))
278
+ assert s.execute("git show -s --format=%B HEAD").start_with?("Merge commit")
279
+ assert s.execute("git show -s --format=%B HEAD~1").start_with?("Third change")
280
+ end
281
+ end
282
+
283
+ private
284
+ def create_ws_git(branch = "master")
285
+ FileUtils.mkdir_p(@ws_remote_dir)
286
+ RIM::git_session(@ws_remote_dir) do |s|
287
+ s.execute("git init")
288
+ s.execute("git checkout -B #{branch}")
289
+ File.open(File.join(@ws_remote_dir, ".gitignore"), "w") do |f|
290
+ f.write(".rim")
291
+ end
292
+ File.open(File.join(@ws_remote_dir, "readme"), "w") do |f|
293
+ f.write("Content")
294
+ end
295
+ s.execute("git add .")
296
+ s.execute("git commit -m \"Initial commit\"")
297
+ s.execute("git checkout --detach #{branch}")
298
+ end
299
+ FileUtils.mkdir_p(@ws_dir)
300
+ RIM::git_session(@ws_dir) do |s|
301
+ s.execute("git clone #{@ws_remote_dir} #{@ws_dir}")
302
+ end
303
+ end
304
+
305
+ def create_module_git(name, branch = "master", remote_branch_format = nil)
306
+ git_dir = File.join(@remote_git_dir, name)
307
+ FileUtils.mkdir_p(git_dir)
308
+ RIM::git_session(git_dir) do |s|
309
+ s.execute("git init")
310
+ s.execute("git checkout -B #{branch}")
311
+ File.open(File.join(git_dir, "readme.txt"), "w") do |f|
312
+ f.write("Content.")
313
+ end
314
+ s.execute("git add .")
315
+ s.execute("git commit -m \"Initial commit\"")
316
+ s.execute("git checkout --detach #{branch}")
317
+ end
318
+ return RIM::ModuleInfo.new("file://" + git_dir, name, branch, nil, remote_branch_format)
319
+ end
320
+
321
+ def module_session(module_info)
322
+ RIM::git_session(module_info.remote_url.gsub(/^file:\/\//, "")) do |s|
323
+ yield s
324
+ end
325
+ end
326
+
327
+ def check_not_dirty(session)
328
+ status = RIM::StatusBuilder.new.rev_status(session, "HEAD")
329
+ status.modules.each do |m|
330
+ assert !m.dirty?
331
+ end
332
+ end
333
+
334
+ def has_ancestor?(session, rev, ancestor)
335
+ rev = session.execute("git rev-list #{rev}").include?(session.rev_sha1(ancestor))
336
+ end
337
+
338
+ end