51
51
self.runbzr('diff')
53
def test_diff_branches(self):
53
def test_diff_nonexistent(self):
54
# Get an error from a file that does not exist at all
56
self.make_example_branch()
57
out, err = self.runbzr('diff does-not-exist', retcode=3)
58
self.assertContainsRe(err, 'not versioned.*does-not-exist')
60
def test_diff_unversioned(self):
61
# Get an error when diffing a non-versioned file.
63
self.make_example_branch()
64
self.build_tree(['unversioned-file'])
65
out, err = self.runbzr('diff unversioned-file', retcode=3)
66
self.assertContainsRe(err, 'not versioned.*unversioned-file')
68
# TODO: What should diff say for a file deleted in working tree?
70
def example_branches(self):
54
71
self.build_tree(['branch1/', 'branch1/file'], line_endings='binary')
55
72
self.capture('init branch1')
56
73
self.capture('add branch1/file')
58
75
self.capture('branch branch1 branch2')
59
76
print >> open('branch2/file', 'wb'), 'new content'
60
77
self.run_bzr_captured(['commit', '-m', 'update file', 'branch2'])
79
def test_diff_branches(self):
80
self.example_branches()
61
81
# should open branch1 and diff against branch2,
62
82
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
65
self.assertEquals(("=== modified file 'file'\n"
85
self.assertEquals(("=== modified file 'a/file'\n"
68
88
"@@ -1,1 +1,1 @@\n"
70
90
"+contents of branch1/file\n"
72
92
output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
74
self.assertEqualDiff(("=== modified file 'file'\n"
94
self.assertEqualDiff(("=== modified file 'a/file'\n"
77
97
"@@ -1,1 +1,1 @@\n"
79
99
"+contents of branch1/file\n"
80
100
"\n", ''), output)
82
def test_diff_to_working_tree(self):
102
def example_branch2(self):
83
103
self.build_tree(['branch1/', 'branch1/file1'], line_endings='binary')
84
104
self.capture('init branch1')
85
105
self.capture('add branch1/file1')
89
109
print >> open('branch1/file1', 'wb'), 'repo line'
90
110
self.run_bzr_captured(['commit', '-m', 'second commit', 'branch1'])
112
def test_diff_to_working_tree(self):
113
self.example_branch2()
92
115
print >> open('branch1/file1', 'wb'), 'new line'
93
116
output = self.run_bzr_captured(['diff', '-r', '1..', 'branch1'], retcode=1)
94
117
self.assertTrue('\n-original line\n+new line\n' in output[0])
120
class TestCheckoutDiff(TestDiff):
122
def make_example_branch(self):
123
super(TestCheckoutDiff, self).make_example_branch()
124
self.runbzr('checkout . checkout')
127
def example_branch2(self):
128
super(TestCheckoutDiff, self).example_branch2()
129
os.mkdir('checkouts')
130
self.runbzr('checkout branch1 checkouts/branch1')
131
os.chdir('checkouts')
133
def example_branches(self):
134
super(TestCheckoutDiff, self).example_branches()
135
os.mkdir('checkouts')
136
self.runbzr('checkout branch1 checkouts/branch1')
137
self.runbzr('checkout branch2 checkouts/branch2')
138
os.chdir('checkouts')
141
class TestDiffLabels(TestDiff):
143
def test_diff_label_removed(self):
144
super(TestDiffLabels, self).make_example_branch()
145
self.runbzr('remove hello')
146
diff = self.run_bzr_captured(['diff'], retcode=1)
147
self.assertTrue("=== removed file 'a/hello'" in diff[0])
149
def test_diff_label_added(self):
150
super(TestDiffLabels, self).make_example_branch()
151
file('barbar', 'wt').write('barbar')
152
self.runbzr('add barbar')
153
diff = self.run_bzr_captured(['diff'], retcode=1)
154
self.assertTrue("=== added file 'b/barbar'" in diff[0])
156
def test_diff_label_modified(self):
157
super(TestDiffLabels, self).make_example_branch()
158
file('hello', 'wt').write('barbar')
159
diff = self.run_bzr_captured(['diff'], retcode=1)
160
self.assertTrue("=== modified file 'a/hello'" in diff[0])
162
def test_diff_label_renamed(self):
163
super(TestDiffLabels, self).make_example_branch()
164
self.runbzr('rename hello gruezi')
165
diff = self.run_bzr_captured(['diff'], retcode=1)
166
self.assertTrue("=== renamed file 'a/hello' => 'b/gruezi'" in diff[0])