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
18
from cStringIO import StringIO
19
from bzrlib.diff import internal_diff
20
from bzrlib.diff import internal_diff, show_diff_trees
20
21
from bzrlib.errors import BinaryFile
21
22
import bzrlib.patiencediff
23
from bzrlib.tests import TestCase, TestCaseWithTransport, TestCaseInTempDir
22
24
from bzrlib.tests import TestCase, TestCaseInTempDir
133
135
'internal_diff should return bytestrings')
138
class TestDiffDates(TestCaseWithTransport):
141
super(TestDiffDates, self).setUp()
142
self.wt = self.make_branch_and_tree('.')
143
self.b = self.wt.branch
144
self.build_tree_contents([
145
('file1', 'file1 contents at rev 1\n'),
146
('file2', 'file2 contents at rev 1\n')
148
self.wt.add(['file1', 'file2'])
150
message='Revision 1',
151
timestamp=1143849600, # 2006-04-01 00:00:00 UTC
154
self.build_tree_contents([('file1', 'file1 contents at rev 2\n')])
156
message='Revision 2',
157
timestamp=1143936000, # 2006-04-02 00:00:00 UTC
160
self.build_tree_contents([('file2', 'file2 contents at rev 3\n')])
162
message='Revision 3',
163
timestamp=1144022400, # 2006-04-03 00:00:00 UTC
166
self.wt.remove(['file2'])
168
message='Revision 4',
169
timestamp=1144108800, # 2006-04-04 00:00:00 UTC
172
self.build_tree_contents([
173
('file1', 'file1 contents in working tree\n')
175
# set the date stamps for files in the working tree to known values
176
os.utime('file1', (1144195200, 1144195200)) # 2006-04-05 00:00:00 UTC
178
def get_diff(self, tree1, tree2):
180
show_diff_trees(tree1, tree2, output,
181
old_label='old/', new_label='new/')
182
return output.getvalue()
184
def test_diff_rev_tree_working_tree(self):
185
output = self.get_diff(self.wt.basis_tree(), self.wt)
186
# note that the date for old/file1 is from rev 2 rather than from
187
# the basis revision (rev 4)
188
self.assertEqualDiff(output, '''\
189
=== modified file 'file1'
190
--- old/file1\t2006-04-02 00:00:00 +0000
191
+++ new/file1\t2006-04-05 00:00:00 +0000
193
-file1 contents at rev 2
194
+file1 contents in working tree
198
def test_diff_rev_tree_rev_tree(self):
199
tree1 = self.b.repository.revision_tree('rev-2')
200
tree2 = self.b.repository.revision_tree('rev-3')
201
output = self.get_diff(tree1, tree2)
202
self.assertEqualDiff(output, '''\
203
=== modified file 'file2'
204
--- old/file2\t2006-04-01 00:00:00 +0000
205
+++ new/file2\t2006-04-03 00:00:00 +0000
207
-file2 contents at rev 1
208
+file2 contents at rev 3
212
def test_diff_add_files(self):
213
tree1 = self.b.repository.revision_tree(None)
214
tree2 = self.b.repository.revision_tree('rev-1')
215
output = self.get_diff(tree1, tree2)
216
# the files have the epoch time stamp for the tree in which
218
self.assertEqualDiff(output, '''\
219
=== added file 'file1'
220
--- old/file1\t1970-01-01 00:00:00 +0000
221
+++ new/file1\t2006-04-01 00:00:00 +0000
223
+file1 contents at rev 1
225
=== added file 'file2'
226
--- old/file2\t1970-01-01 00:00:00 +0000
227
+++ new/file2\t2006-04-01 00:00:00 +0000
229
+file2 contents at rev 1
233
def test_diff_remove_files(self):
234
tree1 = self.b.repository.revision_tree('rev-3')
235
tree2 = self.b.repository.revision_tree('rev-4')
236
output = self.get_diff(tree1, tree2)
237
# the file has the epoch time stamp for the tree in which
239
self.assertEqualDiff(output, '''\
240
=== removed file 'file2'
241
--- old/file2\t2006-04-03 00:00:00 +0000
242
+++ new/file2\t1970-01-01 00:00:00 +0000
244
-file2 contents at rev 3
136
249
class TestPatienceDiffLib(TestCase):
138
251
def test_unique_lcs(self):