~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_add.py

  • Committer: Aaron Bentley
  • Date: 2006-02-22 14:39:42 UTC
  • mto: (2027.1.2 revert-subpath-56549)
  • mto: This revision was merged to the branch mainline in revision 1570.
  • Revision ID: abentley@panoramicfeedback.com-20060222143942-ae72299f2de66767
Fixed build_tree with symlinks

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import os
2
2
import unittest
3
3
 
4
 
from bzrlib.tests import TestCaseInTempDir, TestCase
 
4
from bzrlib.add import smart_add, smart_add_tree
 
5
from bzrlib.tests import TestCaseWithTransport, TestCase
5
6
from bzrlib.branch import Branch
6
7
from bzrlib.errors import NotBranchError, NoSuchFile
7
8
from bzrlib.inventory import InventoryFile, Inventory
8
9
from bzrlib.workingtree import WorkingTree
9
 
from bzrlib.add import smart_add
10
10
 
11
 
class TestSmartAdd(TestCaseInTempDir):
 
11
class TestSmartAdd(TestCaseWithTransport):
12
12
 
13
13
    def test_add_dot_from_root(self):
14
14
        """Test adding . from the root of the tree.""" 
15
15
        from bzrlib.add import smart_add
16
16
        paths = ("original/", "original/file1", "original/file2")
17
17
        self.build_tree(paths)
18
 
        branch = Branch.initialize(u".")
19
 
        smart_add((u".",))
 
18
        wt = self.make_branch_and_tree('.')
 
19
        branch = wt.branch
 
20
        smart_add_tree(wt, (u".",))
20
21
        for path in paths:
21
 
            self.assertNotEqual(branch.working_tree().path2id(path), None)
 
22
            self.assertNotEqual(wt.path2id(path), None)
22
23
 
23
24
    def test_add_dot_from_subdir(self):
24
25
        """Test adding . from a subdir of the tree.""" 
25
26
        from bzrlib.add import smart_add
26
27
        paths = ("original/", "original/file1", "original/file2")
27
28
        self.build_tree(paths)
28
 
        branch = Branch.initialize(u".")
 
29
        wt = self.make_branch_and_tree('.')
 
30
        branch = wt.branch
29
31
        os.chdir("original")
30
 
        smart_add((u".",))
 
32
        smart_add_tree(wt, (u".",))
31
33
        for path in paths:
32
 
            self.assertNotEqual(branch.working_tree().path2id(path), None)
 
34
            self.assertNotEqual(wt.path2id(path), None)
33
35
 
34
36
    def test_add_tree_from_above_tree(self):
35
37
        """Test adding a tree from above the tree.""" 
38
40
        branch_paths = ("branch/", "branch/original/", "branch/original/file1",
39
41
                        "branch/original/file2")
40
42
        self.build_tree(branch_paths)
41
 
        branch = Branch.initialize("branch")
42
 
        smart_add(("branch",))
 
43
        wt = self.make_branch_and_tree('branch')
 
44
        branch = wt.branch
 
45
        smart_add_tree(wt, ("branch",))
43
46
        for path in paths:
44
 
            self.assertNotEqual(branch.working_tree().path2id(path), None)
 
47
            self.assertNotEqual(wt.path2id(path), None)
45
48
 
46
49
    def test_add_above_tree_preserves_tree(self):
47
50
        """Test nested trees are not affect by an add above them."""
53
56
                       "original/child/", "original/child/path")
54
57
        
55
58
        self.build_tree(build_paths)
56
 
        branch = Branch.initialize(u".")
57
 
        child_branch = Branch.initialize("original/child")
58
 
        smart_add((u".",))
 
59
        wt = self.make_branch_and_tree('.')
 
60
        branch = wt.branch
 
61
        child_tree = self.make_branch_and_tree('original/child')
 
62
        smart_add_tree(wt, (u".",))
59
63
        for path in paths:
