~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import os
18
18
import stat
35
35
                              NonDirectoryParent)
36
36
from bzrlib.diff import show_diff_trees
37
37
from bzrlib.errors import (DuplicateKey, MalformedTransform, NoSuchFile,
38
 
                           ReusingTransform, CantMoveRoot, 
 
38
                           ReusingTransform, CantMoveRoot,
39
39
                           PathsNotVersionedError, ExistingLimbo,
40
40
                           ExistingPendingDeletion, ImmortalLimbo,
41
41
                           ImmortalPendingDeletion, LockError)
48
48
    TestCaseInTempDir,
49
49
    TestSkipped,
50
50
    )
51
 
from bzrlib.transform import (TreeTransform, ROOT_PARENT, FinalPaths, 
52
 
                              resolve_conflicts, cook_conflicts, 
 
51
from bzrlib.transform import (TreeTransform, ROOT_PARENT, FinalPaths,
 
52
                              resolve_conflicts, cook_conflicts,
53
53
                              build_tree, get_backup_name,
54
54
                              _FileMover, resolve_checkout,
55
55
                              TransformPreview, create_from_tree)
129
129
        self.assertIs(self.wt.is_executable('my_pretties2'), False)
130
130
        self.assertEqual('directory', file_kind(self.wt.abspath('oz')))
131
131
        self.assertEqual(len(modified_paths), 3)
132
 
        tree_mod_paths = [self.wt.id2abspath(f) for f in 
 
132
        tree_mod_paths = [self.wt.id2abspath(f) for f in
133
133
                          ('ozzie', 'my_pretties', 'my_pretties2')]
134
134
        self.assertSubset(tree_mod_paths, modified_paths)
135
135
        # is it safe to finalize repeatedly?
155
155
        transform, root = self.get_transform()
156
156
        self.wt.lock_tree_write()
157
157
        self.addCleanup(self.wt.unlock)
158
 
        trans_id = transform.new_file('name', root, 'contents', 
 
158
        trans_id = transform.new_file('name', root, 'contents',
159
159
                                      'my_pretties', True)
160
160
        oz = transform.new_directory('oz', root, 'oz-id')
161
161
        dorothy = transform.new_directory('dorothy', oz, 'dorothy-id')
162
 
        toto = transform.new_file('toto', dorothy, 'toto-contents', 
 
162
        toto = transform.new_file('toto', dorothy, 'toto-contents',
163
163
                                  'toto-id', False)
164
164
 
165
165
        self.assertEqual(len(transform.find_conflicts()), 0)
189
189
 
190
190
    def test_conflicts(self):
191
191
        transform, root = self.get_transform()
192
 
        trans_id = transform.new_file('name', root, 'contents', 
 
192
        trans_id = transform.new_file('name', root, 'contents',
193
193
                                      'my_pretties')
194
194
        self.assertEqual(len(transform.find_conflicts()), 0)
195
195
        trans_id2 = transform.new_file('name', root, 'Crontents', 'toto')
196
 
        self.assertEqual(transform.find_conflicts(), 
 
196
        self.assertEqual(transform.find_conflicts(),
197
197
                         [('duplicate', trans_id, trans_id2, 'name')])
198
198
        self.assertRaises(MalformedTransform, transform.apply)
199
199
        transform.adjust_path('name', trans_id, trans_id2)
200
 
        self.assertEqual(transform.find_conflicts(), 
 
200
        self.assertEqual(transform.find_conflicts(),
201
201
                         [('non-directory parent', trans_id)])
202
202
        tinman_id = transform.trans_id_tree_path('tinman')
203
203
        transform.adjust_path('name', tinman_id, trans_id2)
204
 
        self.assertEqual(transform.find_conflicts(), 
205
 
                         [('unversioned parent', tinman_id), 
 
204
        self.assertEqual(transform.find_conflicts(),
 
205
                         [('unversioned parent', tinman_id),
206
206
                          ('missing parent', tinman_id)])
207
207
        lion_id = transform.create_path('lion', root)
208
 
        self.assertEqual(transform.find_conflicts(), 
209
 
                         [('unversioned parent', tinman_id), 
 
208
        self.assertEqual(transform.find_conflicts(),
 
209
                         [('unversioned parent', tinman_id),
210
210
                          ('missing parent', tinman_id)])
211
211
        transform.adjust_path('name', lion_id, trans_id2)
212
 
        self.assertEqual(transform.find_conflicts(), 
 
212
        self.assertEqual(transform.find_conflicts(),
213
213
                         [('unversioned parent', lion_id),
214
214
                          ('missing parent', lion_id)])
215
215
        transform.version_file("Courage", lion_id)
216
 
        self.assertEqual(transform.find_conflicts(), 
217
 
                         [('missing parent', lion_id), 
 
216
        self.assertEqual(transform.find_conflicts(),
 
217
                         [('missing parent', lion_id),
218
218
                          ('versioning no contents', lion_id)])
219
219
        transform.adjust_path('name2', root, trans_id2)
220
 
        self.assertEqual(transform.find_conflicts(), 
 
220
        self.assertEqual(transform.find_conflicts(),
221
221
                         [('versioning no contents', lion_id)])
222
222
        transform.create_file('Contents, okay?', lion_id)
223
223
        transform.adjust_path('name2', trans_id2, trans_id2)
224
 
        self.assertEqual(transform.find_conflicts(), 
225
 
                         [('parent loop', trans_id2), 
 
224
        self.assertEqual(transform.find_conflicts(),
 
225
                         [('parent loop', trans_id2),
226
226
                          ('non-directory parent', trans_id2)])
227
227
        transform.adjust_path('name2', root, trans_id2)
228
228
        oz_id = transform.new_directory('oz', root)
229
229
        transform.set_executability(True, oz_id)
230
 
        self.assertEqual(transform.find_conflicts(), 
 
230
        self.assertEqual(transform.find_conflicts(),
231
231
                         [('unversioned executability', oz_id)])
232
232
        transform.version_file('oz-id', oz_id)
233
 
        self.assertEqual(transform.find_conflicts(), 
 
233
        self.assertEqual(transform.find_conflicts(),
234
234
                         [('non-file executability', oz_id)])
235
235
        transform.set_executability(None, oz_id)
236
236
        tip_id = transform.new_file('tip', oz_id, 'ozma', 'tip-id')
245
245
        self.assert_('oz/tip' in transform2._tree_path_ids)
246
246
        self.assertEqual(fp.get_path(newtip), pathjoin('oz', 'tip'))
247
247
        self.assertEqual(len(result), 2)
248
 
        self.assertEqual((result[0][0], result[0][1]), 
 
248
        self.assertEqual((result[0][0], result[0][1]),
249
249
                         ('duplicate', newtip))
250
 
        self.assertEqual((result[1][0], result[1][2]), 
 
250
        self.assertEqual((result[1][0], result[1][2]),
251
251
                         ('duplicate id', newtip))
252
252
        transform2.finalize()
253
253
        transform3 = TreeTransform(self.wt)
254
254
        self.addCleanup(transform3.finalize)
255
255
        oz_id = transform3.trans_id_tree_file_id('oz-id')
256
256
        transform3.delete_contents(oz_id)
257
 
        self.assertEqual(transform3.find_conflicts(), 
 
257
        self.assertEqual(transform3.find_conflicts(),
258
258
                         [('missing parent', oz_id)])
259
259
        root_id = transform3.root
260
260
        tip_id = transform3.trans_id_tree_file_id('tip-id')
387
387
        self.addCleanup(unversion.finalize)
388
388
        parent = unversion.trans_id_tree_path('parent')
389
389
        unversion.unversion_file(parent)
390
 
        self.assertEqual(unversion.find_conflicts(), 
 
390
        self.assertEqual(unversion.find_conflicts(),
391
391
                         [('unversioned parent', parent_id)])
392
392
        file_id = unversion.trans_id_tree_file_id('child-id')
393
393
        unversion.unversion_file(file_id)
413
413
        mangle_tree.adjust_path('name2', root, name1)
414
414
        mangle_tree.adjust_path('name1', root, name2)
415
415
 
416
 
        #tests for deleting parent directories 
 
416
        #tests for deleting parent directories
417
417
        ddir = mangle_tree.trans_id_tree_file_id('ddir')
418
418
        mangle_tree.delete_contents(ddir)
419
419
        dfile = mangle_tree.trans_id_tree_file_id('dfile')
448
448
        create_tree,root = self.get_transform()
449
449
        newdir = create_tree.new_directory('selftest', root, 'selftest-id')
450
450
        create_tree.new_file('blackbox.py', newdir, 'hello1', 'blackbox-id')
451
 
        create_tree.apply()        
 
451
        create_tree.apply()
452
452
        mangle_tree,root = self.get_transform()
453
453
        selftest = mangle_tree.trans_id_tree_file_id('selftest-id')
454
454
        blackbox = mangle_tree.trans_id_tree_file_id('blackbox-id')
462
462
        bzrlib = create_tree.new_directory('bzrlib', root, 'bzrlib-id')
463
463
        tests = create_tree.new_directory('tests', bzrlib, 'tests-id')
464
464
        blackbox = create_tree.new_directory('blackbox', tests, 'blackbox-id')
465
 
        create_tree.new_file('test_too_much.py', blackbox, 'hello1', 
 
465
        create_tree.new_file('test_too_much.py', blackbox, 'hello1',
466
466
                             'test_too_much-id')
467
 
        create_tree.apply()        
 
467
        create_tree.apply()
468
468
        mangle_tree,root = self.get_transform()
469
469
        bzrlib = mangle_tree.trans_id_tree_file_id('bzrlib-id')
470
470
        tests = mangle_tree.trans_id_tree_file_id('tests-id')
471
471
        test_too_much = mangle_tree.trans_id_tree_file_id('test_too_much-id')
472
472
        mangle_tree.adjust_path('selftest', bzrlib, tests)
473
 
        mangle_tree.adjust_path('blackbox.py', tests, test_too_much) 
 
473
        mangle_tree.adjust_path('blackbox.py', tests, test_too_much)
474
474
        mangle_tree.set_executability(True, test_too_much)
475
475
        mangle_tree.apply()
476
476
 
477
477
    def test_both_rename3(self):
478
478
        create_tree,root = self.get_transform()
479
479
        tests = create_tree.new_directory('tests', root, 'tests-id')
480
 
        create_tree.new_file('test_too_much.py', tests, 'hello1', 
 
480
        create_tree.new_file('test_too_much.py', tests, 'hello1',
481
481
                             'test_too_much-id')
482
 
        create_tree.apply()        
 
482
        create_tree.apply()
483
483
        mangle_tree,root = self.get_transform()
484
484
        tests = mangle_tree.trans_id_tree_file_id('tests-id')
485
485
        test_too_much = mangle_tree.trans_id_tree_file_id('test_too_much-id')
486
486
        mangle_tree.adjust_path('selftest', root, tests)
487
 
        mangle_tree.adjust_path('blackbox.py', tests, test_too_much) 
 
487
        mangle_tree.adjust_path('blackbox.py', tests, test_too_much)
488
488
        mangle_tree.set_executability(True, test_too_much)
489
489
        mangle_tree.apply()
490
490
 
503
503
        newdir = move_id.new_directory('dir', root, 'newdir')
504
504
        move_id.adjust_path('name2', newdir, name1)
505
505
        move_id.apply()
506
 
        
 
506
 
507
507
    def test_replace_dangling_ie(self):
508
508
        create_tree, root = self.get_transform()
509
509
        # prepare tree
529
529
        self.requireFeature(SymlinkFeature)
530
530
        transform,root = self.get_transform()
531
531
        oz_id = transform.new_directory('oz', root, 'oz-id')
532
 
        wizard = transform.new_symlink('wizard', oz_id, 'wizard-target', 
 
532
        wizard = transform.new_symlink('wizard', oz_id, 'wizard-target',
533
533
                                       'wizard-id')
534
534
        wiz_id = transform.create_path('wizard2', oz_id)
535
535
        transform.create_symlink('behind_curtain', wiz_id)
536
 
        transform.version_file('wiz-id2', wiz_id)            
 
536
        transform.version_file('wiz-id2', wiz_id)
537
537
        transform.set_executability(True, wiz_id)
538
 
        self.assertEqual(transform.find_conflicts(), 
 
538
        self.assertEqual(transform.find_conflicts(),
539
539
                         [('non-file executability', wiz_id)])
540
540
        transform.set_executability(None, wiz_id)
541
541
        transform.apply()
542
542
        self.assertEqual(self.wt.path2id('oz/wizard'), 'wizard-id')
543
543
        self.assertEqual(file_kind(self.wt.abspath('oz/wizard')), 'symlink')
544
 
        self.assertEqual(os.readlink(self.wt.abspath('oz/wizard2')), 
 
544
        self.assertEqual(os.readlink(self.wt.abspath('oz/wizard2')),
545
545
                         'behind_curtain')
546
546
        self.assertEqual(os.readlink(self.wt.abspath('oz/wizard')),
547
547
                         'wizard-target')
574
574
        create.apply()
575
575
        conflicts,root = self.get_transform()
576
576
        # set up duplicate entry, duplicate id
577
 
        new_dorothy = conflicts.new_file('dorothy', root, 'dorothy', 
 
577
        new_dorothy = conflicts.new_file('dorothy', root, 'dorothy',
578
578
                                         'dorothy-id')
579
579
        old_dorothy = conflicts.trans_id_tree_file_id('dorothy-id')
580
580
        oz = conflicts.trans_id_tree_file_id('oz-id')
604
604
        tt, emerald, oz, old_dorothy, new_dorothy = self.get_conflicted()
605
605
        raw_conflicts = resolve_conflicts(tt)
606
606
        cooked_conflicts = cook_conflicts(raw_conflicts, tt)
607
 
        duplicate = DuplicateEntry('Moved existing file to', 'dorothy.moved', 
 
607
        duplicate = DuplicateEntry('Moved existing file to', 'dorothy.moved',
608
608
                                   'dorothy', None, 'dorothy-id')
609
609
        self.assertEqual(cooked_conflicts[0], duplicate)
610
 
        duplicate_id = DuplicateID('Unversioned existing file', 
 
610
        duplicate_id = DuplicateID('Unversioned existing file',
611
611
                                   'dorothy.moved', 'dorothy', None,
612
612
                                   'dorothy-id')
613
613
        self.assertEqual(cooked_conflicts[1], duplicate_id)
621
621
        unversioned_parent2 = UnversionedParent('Versioned directory', 'oz',
622
622
                                               'oz-id')
623
623
        self.assertEqual(cooked_conflicts[3], unversioned_parent)
624
 
        parent_loop = ParentLoop('Cancelled move', 'oz/emeraldcity', 
 
624
        parent_loop = ParentLoop('Cancelled move', 'oz/emeraldcity',
625
625
                                 'oz/emeraldcity', 'emerald-id', 'emerald-id')
626
626
        self.assertEqual(cooked_conflicts[4], deleted_parent)
627
627
        self.assertEqual(cooked_conflicts[5], unversioned_parent2)
750
750
 
751
751
    def test_set_executability_order(self):
752
752
        """Ensure that executability behaves the same, no matter what order.
753
 
        
 
753
 
754
754
        - create file and set executability simultaneously
755
755
        - create file and set executability afterward
756
756
        - unsetting the executability of a file whose executability has not been
1410
1410
        # textual merge
1411
1411
        self.assertEqual(this.wt.get_file('a').read(), 'y\nb\nc\nd\bz\n')
1412
1412
        # three-way text conflict
1413
 
        self.assertEqual(this.wt.get_file('b').read(), 
 
1413
        self.assertEqual(this.wt.get_file('b').read(),
1414
1414
                         conflict_text('b', 'b2'))
1415
1415
        # OTHER wins
1416
1416
        self.assertEqual(this.wt.get_file('c').read(), 'c2')
1420
1420
        self.assertEqual(this.wt.get_file('e').read(), 'e2')
1421
1421
        # No change
1422
1422
        self.assertEqual(this.wt.get_file('f').read(), 'f')
1423
 
        # Correct correct results when THIS == OTHER 
 
1423
        # Correct correct results when THIS == OTHER
1424
1424
        self.assertEqual(this.wt.get_file('g').read(), 'g')
1425
1425
        # Text conflict when THIS & OTHER are text and BASE is dir
1426
 
        self.assertEqual(this.wt.get_file('h').read(), 
 
1426
        self.assertEqual(this.wt.get_file('h').read(),
1427
1427
                         conflict_text('1\n2\n3\n4\n', 'h\ni\nj\nk\n'))
1428
1428
        self.assertEqual(this.wt.get_file_byname('h.THIS').read(),
1429
1429
                         '1\n2\n3\n4\n')
1430
1430
        self.assertEqual(this.wt.get_file_byname('h.OTHER').read(),
1431
1431
                         'h\ni\nj\nk\n')
1432
1432
        self.assertEqual(file_kind(this.wt.abspath('h.BASE')), 'directory')
1433
 
        self.assertEqual(this.wt.get_file('i').read(), 
 
1433
        self.assertEqual(this.wt.get_file('i').read(),
1434
1434
                         conflict_text('1\n2\n3\n4\n', 'h\ni\nj\nk\n'))
1435
1435
        self.assertEqual(this.wt.get_file_byname('i.THIS').read(),
1436
1436
                         '1\n2\n3\n4\n')
1460
1460
            tg.tt.new_symlink('b', tg.root, 'b', 'b')
1461
1461
            tg.tt.new_file('c', tg.root, 'c', 'c')
1462
1462
            tg.tt.new_symlink('d', tg.root, tg.name, 'd')
1463
 
        targets = ((base, 'base-e', 'base-f', None, None), 
1464
 
                   (this, 'other-e', 'this-f', 'other-g', 'this-h'), 
 
1463
        targets = ((base, 'base-e', 'base-f', None, None),
 
1464
                   (this, 'other-e', 'this-f', 'other-g', 'this-h'),
1465
1465
                   (other, 'other-e', None, 'other-g', 'other-h'))
1466
1466
        for tg, e_target, f_target, g_target, h_target in targets:
1467
 
            for link, target in (('e', e_target), ('f', f_target), 
 
1467
            for link, target in (('e', e_target), ('f', f_target),
1468
1468
                                 ('g', g_target), ('h', h_target)):
1469
1469
                if target is not None:
1470
1470
                    tg.tt.new_symlink(link, tg.root, target, link)
1496
1496
        base = TransformGroup("BASE", root_id)
1497
1497
        this = TransformGroup("THIS", root_id)
1498
1498
        other = TransformGroup("OTHER", root_id)
1499
 
        base_a, this_a, other_a = [t.tt.new_directory('a', t.root, 'a') 
 
1499
        base_a, this_a, other_a = [t.tt.new_directory('a', t.root, 'a')
1500
1500
                                   for t in [base, this, other]]
1501
 
        base_b, this_b, other_b = [t.tt.new_directory('b', t.root, 'b') 
 
1501
        base_b, this_b, other_b = [t.tt.new_directory('b', t.root, 'b')
1502
1502
                                   for t in [base, this, other]]
1503
1503
        base.tt.new_directory('c', base_a, 'c')
1504
1504
        this.tt.new_directory('c1', this_a, 'c')
1529
1529
        base = TransformGroup("BASE", root_id)
1530
1530
        this = TransformGroup("THIS", root_id)
1531
1531
        other = TransformGroup("OTHER", root_id)
1532
 
        base_a, this_a, other_a = [t.tt.new_directory('a', t.root, 'a') 
 
1532
        base_a, this_a, other_a = [t.tt.new_directory('a', t.root, 'a')
1533
1533
                                   for t in [base, this, other]]
1534
 
        base_b, this_b, other_b = [t.tt.new_directory('b', t.root, 'b') 
 
1534
        base_b, this_b, other_b = [t.tt.new_directory('b', t.root, 'b')
1535
1535
                                   for t in [base, this, other]]
1536
1536
 
1537
1537
        base.tt.new_file('g', base_a, 'g', 'g')
1628
1628
        os.symlink('foo', 'target2/symlink')
1629
1629
        build_tree(source.basis_tree(), target)
1630
1630
        self.assertEqual([], target.conflicts())
1631
 
        
 
1631
 
1632
1632
    def test_directory_conflict_handling(self):
1633
1633
        """Ensure that when building trees, conflict handling is done"""
1634
1634
        source = self.make_branch_and_tree('source')
1690
1690
        target = self.make_branch_and_tree('target')
1691
1691
        self.build_tree(['target/name'])
1692
1692
        target.add('name')
1693
 
        self.assertRaises(errors.WorkingTreeAlreadyPopulated, 
 
1693
        self.assertRaises(errors.WorkingTreeAlreadyPopulated,
1694
1694
            build_tree, source.basis_tree(), target)
1695
1695
 
1696
1696
    def test_build_tree_rename_count(self):