~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_add.py

[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
from bzrlib.branch import Branch
6
6
from bzrlib.errors import NotBranchError
7
7
from bzrlib.inventory import InventoryFile
 
8
from bzrlib.workingtree import WorkingTree
8
9
 
9
10
class TestSmartAdd(TestCaseInTempDir):
10
11
 
13
14
        from bzrlib.add import smart_add
14
15
        paths = ("original/", "original/file1", "original/file2")
15
16
        self.build_tree(paths)
16
 
        branch = Branch.initialize(".")
17
 
        smart_add((".",), recurse=True)
 
17
        branch = Branch.initialize(u".")
 
18
        smart_add((u".",), recurse=True)
18
19
        for path in paths:
19
20
            self.assertNotEqual(branch.working_tree().path2id(path), None)
20
21
 
23
24
        from bzrlib.add import smart_add
24
25
        paths = ("original/", "original/file1", "original/file2")
25
26
        self.build_tree(paths)
26
 
        branch = Branch.initialize(".")
 
27
        branch = Branch.initialize(u".")
27
28
        os.chdir("original")
28
 
        smart_add((".",), recurse=True)
 
29
        smart_add((u".",), recurse=True)
29
30
        for path in paths:
30
31
            self.assertNotEqual(branch.working_tree().path2id(path), None)
31
32
 
52
53
                       "original/child/", "original/child/path")
53
54
        
54
55
        self.build_tree(build_paths)
55
 
        branch = Branch.initialize(".")
 
56
        branch = Branch.initialize(u".")
56
57
        child_branch = Branch.initialize("original/child")
57
 
        smart_add((".",), True, add_reporter_null)
 
58
        smart_add((u".",), True, add_reporter_null)
58
59
        for path in paths:
59
60
            self.assertNotEqual((path, branch.working_tree().path2id(path)),
60
61
                                (path, None))
69
70
        from bzrlib.add import smart_add
70
71
        paths = ("file1", "file2")
71
72
        self.build_tree(paths)
72
 
        branch = Branch.initialize(".")
 
73
        branch = Branch.initialize(u".")
73
74
        smart_add(paths)
74
75
        for path in paths:
75
76
            self.assertNotEqual(branch.working_tree().path2id(path), None)
79
80
 
80
81
    def test_add_dot_from_root(self):
81
82
        """Test adding . from the root of the tree.""" 
82
 
        from bzrlib.add import smart_add_branch
 
83
        from bzrlib.add import smart_add_tree
83
84
        paths = ("original/", "original/file1", "original/file2")
84
85
        self.build_tree(paths)
85
 
        branch = Branch.initialize(".")
86
 
        smart_add_branch(branch, (".",))
 
86
        Branch.initialize(u".")
 
87
        tree = WorkingTree()
 
88
        smart_add_tree(tree, (u".",))
87
89
        for path in paths:
88
 
            self.assertNotEqual(branch.working_tree().path2id(path), None)
 
90
            self.assertNotEqual(tree.path2id(path), None)
89
91
 
90
92
    def test_add_dot_from_subdir(self):
91
93
        """Test adding . from a subdir of the tree.""" 
92
 
        from bzrlib.add import smart_add_branch
 
94
        from bzrlib.add import smart_add_tree
93
95
        paths = ("original/", "original/file1", "original/file2")
94
96
        self.build_tree(paths)
95
 
        branch = Branch.initialize(".")
 
97
        Branch.initialize(u".")
 
98
        tree = WorkingTree()
96
99
        os.chdir("original")
97
 
        smart_add_branch(branch, (".",))
 
100
        smart_add_tree(tree, (u".",))
98
101
        for path in paths:
99
 
            self.assertNotEqual(branch.working_tree().path2id(path), None)
 
102
            self.assertNotEqual(tree.path2id(path), None)
100
103
 
101
104
    def test_add_tree_from_above_tree(self):
102
105
        """Test adding a tree from above the tree.""" 
103
 
        from bzrlib.add import smart_add_branch
 
106
        from bzrlib.add import smart_add_tree
104
107
        paths = ("original/", "original/file1", "original/file2")
105
108
        branch_paths = ("branch/", "branch/original/", "branch/original/file1",
106
109
                        "branch/original/file2")
107
110
        self.build_tree(branch_paths)
108
 
        branch = Branch.initialize("branch")
109
 
        smart_add_branch(branch, ("branch",))
 
111
        Branch.initialize("branch")
 
112
        tree = WorkingTree("branch")
 
113
        smart_add_tree(tree, ("branch",))
110
114
        for path in paths:
111
 
            self.assertNotEqual(branch.working_tree().path2id(path), None)
 
115
            self.assertNotEqual(tree.path2id(path), None)
112
116
 
113
117
    def test_add_above_tree_preserves_tree(self):
114
118
        """Test nested trees are not affect by an add above them."""
115
 
        from bzrlib.add import smart_add_branch
 
119
        from bzrlib.add import smart_add_tree
116
120
        paths = ("original/", "original/file1", "original/file2")
117
121
        child_paths = ("path")
118
122
        full_child_paths = ("original/child", "original/child/path")
119
123
        build_paths = ("original/", "original/file1", "original/file2", 
120
124
                       "original/child/", "original/child/path")
121
125
        self.build_tree(build_paths)
122
 
        branch = Branch.initialize(".")
 
126
        Branch.initialize(u".")
 
127
        tree = WorkingTree()
123
128
        child_branch = Branch.initialize("original/child")
124
 
        smart_add_branch(branch, (".",))
 
129
        smart_add_tree(tree, (u".",))
125
130
        for path in paths:
126
 
            self.assertNotEqual((path, branch.working_tree().path2id(path)),
 
131
            self.assertNotEqual((path, tree.path2id(path)),
127
132
                                (path, None))
128
133
        for path in full_child_paths:
129
 
            self.assertEqual((path, branch.working_tree().path2id(path)),
 
134
            self.assertEqual((path, tree.path2id(path)),
130
135
                             (path, None))
131
136
        for path in child_paths:
132
137
            self.assertEqual(child_branch.working_tree().path2id(path), None)
133
138
 
134
139
    def test_add_paths(self):
135
140
        """Test smart-adding a list of paths."""
136
 
        from bzrlib.add import smart_add_branch
 
141
        from bzrlib.add import smart_add_tree
137
142
        paths = ("file1", "file2")
138
143
        self.build_tree(paths)
139
 
        branch = Branch.initialize(".")
140
 
        smart_add_branch(branch, paths)
 
144
        Branch.initialize(u".")
 
145
        tree = WorkingTree()
 
146
        smart_add_tree(tree, paths)
141
147
        for path in paths:
142
 
            self.assertNotEqual(branch.working_tree().path2id(path), None)
 
148
            self.assertNotEqual(tree.path2id(path), None)
143
149
 
144
150
class TestAddCallbacks(TestCaseInTempDir):
145
151