15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
from bzrlib import tests
20
27
from bzrlib.bzrdir import BzrDir
21
28
from bzrlib.conflicts import (DuplicateEntry, DuplicateID, MissingParent,
22
29
UnversionedParent, ParentLoop, DeletingParent,)
30
37
from bzrlib.transform import (TreeTransform, ROOT_PARENT, FinalPaths,
31
38
resolve_conflicts, cook_conflicts,
32
39
find_interesting, build_tree, get_backup_name)
33
import bzrlib.urlutils as urlutils
35
42
class TestTreeTransform(TestCaseInTempDir):
42
49
def get_transform(self):
43
50
transform = TreeTransform(self.wt)
44
51
#self.addCleanup(transform.finalize)
45
return transform, transform.trans_id_tree_file_id(self.wt.get_root_id())
52
return transform, transform.root
47
54
def test_existing_limbo(self):
48
55
limbo_name = urlutils.local_path_from_url(
192
199
transform3.delete_contents(oz_id)
193
200
self.assertEqual(transform3.find_conflicts(),
194
201
[('missing parent', oz_id)])
195
root_id = transform3.trans_id_tree_file_id('TREE_ROOT')
202
root_id = transform3.root
196
203
tip_id = transform3.trans_id_tree_file_id('tip-id')
197
204
transform3.adjust_path('tip', root_id, tip_id)
198
205
transform3.apply()
224
231
def test_name_invariants(self):
225
232
create_tree, root = self.get_transform()
227
root = create_tree.trans_id_tree_file_id('TREE_ROOT')
234
root = create_tree.root
228
235
create_tree.new_file('name1', root, 'hello1', 'name1')
229
236
create_tree.new_file('name2', root, 'hello2', 'name2')
230
237
ddir = create_tree.new_directory('dying_directory', root, 'ddir')
319
326
def test_move_dangling_ie(self):
320
327
create_tree, root = self.get_transform()
322
root = create_tree.trans_id_tree_file_id('TREE_ROOT')
329
root = create_tree.root
323
330
create_tree.new_file('name1', root, 'hello1', 'name1')
324
331
create_tree.apply()
325
332
delete_contents, root = self.get_transform()
335
342
def test_replace_dangling_ie(self):
336
343
create_tree, root = self.get_transform()
338
root = create_tree.trans_id_tree_file_id('TREE_ROOT')
345
root = create_tree.root
339
346
create_tree.new_file('name1', root, 'hello1', 'name1')
340
347
create_tree.apply()
341
348
delete_contents = TreeTransform(self.wt)
535
542
self.assertTrue(wt.is_executable('soc'))
536
543
self.assertTrue(wt.is_executable('sac'))
545
def test_preserve_mode(self):
546
"""File mode is preserved when replacing content"""
547
if sys.platform == 'win32':
548
raise TestSkipped('chmod has no effect on win32')
549
transform, root = self.get_transform()
550
transform.new_file('file1', root, 'contents', 'file1-id', True)
552
self.assertTrue(self.wt.is_executable('file1-id'))
553
transform, root = self.get_transform()
554
file1_id = transform.trans_id_tree_file_id('file1-id')
555
transform.delete_contents(file1_id)
556
transform.create_file('contents2', file1_id)
558
self.assertTrue(self.wt.is_executable('file1-id'))
560
def test__set_mode_stats_correctly(self):
561
"""_set_mode stats to determine file mode."""
562
if sys.platform == 'win32':
563
raise TestSkipped('chmod has no effect on win32')
567
def instrumented_stat(path):
568
stat_paths.append(path)
569
return real_stat(path)
571
transform, root = self.get_transform()
573
bar1_id = transform.new_file('bar', root, 'bar contents 1\n',
574
file_id='bar-id-1', executable=False)
577
transform, root = self.get_transform()
578
bar1_id = transform.trans_id_tree_path('bar')
579
bar2_id = transform.trans_id_tree_path('bar2')
581
os.stat = instrumented_stat
582
transform.create_file('bar2 contents\n', bar2_id, mode_id=bar1_id)
587
bar1_abspath = self.wt.abspath('bar')
588
self.assertEqual([bar1_abspath], stat_paths)
539
591
class TransformGroup(object):
540
def __init__(self, dirname):
592
def __init__(self, dirname, root_id):
541
593
self.name = dirname
542
594
os.mkdir(dirname)
543
595
self.wt = BzrDir.create_standalone_workingtree(dirname)
596
self.wt.set_root_id(root_id)
544
597
self.b = self.wt.branch
545
598
self.tt = TreeTransform(self.wt)
546
599
self.root = self.tt.trans_id_tree_file_id(self.wt.get_root_id())
553
606
class TestTransformMerge(TestCaseInTempDir):
554
607
def test_text_merge(self):
555
base = TransformGroup("base")
608
root_id = generate_ids.gen_root_id()
609
base = TransformGroup("base", root_id)
556
610
base.tt.new_file('a', base.root, 'a\nb\nc\nd\be\n', 'a')
557
611
base.tt.new_file('b', base.root, 'b1', 'b')
558
612
base.tt.new_file('c', base.root, 'c', 'c')
562
616
base.tt.new_directory('g', base.root, 'g')
563
617
base.tt.new_directory('h', base.root, 'h')
565
other = TransformGroup("other")
619
other = TransformGroup("other", root_id)
566
620
other.tt.new_file('a', other.root, 'y\nb\nc\nd\be\n', 'a')
567
621
other.tt.new_file('b', other.root, 'b2', 'b')
568
622
other.tt.new_file('c', other.root, 'c2', 'c')
573
627
other.tt.new_file('h', other.root, 'h\ni\nj\nk\n', 'h')
574
628
other.tt.new_file('i', other.root, 'h\ni\nj\nk\n', 'i')
576
this = TransformGroup("this")
630
this = TransformGroup("this", root_id)
577
631
this.tt.new_file('a', this.root, 'a\nb\nc\nd\bz\n', 'a')
578
632
this.tt.new_file('b', this.root, 'b', 'b')
579
633
this.tt.new_file('c', this.root, 'c', 'c')
630
684
def test_file_merge(self):
631
685
if not has_symlinks():
632
686
raise TestSkipped('Symlinks are not supported on this platform')
633
base = TransformGroup("BASE")
634
this = TransformGroup("THIS")
635
other = TransformGroup("OTHER")
687
root_id = generate_ids.gen_root_id()
688
base = TransformGroup("BASE", root_id)
689
this = TransformGroup("THIS", root_id)
690
other = TransformGroup("OTHER", root_id)
636
691
for tg in this, base, other:
637
692
tg.tt.new_directory('a', tg.root, 'a')
638
693
tg.tt.new_symlink('b', tg.root, 'b', 'b')
670
725
self.assertIs(os.path.lexists(this.wt.abspath('h.OTHER')), True)
672
727
def test_filename_merge(self):
673
base = TransformGroup("BASE")
674
this = TransformGroup("THIS")
675
other = TransformGroup("OTHER")
728
root_id = generate_ids.gen_root_id()
729
base = TransformGroup("BASE", root_id)
730
this = TransformGroup("THIS", root_id)
731
other = TransformGroup("OTHER", root_id)
676
732
base_a, this_a, other_a = [t.tt.new_directory('a', t.root, 'a')
677
733
for t in [base, this, other]]
678
734
base_b, this_b, other_b = [t.tt.new_directory('b', t.root, 'b')
702
758
self.assertEqual(this.wt.id2path('f'), pathjoin('b/f1'))
704
760
def test_filename_merge_conflicts(self):
705
base = TransformGroup("BASE")
706
this = TransformGroup("THIS")
707
other = TransformGroup("OTHER")
761
root_id = generate_ids.gen_root_id()
762
base = TransformGroup("BASE", root_id)
763
this = TransformGroup("THIS", root_id)
764
other = TransformGroup("OTHER", root_id)
708
765
base_a, this_a, other_a = [t.tt.new_directory('a', t.root, 'a')
709
766
for t in [base, this, other]]
710
767
base_b, this_b, other_b = [t.tt.new_directory('b', t.root, 'b')
853
911
target = self.make_branch_and_tree('target')
854
912
self.build_tree(['target/name'])
855
913
target.add('name')
856
self.assertRaises(AssertionError, build_tree, source.basis_tree(),
914
self.assertRaises(errors.WorkingTreeAlreadyPopulated,
915
build_tree, source.basis_tree(), target)
860
918
class MockTransform(object):