60
 
            self.assertNotEqual((path, branch.working_tree().path2id(path)),
 
64
            self.assertNotEqual((path, wt.path2id(path)),
61
65
                                (path, None))
62
66
        for path in full_child_paths:
63
 
            self.assertEqual((path, branch.working_tree().path2id(path)),
 
67
            self.assertEqual((path, wt.path2id(path)),
64
68
                             (path, None))
65
69
        for path in child_paths:
66
 
            self.assertEqual(child_branch.working_tree().path2id(path), None)
 
70
            self.assertEqual(child_tree.path2id(path), None)
67
71
 
68
72
    def test_add_paths(self):
69
73
        """Test smart-adding a list of paths."""
70
74
        from bzrlib.add import smart_add
71
75
        paths = ("file1", "file2")
72
76
        self.build_tree(paths)
73
 
        branch = Branch.initialize(u".")
74
 
        smart_add(paths)
 
77
        wt = self.make_branch_and_tree('.')
 
78
        branch = wt.branch
 
79
        smart_add_tree(wt, paths)
75
80
        for path in paths:
76
 
            self.assertNotEqual(branch.working_tree().path2id(path), None)
 
81
            self.assertNotEqual(wt.path2id(path), None)
77
82
 
78
83
    def test_add_dry_run(self):
79
84
        """Test a dry run add, make sure nothing is added."""
80
85
        from bzrlib.commands import run_bzr
81
86
        eq = self.assertEqual
82
 
        b = Branch.initialize(u'.')
83
 
        t = b.working_tree()
 
87
        wt = self.make_branch_and_tree('.')
 
88
        branch = wt.branch
84
89
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
85
 
        eq(list(t.unknowns()), ['inertiatic'])
 
90
        eq(list(wt.unknowns()), ['inertiatic'])
86
91
        self.capture('add --dry-run .')
87
 
        eq(list(t.unknowns()), ['inertiatic'])
 
92
        eq(list(wt.unknowns()), ['inertiatic'])
88
93
 
89
94
    def test_add_non_existant(self):
90
95
        """Test smart-adding a file that does not exist."""
91
96
        from bzrlib.add import smart_add
92
 
        branch = Branch.initialize(u".")
93
 
        self.assertRaises(NoSuchFile, smart_add, 'non-existant-file')
 
97
        wt = self.make_branch_and_tree('.')
 
98
        branch = wt.branch
 
99
        self.assertRaises(NoSuchFile, smart_add_tree, wt, 'non-existant-file')
94
100
 
95
101
    def test_returns(self):
96
102
        """Correctly returns added/ignored files"""
97
103
        from bzrlib.commands import run_bzr
98
 
        b = Branch.initialize(u'.')
99
 
        t = b.working_tree()
 
104
        wt = self.make_branch_and_tree('.')
 
105
        branch = wt.branch
100
106
        self.build_tree(['inertiatic/', 'inertiatic/esp', 'inertiatic/CVS', 
101
107
                        'inertiatic/foo.pyc'])
102
 
        added, ignored = smart_add(u'.')
 
108
        added, ignored = smart_add_tree(wt, u'.')
103
109
        self.AssertSubset(('inertiatic', 'inertiatic/esp'), added)
104
110
        self.AssertSubset(('CVS', '*.py[oc]'), ignored)
105
111
        self.AssertSubset(('inertiatic/CVS',), ignored['CVS'])
106
112
        self.AssertSubset(('inertiatic/foo.pyc',), ignored['*.py[oc]'])
107
113
 
108
114
 
109
 
class TestSmartAddBranch(TestCaseInTempDir):
 
115
class TestSmartAddBranch(TestCaseWithTransport):
110
116
    """Test smart adds with a specified branch."""
111
117
 
112
118
    def test_add_dot_from_root(self):
113
119
        """Test adding . from the root of the tree.""" 
114
 
        from bzrlib.add import smart_add_tree
115
120
        paths = ("original/", "original/file1", "original/file2")
116
121
        self.build_tree(paths)
117
 
        Branch.initialize(u".")
118
 
        tree = WorkingTree()
119
 
        smart_add_tree(tree, (u".",))
 
122
        wt = self.make_branch_and_tree('.')
 
123
        branch = wt.branch
 
124
        smart_add_tree(wt, (u".",))
120
125
        for path in paths:
121
 
            self.assertNotEqual(tree.path2id(path), None)
 
126
            self.assertNotEqual(wt.path2id(path), None)
122
127
 
123
128
    def test_add_dot_from_subdir(self):
124
129
        """Test adding . from a subdir of the tree.""" 
125
130
        from bzrlib.add import smart_add_tree
126
131
        paths = ("original/", "original/file1", "original/file2")
127
132
        self.build_tree(paths)
128
 
        Branch.initialize(u".")
129
 
        tree = WorkingTree()
 
133
        wt = self.make_branch_and_tree('.')
 
134
        branch = wt.branch
130
135
        os.chdir("original")
131
 
        smart_add_tree(tree, (u".",))
 
136
        smart_add_tree(wt, (u".",))
132
137
        for path in paths:
133
 
            self.assertNotEqual(tree.path2id(path), None)
 
138
            self.assertNotEqual(wt.path2id(path), None)
134
139
 
135
140
    def test_add_tree_from_above_tree(self):
136
141
        """Test adding a tree from above the tree.""" 
139
144
        branch_paths = ("branch/", "branch/original/", "branch/original/file1",
140
145
                        "branch/original/file2")
141
146
        self.build_tree(branch_paths)
142
 
        Branch.initialize("branch")
143
 
        tree = WorkingTree("branch")
 
147
        tree = self.make_branch_and_tree('branch')
 
148
        branch = tree.branch
144
149
        smart_add_tree(tree, ("branch",))
145
150
        for path in paths:
146
151
            self.assertNotEqual(tree.path2id(path), None)
154
159
        build_paths = ("original/", "original/file1", "original/file2", 
155
160
                       "original/child/", "original/child/path")
156
161
        self.build_tree(build_paths)
157
 
        Branch.initialize(u".")
158
 
        tree = WorkingTree()
159
 
        child_branch = Branch.initialize("original/child")
 
162
        tree = self.make_branch_and_tree('.')
 
163
        branch = tree.branch
 
164
        child_tree = self.make_branch_and_tree("original/child")
160
165
        smart_add_tree(tree, (u".",))
161
166
        for path in paths:
162
167
            self.assertNotEqual((path, tree.path2id(path)),
165
170
            self.assertEqual((path, tree.path2id(path)),
166
171
                             (path, None))
167
172
        for path in child_paths:
168
 
            self.assertEqual(child_branch.working_tree().path2id(path), None)
 
173
            self.assertEqual(child_tree.path2id(path), None)
169
174
 
170
175
    def test_add_paths(self):
171
176
        """Test smart-adding a list of paths."""
172
177
        from bzrlib.add import smart_add_tree
173
178
        paths = ("file1", "file2")
174
179
        self.build_tree(paths)
175
 
        Branch.initialize(u".")
176
 
        tree = WorkingTree()
177
 
        smart_add_tree(tree, paths)
 
180
        wt = self.make_branch_and_tree('.')
 
181
        branch = wt.branch
 
182
        smart_add_tree(wt, paths)
178
183
        for path in paths:
179
 
            self.assertNotEqual(tree.path2id(path), None)
180
 
 
181
 
 
182
 
class TestAddActions(TestCaseInTempDir):
 
184
            self.assertNotEqual(wt.path2id(path), None)
 
185
 
 
186
 
 
187
class TestAddActions(TestCase):
183
188
 
184
189
    def test_null(self):
185
190
        from bzrlib.add import add_action_null