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
160
|
import os
import unittest
from bzrlib.selftest import TestCaseInTempDir, TestCase
from bzrlib.branch import Branch
from bzrlib.errors import NotBranchError, NotVersionedError
from bzrlib.inventory import InventoryFile
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.initialize(".")
smart_add((".",), recurse=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.initialize(".")
os.chdir("original")
smart_add((".",), recurse=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.initialize("branch")
smart_add(("branch",))
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, add_reporter_null
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.initialize(".")
child_branch = Branch.initialize("original/child")
smart_add((".",), True, add_reporter_null)
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.initialize(".")
smart_add(paths)
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.initialize(".")
smart_add_branch(branch, (".",))
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.initialize(".")
os.chdir("original")
smart_add_branch(branch, (".",))
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.initialize("branch")
smart_add_branch(branch, ("branch",))
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.initialize(".")
child_branch = Branch.initialize("original/child")
smart_add_branch(branch, (".",))
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.initialize(".")
smart_add_branch(branch, paths)
for path in paths:
self.assertNotEqual(branch.inventory.path2id(path), None)
class TestAddCallbacks(TestCaseInTempDir):
def setUp(self):
super(TestAddCallbacks, self).setUp()
self.entry = InventoryFile("id", "name", None)
def test_null_callback(self):
from bzrlib.add import add_reporter_null
add_reporter_null('path', 'file', self.entry)
def test_print_callback(self):
from bzrlib.add import add_reporter_print
from StringIO import StringIO
stdout = StringIO()
self.apply_redirected(None, stdout, None, add_reporter_print,
'path', 'file', self.entry)
self.assertEqual(stdout.getvalue(), "added path\n")
|