1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
import os
import unittest
from bzrlib.selftest import TestCaseInTempDir, TestCase
from bzrlib.branch import Branch
from bzrlib.errors import NotBranchError, NotVersionedError
class TestSmartAdd(TestCaseInTempDir):
def test_add_dot_from_root(self):
"""Test adding . from the root of the tree."""
from bzrlib.add import smart_add
paths = ("original/", "original/file1", "original/file2")
self.build_tree(paths)
branch = Branch(".", init=True)
smart_add((".",), False, True)
for path in paths:
self.assertNotEqual(branch.inventory.path2id(path), None)
def test_add_dot_from_subdir(self):
"""Test adding . from a subdir of the tree."""
from bzrlib.add import smart_add
paths = ("original/", "original/file1", "original/file2")
self.build_tree(paths)
branch = Branch(".", init=True)
os.chdir("original")
smart_add((".",), False, True)
for path in paths:
self.assertNotEqual(branch.inventory.path2id(path), None)
def test_add_tree_from_above_tree(self):
"""Test adding a tree from above the tree."""
from bzrlib.add import smart_add
paths = ("original/", "original/file1", "original/file2")
branch_paths = ("branch/", "branch/original/", "branch/original/file1",
"branch/original/file2")
self.build_tree(branch_paths)
branch = Branch("branch", init=True)
smart_add(("branch",), False, True)
for path in paths:
self.assertNotEqual(branch.inventory.path2id(path), None)
def test_add_above_tree_preserves_tree(self):
"""Test nested trees are not affect by an add above them."""
from bzrlib.add import smart_add
paths = ("original/", "original/file1", "original/file2")
child_paths = ("path",)
full_child_paths = ("original/child", "original/child/path")
build_paths = ("original/", "original/file1", "original/file2",
"original/child/", "original/child/path")
self.build_tree(build_paths)
branch = Branch(".", init=True)
child_branch = Branch("original/child", init=True)
smart_add((".",), False, True)
for path in paths:
self.assertNotEqual((path, branch.inventory.path2id(path)),
(path, None))
for path in full_child_paths:
self.assertEqual((path, branch.inventory.path2id(path)),
(path, None))
for path in child_paths:
self.assertEqual(child_branch.inventory.path2id(path), None)
def test_add_paths(self):
"""Test smart-adding a list of paths."""
from bzrlib.add import smart_add
paths = ("file1", "file2")
self.build_tree(paths)
branch = Branch(".", init=True)
smart_add(paths, False, True)
for path in paths:
self.assertNotEqual(branch.inventory.path2id(path), None)
class TestSmartAddBranch(TestCaseInTempDir):
"""Test smart adds with a specified branch."""
def test_add_dot_from_root(self):
"""Test adding . from the root of the tree."""
from bzrlib.add import smart_add_branch
paths = ("original/", "original/file1", "original/file2")
self.build_tree(paths)
branch = Branch(".", init=True)
smart_add_branch(branch, (".",), False, True)
for path in paths:
self.assertNotEqual(branch.inventory.path2id(path), None)
def test_add_dot_from_subdir(self):
"""Test adding . from a subdir of the tree."""
from bzrlib.add import smart_add_branch
paths = ("original/", "original/file1", "original/file2")
self.build_tree(paths)
branch = Branch(".", init=True)
os.chdir("original")
smart_add_branch(branch, (".",), False, True)
for path in paths:
self.assertNotEqual(branch.inventory.path2id(path), None)
def test_add_tree_from_above_tree(self):
"""Test adding a tree from above the tree."""
from bzrlib.add import smart_add_branch
paths = ("original/", "original/file1", "original/file2")
branch_paths = ("branch/", "branch/original/", "branch/original/file1",
"branch/original/file2")
self.build_tree(branch_paths)
branch = Branch("branch", init=True)
smart_add_branch(branch, ("branch",), False, True)
for path in paths:
self.assertNotEqual(branch.inventory.path2id(path), None)
def test_add_above_tree_preserves_tree(self):
"""Test nested trees are not affect by an add above them."""
from bzrlib.add import smart_add_branch
paths = ("original/", "original/file1", "original/file2")
child_paths = ("path")
full_child_paths = ("original/child", "original/child/path")
build_paths = ("original/", "original/file1", "original/file2",
"original/child/", "original/child/path")
self.build_tree(build_paths)
branch = Branch(".", init=True)
child_branch = Branch("original/child", init=True)
smart_add_branch(branch, (".",), False, True)
for path in paths:
self.assertNotEqual((path, branch.inventory.path2id(path)),
(path, None))
for path in full_child_paths:
self.assertEqual((path, branch.inventory.path2id(path)),
(path, None))
for path in child_paths:
self.assertEqual(child_branch.inventory.path2id(path), None)
def test_add_paths(self):
"""Test smart-adding a list of paths."""
from bzrlib.add import smart_add_branch
paths = ("file1", "file2")
self.build_tree(paths)
branch = Branch(".", init=True)
smart_add_branch(branch, paths, False, True)
for path in paths:
self.assertNotEqual(branch.inventory.path2id(path), None)
class TestAddCallbacks(TestCaseInTempDir):
def setUp(self):
from bzrlib.inventory import InventoryEntry
super(TestAddCallbacks, self).setUp()
self.entry = InventoryEntry("id", "name", "file", None)
def test_null_callback(self):
from bzrlib.add import _NullAddCallback
_NullAddCallback('path', 'file', self.entry)
def test_print_callback(self):
from bzrlib.add import _PrintAddCallback
from StringIO import StringIO
stdout = StringIO()
self.apply_redirected(None, stdout, None, _PrintAddCallback,
'path', 'file', self.entry)
self.assertEqual(stdout.getvalue(), "added path\n")
|