bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
1185.50.44
by John Arbash Meinel
[patch] Robey Pointer: diff -r 1.. should diff against working tree. |
1 |
# Copyright (C) 2005 by Canonical Ltd
|
2 |
# -*- coding: utf-8 -*-
|
|
3 |
||
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
||
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
||
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
||
18 |
||
19 |
"""Black-box tests for bzr diff.
|
|
20 |
"""
|
|
21 |
||
22 |
import os |
|
23 |
||
24 |
import bzrlib |
|
25 |
from bzrlib.branch import Branch |
|
26 |
from bzrlib.clone import copy_branch |
|
27 |
from bzrlib.tests.blackbox import ExternalBase |
|
28 |
||
29 |
||
30 |
class TestDiff(ExternalBase): |
|
31 |
def example_branch(test): |
|
32 |
# FIXME: copied from test_too_much -- share elsewhere?
|
|
33 |
test.runbzr('init') |
|
34 |
file('hello', 'wt').write('foo') |
|
35 |
test.runbzr('add hello') |
|
36 |
test.runbzr('commit -m setup hello') |
|
37 |
file('goodbye', 'wt').write('baz') |
|
38 |
test.runbzr('add goodbye') |
|
39 |
test.runbzr('commit -m setup goodbye') |
|
40 |
||
41 |
def test_diff(self): |
|
42 |
self.example_branch() |
|
43 |
file('hello', 'wt').write('hello world!') |
|
44 |
self.runbzr('commit -m fixing hello') |
|
45 |
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1) |
|
46 |
self.assert_('\n+hello world!' in output) |
|
47 |
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1) |
|
48 |
self.assert_('\n+baz' in output) |
|
49 |
file('moo', 'wb').write('moo') |
|
50 |
self.runbzr('add moo') |
|
51 |
os.unlink('moo') |
|
52 |
self.runbzr('diff') |
|
53 |
||
54 |
def test_diff_branches(self): |
|
55 |
self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary') |
|
56 |
branch = Branch.initialize('branch1') |
|
57 |
branch.working_tree().add(['file']) |
|
58 |
branch.working_tree().commit('add file') |
|
59 |
copy_branch(branch, 'branch2') |
|
60 |
print >> open('branch2/file', 'wb'), 'new content' |
|
61 |
branch2 = Branch.open('branch2') |
|
62 |
branch2.working_tree().commit('update file') |
|
63 |
# should open branch1 and diff against branch2,
|
|
64 |
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', |
|
65 |
'branch1'], |
|
66 |
retcode=1) |
|
67 |
self.assertEquals(("=== modified file 'file'\n" |
|
68 |
"--- file\t\n" |
|
69 |
"+++ file\t\n" |
|
70 |
"@@ -1,1 +1,1 @@\n" |
|
71 |
"-new content\n" |
|
72 |
"+contents of branch1/file\n" |
|
73 |
"\n", ''), output) |
|
74 |
output = self.run_bzr_captured(['diff', 'branch2', 'branch1'], |
|
75 |
retcode=1) |
|
76 |
self.assertEqualDiff(("=== modified file 'file'\n" |
|
77 |
"--- file\t\n" |
|
78 |
"+++ file\t\n" |
|
79 |
"@@ -1,1 +1,1 @@\n" |
|
80 |
"-new content\n" |
|
81 |
"+contents of branch1/file\n" |
|
82 |
"\n", ''), output) |
|
83 |
||
84 |
def test_diff_to_working_tree(self): |
|
85 |
self.build_tree(['branch1/', 'branch1/file1'], line_endings='binary') |
|
86 |
branch = Branch.initialize('branch1') |
|
87 |
branch.working_tree().add(['file1']) |
|
88 |
print >> open('branch1/file1', 'wb'), 'original line' |
|
89 |
branch.working_tree().commit('first commit') |
|
90 |
||
91 |
print >> open('branch1/file1', 'wb'), 'repo line' |
|
92 |
branch.working_tree().commit('second commit') |
|
93 |
||
94 |
print >> open('branch1/file1', 'wb'), 'new line' |
|
95 |
output = self.run_bzr_captured(['diff', '-r', '1..', 'branch1'], retcode=1) |
|
96 |
self.assertTrue('\n-original line\n+new line\n' in output[0]) |
|
97 |