14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
from cStringIO import StringIO
20
from bzrlib.branch import Branch
21
from bzrlib.diff import internal_diff
22
from bzrlib.inventory import Inventory, InventoryEntry, ROOT_ID
23
from bzrlib.osutils import has_symlinks
18
24
from bzrlib.selftest import TestCase, TestCaseInTempDir
20
from bzrlib.inventory import Inventory, InventoryEntry, ROOT_ID
23
27
class TestInventory(TestCase):
112
116
left.symlink_target = 'different'
113
117
self.assertEqual((True, False), left.detect_changes(right))
114
118
self.assertEqual((True, False), right.detect_changes(left))
121
class TestEntryDiffing(TestCaseInTempDir):
124
super(TestEntryDiffing, self).setUp()
125
self.branch = Branch.initialize('.')
126
print >> open('file', 'wb'), 'foo'
127
self.branch.add(['file'], ['fileid'])
129
os.symlink('target1', 'symlink')
130
self.branch.add(['symlink'], ['linkid'])
131
self.branch.commit('message_1', rev_id = '1')
132
print >> open('file', 'wb'), 'bar'
135
os.symlink('target2', 'symlink')
136
self.tree_1 = self.branch.revision_tree('1')
137
self.inv_1 = self.branch.get_inventory('1')
138
self.file_1 = self.inv_1['fileid']
139
self.tree_2 = self.branch.working_tree()
140
self.inv_2 = self.branch.inventory
141
self.file_2 = self.inv_2['fileid']
143
self.link_1 = self.inv_1['linkid']
144
self.link_2 = self.inv_2['linkid']
146
def test_file_diff_deleted(self):
148
self.file_1.diff(internal_diff,
149
"old_label", self.tree_1,
150
"/dev/null", None, None,
152
self.assertEqual(output.getvalue(), "--- old_label\n"
158
def test_file_diff_added(self):
160
self.file_1.diff(internal_diff,
161
"new_label", self.tree_1,
162
"/dev/null", None, None,
163
output, reverse=True)
164
self.assertEqual(output.getvalue(), "--- /dev/null\n"
170
def test_file_diff_changed(self):
172
self.file_1.diff(internal_diff,
173
"/dev/null", self.tree_1,
174
"new_label", self.file_2, self.tree_2,
176
self.assertEqual(output.getvalue(), "--- /dev/null\n"
183
def test_link_diff_deleted(self):
185
self.link_1.diff(internal_diff,
186
"old_label", self.tree_1,
187
"/dev/null", None, None,
189
self.assertEqual(output.getvalue(),
190
"=== target was 'target1'\n")
192
def test_link_diff_added(self):
194
self.link_1.diff(internal_diff,
195
"new_label", self.tree_1,
196
"/dev/null", None, None,
197
output, reverse=True)
198
self.assertEqual(output.getvalue(),
199
"=== target is 'target1'\n")
201
def test_link_diff_changed(self):
203
self.link_1.diff(internal_diff,
204
"/dev/null", self.tree_1,
205
"new_label", self.link_2, self.tree_2,
207
self.assertEqual(output.getvalue(),
208
"=== target changed 'target1' => 'target2'\n")