~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_diff.py

  • Committer: Martin Pool
  • Date: 2007-10-02 02:54:30 UTC
  • mto: This revision was merged to the branch mainline in revision 2873.
  • Revision ID: mbp@sourcefrog.net-20071002025430-5qkc146iuaqxdsgk
Ignore .pyd files in bzr tree (windows C extensions)

Show diffs side-by-side

added added

removed removed

Lines of Context:
146
146
    def example_branches(self):
147
147
        branch1_tree = self.make_branch_and_tree('branch1')
148
148
        self.build_tree(['branch1/file'], line_endings='binary')
149
 
        self.build_tree(['branch1/file2'], line_endings='binary')
150
149
        branch1_tree.add('file')
151
 
        branch1_tree.add('file2')
152
 
        branch1_tree.commit(message='add file and file2')
 
150
        branch1_tree.commit(message='add file')
153
151
        branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
154
152
        self.build_tree_contents([('branch2/file', 'new content\n')])
155
153
        branch2_tree.commit(message='update file')
156
154
        return branch1_tree, branch2_tree
157
155
 
158
 
    def check_b2_vs_b1(self, cmd):
159
 
        # Compare branch2 vs branch1 using cmd and check the result
160
 
        out, err = self.run_bzr(cmd, retcode=1)
 
156
    def test_diff_branches(self):
 
157
        self.example_branches()
 
158
        # should open branch1 and diff against branch2, 
 
159
        out, err = self.run_bzr('diff -r branch:branch2 branch1',
 
160
                                retcode=1)
161
161
        self.assertEquals('', err)
162
162
        self.assertEquals("=== modified file 'file'\n"
163
163
                          "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
166
166
                          "-new content\n"
167
167
                          "+contents of branch1/file\n"
168
168
                          "\n", subst_dates(out))
169
 
 
170
 
    def check_b1_vs_b2(self, cmd):
171
 
        # Compare branch1 vs branch2 using cmd and check the result
172
 
        out, err = self.run_bzr(cmd, retcode=1)
 
169
        out, err = self.run_bzr('diff branch2 branch1',
 
170
                                         retcode=1)
173
171
        self.assertEquals('', err)
174
172
        self.assertEqualDiff("=== modified file 'file'\n"
175
173
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
176
174
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
177
175
                              "@@ -1,1 +1,1 @@\n"
178
 
                              "-contents of branch1/file\n"
179
 
                              "+new content\n"
 
176
                              "-new content\n"
 
177
                              "+contents of branch1/file\n"
180
178
                              "\n", subst_dates(out))
181
179
 
182
 
    def check_no_diffs(self, cmd):
183
 
        # Check that running cmd returns an empty diff
184
 
        out, err = self.run_bzr(cmd, retcode=0)
185
 
        self.assertEquals('', err)
186
 
        self.assertEquals('', out)
187
 
 
188
 
    def test_diff_branches(self):
189
 
        self.example_branches()
190
 
        # should open branch1 and diff against branch2, 
191
 
        self.check_b2_vs_b1('diff -r branch:branch2 branch1')
192
 
        # Compare two working trees using various syntax forms
193
 
        self.check_b2_vs_b1('diff --old branch2 --new branch1')
194
 
        self.check_b2_vs_b1('diff --old branch2 branch1')
195
 
        self.check_b2_vs_b1('diff branch2 --new branch1')
196
 
        # Test with a selected file that was changed
197
 
        self.check_b2_vs_b1('diff --old branch2 --new branch1 file')
198
 
        self.check_b2_vs_b1('diff --old branch2 branch1/file')
199
 
        self.check_b2_vs_b1('diff branch2/file --new branch1')
200
 
        # Test with a selected file that was not changed
201
 
        self.check_no_diffs('diff --old branch2 --new branch1 file2')
202
 
        self.check_no_diffs('diff --old branch2 branch1/file2')
203
 
        self.check_no_diffs('diff branch2/file2 --new branch1')
204
 
 
205
 
    def test_diff_branches_no_working_trees(self):
206
 
        branch1_tree, branch2_tree = self.example_branches()
207
 
        # Compare a working tree to a branch without a WT
208
 
        dir1 = branch1_tree.bzrdir
209
 
        dir1.destroy_workingtree()
210
 
        self.assertFalse(dir1.has_workingtree())
211
 
        self.check_b2_vs_b1('diff --old branch2 --new branch1')
212
 
        self.check_b2_vs_b1('diff --old branch2 branch1')
213
 
        self.check_b2_vs_b1('diff branch2 --new branch1')
214
 
        # Compare a branch without a WT to one with a WT
215
 
        self.check_b1_vs_b2('diff --old branch1 --new branch2')
216
 
        self.check_b1_vs_b2('diff --old branch1 branch2')
217
 
        self.check_b1_vs_b2('diff branch1 --new branch2')
218
 
        # Compare a branch with a WT against another without a WT
219
 
        dir2 = branch2_tree.bzrdir
220
 
        dir2.destroy_workingtree()
221
 
        self.assertFalse(dir2.has_workingtree())
222
 
        self.check_b1_vs_b2('diff --old branch1 --new branch2')
223
 
        self.check_b1_vs_b2('diff --old branch1 branch2')
224
 
        self.check_b1_vs_b2('diff branch1 --new branch2')
225
 
 
226
180
    def test_diff_revno_branches(self):
227
181
        self.example_branches()
228
182
        branch2_tree = workingtree.WorkingTree.open_containing('branch2')[0]
259
213
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
260
214
        self.assertContainsRe(output[0], '\n\\-original line\n\\+new line\n')
261
215
 
262
 
    def test_diff_to_working_tree_in_subdir(self):
263
 
        self.example_branch2()
264
 
        self.build_tree_contents([('branch1/file1', 'new line')])
265
 
        os.mkdir('branch1/dir1')
266
 
        os.chdir('branch1/dir1')
267
 
        output = self.run_bzr('diff -r 1..', retcode=1)
268
 
        self.assertContainsRe(output[0], '\n\\-original line\n\\+new line\n')
269
 
 
270
216
    def test_diff_across_rename(self):
271
217
        """The working tree path should always be considered for diffing"""
272
218
        tree = self.make_example_branch()
275
221
        self.run_bzr('diff hello1', retcode=1)
276
222
        self.run_bzr('diff -r 0..1 hello1', retcode=1)
277
223
 
278
 
    def test_diff_to_branch_no_working_tree(self):
279
 
        branch1_tree = self.example_branch2()
280
 
        dir1 = branch1_tree.bzrdir
281
 
        dir1.destroy_workingtree()
282
 
        self.assertFalse(dir1.has_workingtree())
283
 
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
284
 
        self.assertContainsRe(output[0], '\n\\-original line\n\\+repo line\n')
285
 
 
286
224
 
287
225
class TestCheckoutDiff(TestDiff):
288
226