/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_add.py

  • Committer: Aaron Bentley
  • Date: 2005-12-13 18:56:57 UTC
  • mto: (1185.60.3 Aaron's mergeable stuff)
  • mto: This revision was merged to the branch mainline in revision 1530.
  • Revision ID: abentley@panoramicfeedback.com-20051213185657-3f900268287d6559
bzr add reports ignored patterns.

Show diffs side-by-side

added added

removed removed

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