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