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
11
class TestSmartAdd(TestCaseInTempDir):
11
class TestSmartAdd(TestCaseWithTransport):
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".")
18
wt = self.make_branch_and_tree('.')
20
smart_add_tree(wt, (u".",))
21
self.assertNotEqual(branch.working_tree().path2id(path), None)
22
self.assertNotEqual(wt.path2id(path), None)
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('.')
29
31
os.chdir("original")
32
smart_add_tree(wt, (u".",))
32
self.assertNotEqual(branch.working_tree().path2id(path), None)
34
self.assertNotEqual(wt.path2id(path), None)
34
36
def test_add_tree_from_above_tree(self):
35
37
"""Test adding a tree from above the tree."""
53
56
"original/child/", "original/child/path")
55
58
self.build_tree(build_paths)
56
branch = Branch.initialize(u".")
57
child_branch = Branch.initialize("original/child")
59
wt = self.make_branch_and_tree('.')
61
child_tree = self.make_branch_and_tree('original/child')
62
smart_add_tree(wt, (u".",))
60
self.assertNotEqual((path, branch.working_tree().path2id(path)),
64
self.assertNotEqual((path, wt.path2id(path)),
62
66
for path in full_child_paths:
63
self.assertEqual((path, branch.working_tree().path2id(path)),
67
self.assertEqual((path, wt.path2id(path)),
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)
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".")
77
wt = self.make_branch_and_tree('.')
79
smart_add_tree(wt, paths)
76
self.assertNotEqual(branch.working_tree().path2id(path), None)
81
self.assertNotEqual(wt.path2id(path), None)
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'.')
87
wt = self.make_branch_and_tree('.')
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'])
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('.')
99
self.assertRaises(NoSuchFile, smart_add_tree, wt, 'non-existant-file')
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'.')
104
wt = self.make_branch_and_tree('.')
100
106
self.build_tree(['inertiatic/', 'inertiatic/esp', 'inertiatic/CVS',
101
107
'inertiatic/foo.pyc'])
102
added, ignored = smart_add(u'.')
103
self.AssertSubset(('inertiatic', 'inertiatic/esp'), added)
104
self.AssertSubset(('CVS', '*.py[oc]'), ignored)
105
self.AssertSubset(('inertiatic/CVS',), ignored['CVS'])
106
self.AssertSubset(('inertiatic/foo.pyc',), ignored['*.py[oc]'])
109
class TestSmartAddBranch(TestCaseInTempDir):
108
added, ignored = smart_add_tree(wt, u'.')
109
self.assertSubset(('inertiatic', 'inertiatic/esp'), added)
110
self.assertSubset(('CVS', '*.py[oc]'), ignored)
111
self.assertSubset(('inertiatic/CVS',), ignored['CVS'])
112
self.assertSubset(('inertiatic/foo.pyc',), ignored['*.py[oc]'])
115
class TestSmartAddBranch(TestCaseWithTransport):
110
116
"""Test smart adds with a specified branch."""
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".")
119
smart_add_tree(tree, (u".",))
122
wt = self.make_branch_and_tree('.')
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)
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".")
133
wt = self.make_branch_and_tree('.')
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)
135
140
def test_add_tree_from_above_tree(self):
136
141
"""Test adding a tree from above the tree."""
165
170
self.assertEqual((path, tree.path2id(path)),
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)
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".")
177
smart_add_tree(tree, paths)
180
wt = self.make_branch_and_tree('.')
182
smart_add_tree(wt, paths)
178
183
for path in paths:
179
self.assertNotEqual(tree.path2id(path), None)
182
class TestAddActions(TestCaseInTempDir):
184
self.assertNotEqual(wt.path2id(path), None)
187
class TestAddActions(TestCase):
184
189
def test_null(self):
185
190
from bzrlib.add import add_action_null