|
87 | 87 | `git add . 2>&1 > #{File::NULL}`
|
88 | 88 | `git commit -m "Update Branch 2" 2>&1 > #{File::NULL}`
|
89 | 89 |
|
90 |
| - should include(*%w[added-1 update-me added-2].map { |file| File.expand_path(file) }) |
| 90 | + should == %w[added-1 added-2 update-me].map { |file| File.expand_path(file) } |
| 91 | + should_not include(*%w[delete-me].map { |file| File.expand_path(file) }) |
| 92 | + end |
| 93 | + end |
| 94 | + end |
| 95 | + |
| 96 | + context 'when pushing multiple branches at once' do |
| 97 | + let(:local_ref_1) { 'refs/heads/project-branch-1' } |
| 98 | + let(:local_sha1_1) { get_sha1(local_ref_1) } |
| 99 | + let(:local_ref_2) { 'refs/heads/project-branch-2' } |
| 100 | + let(:local_sha1_2) { get_sha1(local_ref_2) } |
| 101 | + let(:remote_ref) { 'refs/remotes/origin/master' } |
| 102 | + let(:remote_sha1) { get_sha1(remote_ref) } |
| 103 | + let(:input) do |
| 104 | + double('input', read: ref_ranges) |
| 105 | + end |
| 106 | + let(:ref_ranges) do |
| 107 | + [ |
| 108 | + "#{local_ref_1} #{local_sha1_1} #{remote_ref} #{remote_sha1}\n", |
| 109 | + "#{local_ref_2} #{local_sha1_2} #{remote_ref} #{remote_sha1}\n" |
| 110 | + ].join |
| 111 | + end |
| 112 | + |
| 113 | + it 'has modified files based on multiple tracking branches' do |
| 114 | + repo do |
| 115 | + `git remote add origin file://#{remote_repo}` |
| 116 | + `git fetch origin 2>&1 > #{File::NULL} && git reset --hard origin/master` |
| 117 | + |
| 118 | + `git checkout -b project-branch-1 2>&1 > #{File::NULL}` |
| 119 | + `git push -u origin project-branch-1 2>&1 > #{File::NULL}` |
| 120 | + |
| 121 | + touch 'added-1' |
| 122 | + echo 'add', 'added-1' |
| 123 | + echo 'append', 'update-me' |
| 124 | + FileUtils.rm 'delete-me' |
| 125 | + `git add . 2>&1 > #{File::NULL}` |
| 126 | + `git commit -m "Update Branch 1" 2>&1 > #{File::NULL}` |
| 127 | + |
| 128 | + `git checkout master 2>&1 > #{File::NULL}` |
| 129 | + `git checkout -b project-branch-2 2>&1 > #{File::NULL}` |
| 130 | + `git push -u origin project-branch-2 2>&1 > #{File::NULL}` |
| 131 | + |
| 132 | + echo 'append', 'update-me' |
| 133 | + touch 'added-2' |
| 134 | + echo 'add', 'added-2' |
| 135 | + `git add . 2>&1 > #{File::NULL}` |
| 136 | + `git commit -m "Update Branch 2" 2>&1 > #{File::NULL}` |
| 137 | + |
| 138 | + should == %w[added-1 update-me added-2].map { |file| File.expand_path(file) } |
91 | 139 | should_not include(*%w[delete-me].map { |file| File.expand_path(file) })
|
92 | 140 | end
|
93 | 141 | end
|
|
121 | 169 | `git add . 2>&1 > #{File::NULL}`
|
122 | 170 | `git commit -m "Update Branch 2" 2>&1 > #{File::NULL}`
|
123 | 171 |
|
124 |
| - should include(*%w[added-1 update-me added-2].map { |file| File.expand_path(file) }) |
| 172 | + should == %w[added-1 added-2 update-me].map { |file| File.expand_path(file) } |
125 | 173 | should_not include(*%w[delete-me].map { |file| File.expand_path(file) })
|
126 | 174 | end
|
127 | 175 | end
|
|
130 | 178 |
|
131 | 179 | describe '#modified_lines_in_file' do
|
132 | 180 | subject { context.modified_lines_in_file(file) }
|
133 |
| - let(:local_ref) { 'refs/heads/project-branch' } |
134 |
| - let(:local_sha1) { get_sha1(local_ref) } |
| 181 | + let(:local_ref_1) { 'refs/heads/project-branch-1' } |
| 182 | + let(:local_sha1_1) { get_sha1(local_ref_1) } |
| 183 | + let(:local_ref_2) { 'refs/heads/project-branch-2' } |
| 184 | + let(:local_sha1_2) { get_sha1(local_ref_2) } |
135 | 185 | let(:remote_ref) { 'refs/remotes/origin/master' }
|
136 | 186 | let(:remote_sha1) { get_sha1(remote_ref) }
|
137 | 187 | let(:input) do
|
138 |
| - double('input', read: "#{local_ref} #{local_sha1} #{remote_ref} #{remote_sha1}\n") |
| 188 | + double('input', read: ref_ranges) |
| 189 | + end |
| 190 | + let(:ref_ranges) do |
| 191 | + [ |
| 192 | + "#{local_ref_1} #{local_sha1_1} #{remote_ref} #{remote_sha1}\n", |
| 193 | + "#{local_ref_2} #{local_sha1_2} #{remote_ref} #{remote_sha1}\n" |
| 194 | + ].join |
139 | 195 | end
|
140 | 196 | let(:remote_repo) do
|
141 | 197 | repo do
|
|
154 | 210 | `git remote add origin file://#{remote_repo}`
|
155 | 211 | `git fetch origin 2>&1 > #{File::NULL} && git reset --hard origin/master`
|
156 | 212 |
|
157 |
| - `git checkout -b project-branch 2>&1 > #{File::NULL}` |
158 |
| - `git push -u origin project-branch 2>&1 > #{File::NULL}` |
| 213 | + `git checkout -b project-branch-1 2>&1 > #{File::NULL}` |
| 214 | + `git push -u origin project-branch-1 2>&1 > #{File::NULL}` |
159 | 215 |
|
160 | 216 | echo 'append-1', 'initial_file', append: true
|
161 | 217 |
|
162 | 218 | `git add . 2>&1 > #{File::NULL}`
|
163 |
| - `git commit -m "Update Branch 1" 2>&1 > #{File::NULL}` |
| 219 | + `git commit -m "Update Branch 1 Commit 1" 2>&1 > #{File::NULL}` |
164 | 220 |
|
165 | 221 | echo 'append-2', 'initial_file', append: true
|
166 | 222 |
|
167 | 223 | `git add . 2>&1 > #{File::NULL}`
|
168 |
| - `git commit -m "Update Branch 2" 2>&1 > #{File::NULL}` |
| 224 | + `git commit -m "Update Branch 1 Commit 2" 2>&1 > #{File::NULL}` |
169 | 225 |
|
170 |
| - should == [2, 3].to_set |
| 226 | + `git checkout -b project-branch-2 2>&1 > #{File::NULL}` |
| 227 | + `git push -u origin project-branch-2 2>&1 > #{File::NULL}` |
| 228 | + |
| 229 | + echo 'append-3', 'initial_file', append: true |
| 230 | + |
| 231 | + `git add . 2>&1 > #{File::NULL}` |
| 232 | + `git commit -m "Update Branch 2 Commit 1" 2>&1 > #{File::NULL}` |
| 233 | + |
| 234 | + should == [2, 3, 4].to_set |
171 | 235 | end
|
172 | 236 | end
|
173 | 237 | end
|
|
180 | 244 | `git remote add origin file://#{remote_repo}`
|
181 | 245 | `git fetch origin 2>&1 > #{File::NULL} && git reset --hard origin/master`
|
182 | 246 |
|
183 |
| - `git checkout -b project-branch 2>&1 > #{File::NULL}` |
184 |
| - `git push -u origin project-branch 2>&1 > #{File::NULL}` |
| 247 | + `git checkout -b project-branch-1 2>&1 > #{File::NULL}` |
| 248 | + `git push -u origin project-branch-1 2>&1 > #{File::NULL}` |
185 | 249 |
|
186 | 250 | touch 'new_file'
|
187 | 251 |
|
188 | 252 | echo 'append-1', 'new_file', append: true
|
189 | 253 |
|
190 | 254 | `git add . 2>&1 > #{File::NULL}`
|
191 |
| - `git commit -m "Update Branch 1" 2>&1 > #{File::NULL}` |
| 255 | + `git commit -m "Update Branch 1 Commit 1" 2>&1 > #{File::NULL}` |
192 | 256 |
|
193 | 257 | echo 'append-2', 'new_file', append: true
|
194 | 258 |
|
195 | 259 | `git add . 2>&1 > #{File::NULL}`
|
196 |
| - `git commit -m "Update Branch 2" 2>&1 > #{File::NULL}` |
| 260 | + `git commit -m "Update Branch 1 Commit 2" 2>&1 > #{File::NULL}` |
| 261 | + |
| 262 | + `git checkout -b project-branch-2 2>&1 > #{File::NULL}` |
| 263 | + `git push -u origin project-branch-2 2>&1 > #{File::NULL}` |
197 | 264 |
|
198 |
| - should == [1, 2].to_set |
| 265 | + echo 'append-3', 'new_file', append: true |
| 266 | + |
| 267 | + `git add . 2>&1 > #{File::NULL}` |
| 268 | + `git commit -m "Update Branch 2 Commit 1" 2>&1 > #{File::NULL}` |
| 269 | + |
| 270 | + should == [1, 2, 3].to_set |
199 | 271 | end
|
200 | 272 | end
|
201 | 273 | end
|
202 | 274 |
|
203 | 275 | context 'when deleting a file' do
|
204 | 276 | let(:file) { File.expand_path('initial_file') }
|
| 277 | + let(:ref_ranges) do |
| 278 | + "#{local_ref_1} #{local_sha1_1} #{remote_ref} #{remote_sha1}\n" |
| 279 | + end |
205 | 280 |
|
206 | 281 | it 'has modified lines in file' do
|
207 | 282 | repo do
|
208 | 283 | `git remote add origin file://#{remote_repo}`
|
209 | 284 | `git fetch origin 2>&1 > #{File::NULL} && git reset --hard origin/master`
|
210 | 285 |
|
211 |
| - `git checkout -b project-branch 2>&1 > #{File::NULL}` |
212 |
| - `git push -u origin project-branch 2>&1 > #{File::NULL}` |
| 286 | + `git checkout -b project-branch-1 2>&1 > #{File::NULL}` |
| 287 | + `git push -u origin project-branch-1 2>&1 > #{File::NULL}` |
213 | 288 |
|
214 | 289 | FileUtils.rm 'initial_file'
|
215 | 290 |
|
|
0 commit comments