OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Unit tests for git_common.py""" | 6 """Unit tests for git_common.py""" |
7 | 7 |
8 import binascii | 8 import binascii |
9 import collections | 9 import collections |
10 import os | 10 import os |
11 import signal | 11 import signal |
12 import sys | 12 import sys |
13 import tempfile | 13 import tempfile |
14 import time | 14 import time |
15 import unittest | 15 import unittest |
16 | 16 |
17 DEPOT_TOOLS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 17 DEPOT_TOOLS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
18 sys.path.insert(0, DEPOT_TOOLS_ROOT) | 18 sys.path.insert(0, DEPOT_TOOLS_ROOT) |
19 | 19 |
20 from testing_support import coverage_utils | 20 from testing_support import coverage_utils |
21 from testing_support import git_test_utils | 21 from testing_support import git_test_utils |
22 | 22 |
23 | 23 |
24 class GitCommonTestBase(unittest.TestCase): | 24 class GitCommonTestBase(unittest.TestCase): |
25 @classmethod | 25 @classmethod |
26 def setUpClass(cls): | 26 def setUpClass(cls): |
27 super(GitCommonTestBase, cls).setUpClass() | 27 super(GitCommonTestBase, cls).setUpClass() |
28 import git_common | 28 import git_common |
29 cls.gc = git_common | 29 cls.gc = git_common |
| 30 cls.gc.TEST_MODE = True |
30 | 31 |
31 | 32 |
32 class Support(GitCommonTestBase): | 33 class Support(GitCommonTestBase): |
33 def _testMemoizeOneBody(self, threadsafe): | 34 def _testMemoizeOneBody(self, threadsafe): |
34 calls = collections.defaultdict(int) | 35 calls = collections.defaultdict(int) |
35 def double_if_even(val): | 36 def double_if_even(val): |
36 calls[val] += 1 | 37 calls[val] += 1 |
37 return val * 2 if val % 2 == 0 else None | 38 return val * 2 if val % 2 == 0 else None |
38 # Use this explicitly as a wrapper fn instead of a decorator. Otherwise | 39 # Use this explicitly as a wrapper fn instead of a decorator. Otherwise |
39 # pylint crashes (!!) | 40 # pylint crashes (!!) |
(...skipping 16 matching lines...) Expand all Loading... |
56 self.assertEqual(None, double_if_even(1)) | 57 self.assertEqual(None, double_if_even(1)) |
57 self.assertEqual(20, double_if_even(10)) | 58 self.assertEqual(20, double_if_even(10)) |
58 self.assertDictEqual({1: 4, 2: 2, 10: 1}, calls) | 59 self.assertDictEqual({1: 4, 2: 2, 10: 1}, calls) |
59 | 60 |
60 def testMemoizeOne(self): | 61 def testMemoizeOne(self): |
61 self._testMemoizeOneBody(threadsafe=False) | 62 self._testMemoizeOneBody(threadsafe=False) |
62 | 63 |
63 def testMemoizeOneThreadsafe(self): | 64 def testMemoizeOneThreadsafe(self): |
64 self._testMemoizeOneBody(threadsafe=True) | 65 self._testMemoizeOneBody(threadsafe=True) |
65 | 66 |
| 67 def testOnce(self): |
| 68 testlist = [] |
| 69 |
| 70 # This works around a bug in pylint |
| 71 once = self.gc.once |
| 72 |
| 73 @once |
| 74 def add_to_list(): |
| 75 testlist.append('dog') |
| 76 |
| 77 add_to_list() |
| 78 add_to_list() |
| 79 add_to_list() |
| 80 add_to_list() |
| 81 |
| 82 self.assertEquals(testlist, ['dog']) |
| 83 |
66 | 84 |
67 def slow_square(i): | 85 def slow_square(i): |
68 """Helper for ScopedPoolTest. | 86 """Helper for ScopedPoolTest. |
69 | 87 |
70 Must be global because non top-level functions aren't pickleable. | 88 Must be global because non top-level functions aren't pickleable. |
71 """ | 89 """ |
72 return i ** 2 | 90 return i ** 2 |
73 | 91 |
74 | 92 |
75 class ScopedPoolTest(GitCommonTestBase): | 93 class ScopedPoolTest(GitCommonTestBase): |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 """This test is probably racy, but I don't have a better alternative.""" | 145 """This test is probably racy, but I don't have a better alternative.""" |
128 fmt = '%(count)d/10' | 146 fmt = '%(count)d/10' |
129 stream = self.FakeStream() | 147 stream = self.FakeStream() |
130 | 148 |
131 pp = self.gc.ProgressPrinter(fmt, enabled=True, fout=stream, period=0.01) | 149 pp = self.gc.ProgressPrinter(fmt, enabled=True, fout=stream, period=0.01) |
132 with pp as inc: | 150 with pp as inc: |
133 for _ in xrange(10): | 151 for _ in xrange(10): |
134 time.sleep(0.02) | 152 time.sleep(0.02) |
135 inc() | 153 inc() |
136 | 154 |
137 filtered = set(x.strip() for x in stream.data) | 155 filtered = {x.strip() for x in stream.data} |
138 rslt = set(fmt % {'count': i} for i in xrange(11)) | 156 rslt = {fmt % {'count': i} for i in xrange(11)} |
139 self.assertSetEqual(filtered, rslt) | 157 self.assertSetEqual(filtered, rslt) |
140 self.assertGreaterEqual(stream.count, 10) | 158 self.assertGreaterEqual(stream.count, 10) |
141 | 159 |
142 | 160 |
143 class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase, | 161 class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase, |
144 GitCommonTestBase): | 162 GitCommonTestBase): |
145 REPO = """ | 163 REPO_SCHEMA = """ |
146 A B C D | 164 A B C D |
147 B E D | 165 B E D |
148 """ | 166 """ |
149 | 167 |
150 COMMIT_A = { | 168 COMMIT_A = { |
151 'some/files/file1': {'data': 'file1'}, | 169 'some/files/file1': {'data': 'file1'}, |
152 'some/files/file2': {'data': 'file2'}, | 170 'some/files/file2': {'data': 'file2'}, |
153 'some/files/file3': {'data': 'file3'}, | 171 'some/files/file3': {'data': 'file3'}, |
154 'some/other/file': {'data': 'otherfile'}, | 172 'some/other/file': {'data': 'otherfile'}, |
155 } | 173 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 ], ret) | 205 ], ret) |
188 self.assertEquals( | 206 self.assertEquals( |
189 self.repo.run(self.gc.hash_one, 'branch_D'), | 207 self.repo.run(self.gc.hash_one, 'branch_D'), |
190 self.repo['D'] | 208 self.repo['D'] |
191 ) | 209 ) |
192 | 210 |
193 def testStream(self): | 211 def testStream(self): |
194 items = set(self.repo.commit_map.itervalues()) | 212 items = set(self.repo.commit_map.itervalues()) |
195 | 213 |
196 def testfn(): | 214 def testfn(): |
197 for line in self.gc.stream('log', '--format=%H').xreadlines(): | 215 for line in self.gc.run_stream('log', '--format=%H').xreadlines(): |
198 line = line.strip() | 216 line = line.strip() |
199 self.assertIn(line, items) | 217 self.assertIn(line, items) |
200 items.remove(line) | 218 items.remove(line) |
201 | 219 |
202 self.repo.run(testfn) | 220 self.repo.run(testfn) |
203 | 221 |
204 def testCurrentBranch(self): | 222 def testCurrentBranch(self): |
| 223 def cur_branch_out_of_git(): |
| 224 os.chdir('..') |
| 225 return self.gc.current_branch() |
| 226 self.assertIsNone(self.repo.run(cur_branch_out_of_git)) |
| 227 |
205 self.repo.git('checkout', 'branch_D') | 228 self.repo.git('checkout', 'branch_D') |
206 self.assertEqual(self.repo.run(self.gc.current_branch), 'branch_D') | 229 self.assertEqual(self.repo.run(self.gc.current_branch), 'branch_D') |
207 | 230 |
208 def testBranches(self): | 231 def testBranches(self): |
209 self.assertEqual(self.repo.run(set, self.gc.branches()), | 232 self.assertEqual(self.repo.run(set, self.gc.branches()), |
210 set(('branch_D', 'root_A'))) | 233 {'master', 'branch_D', 'root_A'}) |
211 | 234 |
212 def testTags(self): | 235 def testDormant(self): |
213 self.assertEqual(set(self.repo.run(self.gc.tags)), | 236 self.assertFalse(self.repo.run(self.gc.is_dormant, 'master')) |
214 {'tag_'+l for l in 'ABCDE'}) | 237 self.repo.git('config', 'branch.master.dormant', 'true') |
| 238 self.assertTrue(self.repo.run(self.gc.is_dormant, 'master')) |
215 | 239 |
216 def testParseCommitrefs(self): | 240 def testParseCommitrefs(self): |
217 ret = self.repo.run( | 241 ret = self.repo.run( |
218 self.gc.parse_commitrefs, *[ | 242 self.gc.parse_commitrefs, *[ |
219 'master', | 243 'master', |
220 'master~3', | 244 'master~3', |
221 self.repo['E']+'~', | 245 self.repo['E']+'~', |
222 self.repo['D']+'^2', | 246 self.repo['D']+'^2', |
223 'tag_C^{}', | 247 'tag_C^{}', |
224 ] | 248 ] |
225 ) | 249 ) |
226 self.assertEqual(ret, map(binascii.unhexlify, [ | 250 self.assertEqual(ret, map(binascii.unhexlify, [ |
227 self.repo['D'], | 251 self.repo['D'], |
228 self.repo['A'], | 252 self.repo['A'], |
229 self.repo['B'], | 253 self.repo['B'], |
230 self.repo['E'], | 254 self.repo['E'], |
231 self.repo['C'], | 255 self.repo['C'], |
232 ])) | 256 ])) |
233 | 257 |
234 with self.assertRaisesRegexp(Exception, r"one of \('master', 'bananas'\)"): | 258 with self.assertRaisesRegexp(Exception, r"one of \('master', 'bananas'\)"): |
235 self.repo.run(self.gc.parse_commitrefs, 'master', 'bananas') | 259 self.repo.run(self.gc.parse_commitrefs, 'master', 'bananas') |
236 | 260 |
| 261 def testTags(self): |
| 262 self.assertEqual(set(self.repo.run(self.gc.tags)), |
| 263 {'tag_'+l for l in 'ABCDE'}) |
| 264 |
237 def testTree(self): | 265 def testTree(self): |
238 tree = self.repo.run(self.gc.tree, 'master:some/files') | 266 tree = self.repo.run(self.gc.tree, 'master:some/files') |
239 file1 = self.COMMIT_A['some/files/file1']['data'] | 267 file1 = self.COMMIT_A['some/files/file1']['data'] |
240 file2 = self.COMMIT_D['some/files/file2']['data'] | 268 file2 = self.COMMIT_D['some/files/file2']['data'] |
241 file3 = self.COMMIT_A['some/files/file3']['data'] | 269 file3 = self.COMMIT_A['some/files/file3']['data'] |
242 self.assertEquals( | 270 self.assertEquals( |
243 tree['file1'], | 271 tree['file1'], |
244 ('100644', 'blob', git_test_utils.git_hash_data(file1))) | 272 ('100644', 'blob', git_test_utils.git_hash_data(file1))) |
245 self.assertEquals( | 273 self.assertEquals( |
246 tree['file2'], | 274 tree['file2'], |
(...skipping 25 matching lines...) Expand all Loading... |
272 self.assertEquals( | 300 self.assertEquals( |
273 tree['files/file3'], | 301 tree['files/file3'], |
274 ('100644', 'blob', git_test_utils.git_hash_data(file3))) | 302 ('100644', 'blob', git_test_utils.git_hash_data(file3))) |
275 self.assertEquals( | 303 self.assertEquals( |
276 tree['other/file'], | 304 tree['other/file'], |
277 ('100644', 'blob', git_test_utils.git_hash_data(other))) | 305 ('100644', 'blob', git_test_utils.git_hash_data(other))) |
278 | 306 |
279 | 307 |
280 class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase, | 308 class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase, |
281 GitCommonTestBase): | 309 GitCommonTestBase): |
282 REPO = '' | 310 REPO_SCHEMA = '' |
283 | 311 |
284 def _intern_data(self, data): | 312 def _intern_data(self, data): |
285 with tempfile.TemporaryFile() as f: | 313 with tempfile.TemporaryFile() as f: |
286 f.write(data) | 314 f.write(data) |
287 f.seek(0) | 315 f.seek(0) |
288 return self.repo.run(self.gc.intern_f, f) | 316 return self.repo.run(self.gc.intern_f, f) |
289 | 317 |
290 def testInternF(self): | 318 def testInternF(self): |
291 data = 'CoolBobcatsBro' | 319 data = 'CoolBobcatsBro' |
292 data_hash = self._intern_data(data) | 320 data_hash = self._intern_data(data) |
(...skipping 11 matching lines...) Expand all Loading... |
304 def testConfig(self): | 332 def testConfig(self): |
305 self.repo.git('config', '--add', 'happy.derpies', 'food') | 333 self.repo.git('config', '--add', 'happy.derpies', 'food') |
306 self.assertEquals(self.repo.run(self.gc.config_list, 'happy.derpies'), | 334 self.assertEquals(self.repo.run(self.gc.config_list, 'happy.derpies'), |
307 ['food']) | 335 ['food']) |
308 self.assertEquals(self.repo.run(self.gc.config_list, 'sad.derpies'), []) | 336 self.assertEquals(self.repo.run(self.gc.config_list, 'sad.derpies'), []) |
309 | 337 |
310 self.repo.git('config', '--add', 'happy.derpies', 'cat') | 338 self.repo.git('config', '--add', 'happy.derpies', 'cat') |
311 self.assertEquals(self.repo.run(self.gc.config_list, 'happy.derpies'), | 339 self.assertEquals(self.repo.run(self.gc.config_list, 'happy.derpies'), |
312 ['food', 'cat']) | 340 ['food', 'cat']) |
313 | 341 |
| 342 self.assertEquals('cat', self.repo.run(self.gc.config, 'dude.bob', 'cat')) |
| 343 |
| 344 self.repo.run(self.gc.set_config, 'dude.bob', 'dog') |
| 345 |
| 346 self.assertEquals('dog', self.repo.run(self.gc.config, 'dude.bob', 'cat')) |
| 347 |
| 348 self.repo.run(self.gc.del_config, 'dude.bob') |
| 349 |
| 350 # This should work without raising an exception |
| 351 self.repo.run(self.gc.del_config, 'dude.bob') |
| 352 |
| 353 self.assertEquals('cat', self.repo.run(self.gc.config, 'dude.bob', 'cat')) |
| 354 |
| 355 self.assertEquals('origin/master', self.repo.run(self.gc.root)) |
| 356 |
| 357 self.repo.git('config', 'depot-tools.upstream', 'catfood') |
| 358 |
| 359 self.assertEquals('catfood', self.repo.run(self.gc.root)) |
| 360 |
314 def testUpstream(self): | 361 def testUpstream(self): |
315 self.repo.git('commit', '--allow-empty', '-am', 'foooooo') | 362 self.repo.git('commit', '--allow-empty', '-am', 'foooooo') |
316 self.assertEquals(self.repo.run(self.gc.upstream, 'bobly'), None) | 363 self.assertEquals(self.repo.run(self.gc.upstream, 'bobly'), None) |
317 self.assertEquals(self.repo.run(self.gc.upstream, 'master'), None) | 364 self.assertEquals(self.repo.run(self.gc.upstream, 'master'), None) |
318 self.repo.git('checkout', '-tb', 'happybranch', 'master') | 365 self.repo.git('checkout', '-tb', 'happybranch', 'master') |
319 self.assertEquals(self.repo.run(self.gc.upstream, 'happybranch'), | 366 self.assertEquals(self.repo.run(self.gc.upstream, 'happybranch'), |
320 'master') | 367 'master') |
321 | 368 |
322 | 369 |
| 370 class GitMutableStructuredTest(git_test_utils.GitRepoReadWriteTestBase, |
| 371 GitCommonTestBase): |
| 372 REPO_SCHEMA = """ |
| 373 A B C D E F G |
| 374 B H I J K |
| 375 J L |
| 376 |
| 377 X Y Z |
| 378 """ |
| 379 |
| 380 COMMIT_B = {'file': {'data': 'B'}} |
| 381 COMMIT_H = {'file': {'data': 'H'}} |
| 382 COMMIT_I = {'file': {'data': 'I'}} |
| 383 COMMIT_J = {'file': {'data': 'J'}} |
| 384 COMMIT_K = {'file': {'data': 'K'}} |
| 385 COMMIT_L = {'file': {'data': 'L'}} |
| 386 |
| 387 def setUp(self): |
| 388 super(GitMutableStructuredTest, self).setUp() |
| 389 self.repo.git('branch', '--set-upstream-to', 'root_X', 'branch_Z') |
| 390 self.repo.git('branch', '--set-upstream-to', 'branch_G', 'branch_K') |
| 391 self.repo.git('branch', '--set-upstream-to', 'branch_K', 'branch_L') |
| 392 self.repo.git('branch', '--set-upstream-to', 'root_A', 'branch_G') |
| 393 self.repo.git('branch', '--set-upstream-to', 'root_X', 'root_A') |
| 394 |
| 395 def testMergeBase(self): |
| 396 self.repo.git('checkout', 'branch_K') |
| 397 |
| 398 self.assertEqual( |
| 399 self.repo['B'], |
| 400 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') |
| 401 ) |
| 402 |
| 403 self.assertEqual( |
| 404 self.repo['J'], |
| 405 self.repo.run(self.gc.get_or_create_merge_base, 'branch_L', 'branch_K') |
| 406 ) |
| 407 |
| 408 self.assertEqual( |
| 409 self.repo['B'], self.repo.run(self.gc.config, 'branch.branch_K.base') |
| 410 ) |
| 411 |
| 412 # deadbeef is a bad hash, so this will result in repo['B'] |
| 413 self.repo.run(self.gc.manual_merge_base, 'branch_K', 'deadbeef') |
| 414 |
| 415 self.assertEqual( |
| 416 self.repo['B'], |
| 417 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') |
| 418 ) |
| 419 |
| 420 # but if we pick a real ancestor, then it'll work |
| 421 self.repo.run(self.gc.manual_merge_base, 'branch_K', self.repo['I']) |
| 422 |
| 423 self.assertEqual( |
| 424 self.repo['I'], |
| 425 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') |
| 426 ) |
| 427 |
| 428 self.assertEqual({'branch_K': self.repo['I'], 'branch_L': self.repo['J']}, |
| 429 self.repo.run(self.gc.branch_config_map, 'base')) |
| 430 |
| 431 self.repo.run(self.gc.remove_merge_base, 'branch_K') |
| 432 self.repo.run(self.gc.remove_merge_base, 'branch_L') |
| 433 |
| 434 self.assertEqual(None, |
| 435 self.repo.run(self.gc.config, 'branch.branch_K.base')) |
| 436 |
| 437 self.assertEqual({}, self.repo.run(self.gc.branch_config_map, 'base')) |
| 438 |
| 439 def testGetBranchTree(self): |
| 440 skipped, tree = self.repo.run(self.gc.get_branch_tree) |
| 441 self.assertEqual(skipped, {'master', 'root_X'}) |
| 442 self.assertEqual(tree, { |
| 443 'branch_G': 'root_A', |
| 444 'root_A': 'root_X', |
| 445 'branch_K': 'branch_G', |
| 446 'branch_L': 'branch_K', |
| 447 'branch_Z': 'root_X' |
| 448 }) |
| 449 |
| 450 topdown = list(self.gc.topo_iter(tree)) |
| 451 bottomup = list(self.gc.topo_iter(tree, top_down=False)) |
| 452 |
| 453 self.assertEqual(topdown, [ |
| 454 ('branch_Z', 'root_X'), |
| 455 ('root_A', 'root_X'), |
| 456 ('branch_G', 'root_A'), |
| 457 ('branch_K', 'branch_G'), |
| 458 ('branch_L', 'branch_K'), |
| 459 ]) |
| 460 |
| 461 self.assertEqual(bottomup, [ |
| 462 ('branch_L', 'branch_K'), |
| 463 ('branch_Z', 'root_X'), |
| 464 ('branch_K', 'branch_G'), |
| 465 ('branch_G', 'root_A'), |
| 466 ('root_A', 'root_X'), |
| 467 ]) |
| 468 |
| 469 def testSquashBranch(self): |
| 470 self.repo.git('checkout', 'branch_K') |
| 471 |
| 472 self.repo.run(self.gc.squash_current_branch, 'cool message') |
| 473 |
| 474 lines = ['cool message', ''] |
| 475 for l in 'HIJK': |
| 476 lines.extend((self.repo[l], l, '')) |
| 477 lines.pop() |
| 478 msg = '\n'.join(lines) |
| 479 |
| 480 self.assertEquals(self.repo.run(self.gc.run, 'log', '-n1', '--format=%B'), |
| 481 msg) |
| 482 |
| 483 self.assertEquals( |
| 484 self.repo.git('cat-file', 'blob', 'branch_K:file').stdout, |
| 485 'K' |
| 486 ) |
| 487 |
| 488 def testRebase(self): |
| 489 self.assertSchema(""" |
| 490 A B C D E F G |
| 491 B H I J K |
| 492 J L |
| 493 |
| 494 X Y Z |
| 495 """) |
| 496 |
| 497 rslt = self.repo.run( |
| 498 self.gc.rebase, 'branch_G', 'branch_K~4', 'branch_K') |
| 499 self.assertTrue(rslt.success) |
| 500 |
| 501 self.assertSchema(""" |
| 502 A B C D E F G H I J K |
| 503 B H I J L |
| 504 |
| 505 X Y Z |
| 506 """) |
| 507 |
| 508 rslt = self.repo.run( |
| 509 self.gc.rebase, 'branch_K', 'branch_L~1', 'branch_L', abort=True) |
| 510 self.assertFalse(rslt.success) |
| 511 |
| 512 self.assertFalse(self.repo.run(self.gc.in_rebase)) |
| 513 |
| 514 rslt = self.repo.run( |
| 515 self.gc.rebase, 'branch_K', 'branch_L~1', 'branch_L', abort=False) |
| 516 self.assertFalse(rslt.success) |
| 517 |
| 518 self.assertTrue(self.repo.run(self.gc.in_rebase)) |
| 519 |
| 520 self.assertEqual(self.repo.git('status', '--porcelain').stdout, 'UU file\n') |
| 521 self.repo.git('checkout', '--theirs', 'file') |
| 522 self.repo.git('add', 'file') |
| 523 self.repo.git('rebase', '--continue') |
| 524 |
| 525 self.assertSchema(""" |
| 526 A B C D E F G H I J K L |
| 527 |
| 528 X Y Z |
| 529 """) |
| 530 |
| 531 |
| 532 class GitFreezeThaw(git_test_utils.GitRepoReadWriteTestBase): |
| 533 @classmethod |
| 534 def setUpClass(cls): |
| 535 super(GitFreezeThaw, cls).setUpClass() |
| 536 import git_common |
| 537 cls.gc = git_common |
| 538 cls.gc.TEST_MODE = True |
| 539 |
| 540 REPO_SCHEMA = """ |
| 541 A B C D |
| 542 B E D |
| 543 """ |
| 544 |
| 545 COMMIT_A = { |
| 546 'some/files/file1': {'data': 'file1'}, |
| 547 'some/files/file2': {'data': 'file2'}, |
| 548 'some/files/file3': {'data': 'file3'}, |
| 549 'some/other/file': {'data': 'otherfile'}, |
| 550 } |
| 551 |
| 552 COMMIT_C = { |
| 553 'some/files/file2': { |
| 554 'mode': 0755, |
| 555 'data': 'file2 - vanilla'}, |
| 556 } |
| 557 |
| 558 COMMIT_E = { |
| 559 'some/files/file2': {'data': 'file2 - merged'}, |
| 560 } |
| 561 |
| 562 COMMIT_D = { |
| 563 'some/files/file2': {'data': 'file2 - vanilla\nfile2 - merged'}, |
| 564 } |
| 565 |
| 566 def testNothing(self): |
| 567 self.assertIsNotNone(self.repo.run(self.gc.thaw)) # 'Nothing to thaw' |
| 568 self.assertIsNotNone(self.repo.run(self.gc.freeze)) # 'Nothing to freeze' |
| 569 |
| 570 def testAll(self): |
| 571 def inner(): |
| 572 with open('some/files/file2', 'a') as f2: |
| 573 print >> f2, 'cool appended line' |
| 574 os.mkdir('some/other_files') |
| 575 with open('some/other_files/subdir_file', 'w') as f3: |
| 576 print >> f3, 'new file!' |
| 577 with open('some/files/file5', 'w') as f5: |
| 578 print >> f5, 'New file!1!one!' |
| 579 |
| 580 STATUS_1 = '\n'.join(( |
| 581 ' M some/files/file2', |
| 582 'A some/files/file5', |
| 583 '?? some/other_files/' |
| 584 )) + '\n' |
| 585 |
| 586 self.repo.git('add', 'some/files/file5') |
| 587 |
| 588 # Freeze group 1 |
| 589 self.assertEquals(self.repo.git('status', '--porcelain').stdout, STATUS_1) |
| 590 self.assertIsNone(self.gc.freeze()) |
| 591 self.assertEquals(self.repo.git('status', '--porcelain').stdout, '') |
| 592 |
| 593 # Freeze group 2 |
| 594 with open('some/files/file2', 'a') as f2: |
| 595 print >> f2, 'new! appended line!' |
| 596 self.assertEquals(self.repo.git('status', '--porcelain').stdout, |
| 597 ' M some/files/file2\n') |
| 598 self.assertIsNone(self.gc.freeze()) |
| 599 self.assertEquals(self.repo.git('status', '--porcelain').stdout, '') |
| 600 |
| 601 # Thaw it out! |
| 602 self.assertIsNone(self.gc.thaw()) |
| 603 self.assertIsNotNone(self.gc.thaw()) # One thaw should thaw everything |
| 604 |
| 605 self.assertEquals(self.repo.git('status', '--porcelain').stdout, STATUS_1) |
| 606 |
| 607 self.repo.run(inner) |
| 608 |
| 609 |
323 if __name__ == '__main__': | 610 if __name__ == '__main__': |
324 sys.exit(coverage_utils.covered_main( | 611 sys.exit(coverage_utils.covered_main( |
325 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py') | 612 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py') |
326 )) | 613 )) |
OLD | NEW |