/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
622.1.2 by John Arbash Meinel
Add tests of RevisionView that it can handle broken file-info properties.
1
# Copyright (C) 2007, 2008 John Arbash Meinel <john@arbash-meinel.com>
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Test the Commit functionality."""
18
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
19
import os
20
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
21
from gi.repository import Gtk
278.1.23 by John Arbash Meinel
Beginning to support actual commit.
22
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
23
from bzrlib import (
635.2.12 by Vincent Ladeuil
Implement commit message saving without modifying bzrlib.
24
    branch,
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
25
    tests,
635.2.8 by Vincent Ladeuil
Start testing patch behavior.
26
    uncommit,
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
27
    )
645 by Jelmer Vernooij
Fix more bencode imports.
28
try:
646 by Jelmer Vernooij
Reorder bencode imports, prefer the new location to prevent deprecation warnings.
29
    from bzrlib import bencode
30
except ImportError:
645 by Jelmer Vernooij
Fix more bencode imports.
31
    from bzrlib.util import bencode
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
32
33
from bzrlib.plugins.gtk import commit
34
35
36
# TODO: All we need is basic ancestry code to test this, we shouldn't need a
37
# TestCaseWithTransport, just a TestCaseWithMemoryTransport or somesuch.
38
39
class TestPendingRevisions(tests.TestCaseWithTransport):
40
41
    def test_pending_revisions_none(self):
42
        tree = self.make_branch_and_tree('.')
43
        tree.commit('one')
44
45
        self.assertIs(None, commit.pending_revisions(tree))
46
47
    def test_pending_revisions_simple(self):
48
        tree = self.make_branch_and_tree('tree')
49
        rev_id1 = tree.commit('one')
50
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
51
        rev_id2 = tree2.commit('two')
52
        tree.merge_from_branch(tree2.branch)
53
        self.assertEqual([rev_id1, rev_id2], tree.get_parent_ids())
54
55
        pending_revisions = commit.pending_revisions(tree)
56
        # One primary merge
57
        self.assertEqual(1, len(pending_revisions))
58
        # Revision == rev_id2
59
        self.assertEqual(rev_id2, pending_revisions[0][0].revision_id)
60
        # No children of this revision.
61
        self.assertEqual([], pending_revisions[0][1])
62
63
    def test_pending_revisions_with_children(self):
64
        tree = self.make_branch_and_tree('tree')
65
        rev_id1 = tree.commit('one')
66
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
67
        rev_id2 = tree2.commit('two')
68
        rev_id3 = tree2.commit('three')
69
        rev_id4 = tree2.commit('four')
70
        tree.merge_from_branch(tree2.branch)
71
        self.assertEqual([rev_id1, rev_id4], tree.get_parent_ids())
72
73
        pending_revisions = commit.pending_revisions(tree)
74
        # One primary merge
75
        self.assertEqual(1, len(pending_revisions))
76
        # Revision == rev_id2
77
        self.assertEqual(rev_id4, pending_revisions[0][0].revision_id)
78
        # Two children for this revision
79
        self.assertEqual(2, len(pending_revisions[0][1]))
80
        self.assertEqual(rev_id3, pending_revisions[0][1][0].revision_id)
81
        self.assertEqual(rev_id2, pending_revisions[0][1][1].revision_id)
82
83
    def test_pending_revisions_multi_merge(self):
84
        tree = self.make_branch_and_tree('tree')
85
        rev_id1 = tree.commit('one')
86
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
87
        rev_id2 = tree2.commit('two')
88
        tree3 = tree2.bzrdir.sprout('tree3').open_workingtree()
500.1.2 by Vincent Ladeuil
Fix third failing test (thanks to jam).
89
        rev_id3 = tree2.commit('three')
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
90
        rev_id4 = tree3.commit('four')
91
        rev_id5 = tree3.commit('five')
92
        tree.merge_from_branch(tree2.branch)
670 by Vincent Ladeuil
Fix regressions in tests about merge being more strict by default.
93
        tree.merge_from_branch(tree3.branch, force=True)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
94
        self.assertEqual([rev_id1, rev_id3, rev_id5], tree.get_parent_ids())
95
96
        pending_revisions = commit.pending_revisions(tree)
97
        # Two primary merges
98
        self.assertEqual(2, len(pending_revisions))
99
        # Revision == rev_id2
100
        self.assertEqual(rev_id3, pending_revisions[0][0].revision_id)
101
        self.assertEqual(rev_id5, pending_revisions[1][0].revision_id)
102
        # One child for the first merge
103
        self.assertEqual(1, len(pending_revisions[0][1]))
104
        self.assertEqual(rev_id2, pending_revisions[0][1][0].revision_id)
105
        # One child for the second merge
106
        self.assertEqual(1, len(pending_revisions[1][1]))
107
        self.assertEqual(rev_id4, pending_revisions[1][1][0].revision_id)
108
109
110
class Test_RevToPendingInfo(tests.TestCaseWithTransport):
111
112
    def test_basic_info(self):
113
        tree = self.make_branch_and_tree('tree')
114
        rev_id = tree.commit('Multiline\ncommit\nmessage',
115
                             committer='Joe Foo <joe@foo.com>',
116
                             timestamp=1191012408.674,
117
                             timezone=-18000
118
                             )
119
        rev = tree.branch.repository.get_revision(rev_id)
120
        rev_dict = commit.CommitDialog._rev_to_pending_info(rev)
121
        self.assertEqual({'committer':'Joe Foo',
122
                          'summary':'Multiline',
123
                          'date':'2007-09-28',
124
                          'revision_id':rev_id,
125
                         }, rev_dict)
126
127
128
class CommitDialogNoWidgets(commit.CommitDialog):
129
130
    def construct(self):
131
        pass # Don't create any widgets here
132
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
133
    def fill_in_data(self):
134
        pass # With no widgets, there are no widgets to fill out
135
136
137
class TestCommitDialogSimple(tests.TestCaseWithTransport):
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
138
139
    def test_setup_parameters_no_pending(self):
140
        tree = self.make_branch_and_tree('tree')
141
        rev_id = tree.commit('first')
142
143
        dlg = CommitDialogNoWidgets(tree)
144
        self.assertEqual(rev_id, dlg._basis_tree.get_revision_id())
145
        self.assertIs(None, dlg._pending)
146
        self.assertFalse(dlg._is_checkout)
147
148
    def test_setup_parameters_checkout(self):
149
        tree = self.make_branch_and_tree('tree')
150
        rev_id = tree.commit('first')
151
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
152
        tree2.branch.bind(tree.branch)
153
154
        dlg = CommitDialogNoWidgets(tree2)
155
        self.assertEqual(rev_id, dlg._basis_tree.get_revision_id())
156
        self.assertIs(None, dlg._pending)
157
        self.assertTrue(dlg._is_checkout)
158
159
    def test_setup_parameters_pending(self):
160
        tree = self.make_branch_and_tree('tree')
161
        rev_id1 = tree.commit('one')
162
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
163
        rev_id2 = tree2.commit('two')
164
        tree.merge_from_branch(tree2.branch)
165
166
        dlg = CommitDialogNoWidgets(tree)
167
        self.assertEqual(rev_id1, dlg._basis_tree.get_revision_id())
168
        self.assertIsNot(None, dlg._pending)
169
        self.assertEqual(1, len(dlg._pending))
170
        self.assertEqual(rev_id2, dlg._pending[0][0].revision_id)
171
172
    def test_setup_parameters_delta(self):
173
        tree = self.make_branch_and_tree('tree')
174
        self.build_tree(['tree/a'])
175
        tree.add(['a'], ['a-id'])
176
177
        dlg = CommitDialogNoWidgets(tree)
278.1.12 by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names.
178
        self.assertIs(None, dlg._delta)
179
        dlg._compute_delta()
180
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
181
        delta = dlg._delta
182
        self.assertEqual([], delta.modified)
183
        self.assertEqual([], delta.renamed)
184
        self.assertEqual([], delta.removed)
185
        self.assertEqual([(u'a', 'a-id', 'file')], delta.added)
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
186
187
188
class TestCommitDialog(tests.TestCaseWithTransport):
189
278.1.25 by John Arbash Meinel
Add the 'Only Commit Locally' checkbox, we may want to put it elsewhere, though.
190
    def test_bound(self):
191
        tree = self.make_branch_and_tree('tree')
192
        rev_id = tree.commit('first')
193
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
194
        tree2.branch.bind(tree.branch)
195
196
        # tree is not a checkout
197
        dlg = commit.CommitDialog(tree)
198
        self.assertFalse(dlg._check_local.get_property('visible'))
199
200
        # tree2 is a checkout
201
        dlg2 = commit.CommitDialog(tree2)
202
        self.assertTrue(dlg2._check_local.get_property('visible'))
203
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
204
    def test_no_pending(self):
205
        tree = self.make_branch_and_tree('tree')
206
        rev_id1 = tree.commit('one')
207
208
        dlg = commit.CommitDialog(tree)
278.1.25 by John Arbash Meinel
Add the 'Only Commit Locally' checkbox, we may want to put it elsewhere, though.
209
210
        self.assertFalse(dlg._pending_box.get_property('visible'))
211
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
212
        commit_col = dlg._treeview_files.get_column(0)
213
        self.assertEqual('Commit', commit_col.get_title())
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
214
        renderer = commit_col.get_cell_renderers()[0]
278.1.39 by John Arbash Meinel
To disable a checkbox it is set_property('activatable', False),
215
        self.assertTrue(renderer.get_property('activatable'))
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
216
278.1.43 by John Arbash Meinel
Finish connecting the 'Commit all changes' radio buttons.
217
        self.assertEqual('Commit all changes',
218
                         dlg._commit_all_files_radio.get_label())
219
        self.assertTrue(dlg._commit_all_files_radio.get_property('sensitive'))
220
        self.assertTrue(dlg._commit_selected_radio.get_property('sensitive'))
221
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
222
    def test_pending(self):
223
        tree = self.make_branch_and_tree('tree')
224
        rev_id1 = tree.commit('one')
225
226
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
227
        rev_id2 = tree2.commit('two',
228
                               committer='Joe Foo <joe@foo.com>',
229
                               timestamp=1191264271.05,
230
                               timezone=+7200)
231
        tree.merge_from_branch(tree2.branch)
232
233
        dlg = commit.CommitDialog(tree)
278.1.25 by John Arbash Meinel
Add the 'Only Commit Locally' checkbox, we may want to put it elsewhere, though.
234
235
        self.assertTrue(dlg._pending_box.get_property('visible'))
236
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
237
        commit_col = dlg._treeview_files.get_column(0)
238
        self.assertEqual('Commit*', commit_col.get_title())
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
239
        renderer = commit_col.get_cell_renderers()[0]
278.1.39 by John Arbash Meinel
To disable a checkbox it is set_property('activatable', False),
240
        self.assertFalse(renderer.get_property('activatable'))
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
241
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
242
        values = [(r[0], r[1], r[2], r[3]) for r in dlg._pending_store]
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
243
        self.assertEqual([(rev_id2, '2007-10-01', 'Joe Foo', 'two')], values)
244
278.1.43 by John Arbash Meinel
Finish connecting the 'Commit all changes' radio buttons.
245
        self.assertEqual('Commit all changes*',
246
                         dlg._commit_all_files_radio.get_label())
247
        self.assertFalse(dlg._commit_all_files_radio.get_property('sensitive'))
248
        self.assertFalse(dlg._commit_selected_radio.get_property('sensitive'))
249
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
250
    def test_pending_multiple(self):
251
        tree = self.make_branch_and_tree('tree')
252
        rev_id1 = tree.commit('one')
253
254
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
255
        rev_id2 = tree2.commit('two',
256
                               committer='Joe Foo <joe@foo.com>',
257
                               timestamp=1191264271.05,
258
                               timezone=+7200)
259
        rev_id3 = tree2.commit('three',
260
                               committer='Jerry Foo <jerry@foo.com>',
261
                               timestamp=1191264278.05,
262
                               timezone=+7200)
263
        tree.merge_from_branch(tree2.branch)
264
        tree3 = tree.bzrdir.sprout('tree3').open_workingtree()
265
        rev_id4 = tree3.commit('four',
266
                               committer='Joe Foo <joe@foo.com>',
267
                               timestamp=1191264279.05,
268
                               timezone=+7200)
269
        rev_id5 = tree3.commit('five',
270
                               committer='Jerry Foo <jerry@foo.com>',
271
                               timestamp=1191372278.05,
272
                               timezone=+7200)
670 by Vincent Ladeuil
Fix regressions in tests about merge being more strict by default.
273
        tree.merge_from_branch(tree3.branch, force=True)
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
274
275
        dlg = commit.CommitDialog(tree)
276
        # TODO: assert that the pending box is set to show
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
277
        values = [(r[0], r[1], r[2], r[3]) for r in dlg._pending_store]
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
278
        self.assertEqual([(rev_id3, '2007-10-01', 'Jerry Foo', 'three'),
279
                          (rev_id2, '2007-10-01', 'Joe Foo', 'two'),
280
                          (rev_id5, '2007-10-03', 'Jerry Foo', 'five'),
281
                          (rev_id4, '2007-10-01', 'Joe Foo', 'four'),
282
                         ], values)
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
283
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
284
    def test_filelist_added(self):
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
285
        tree = self.make_branch_and_tree('tree')
286
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
287
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
288
289
        dlg = commit.CommitDialog(tree)
290
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
291
        self.assertEqual([(None, None, True, 'All Files', ''),
292
                          ('a-id', 'a', True, 'a', 'added'),
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
293
                          ('b-id', 'b', True, 'b/', 'added'),
294
                          ('c-id', 'b/c', True, 'b/c', 'added'),
295
                         ], values)
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
296
297
    def test_filelist_renamed(self):
298
        tree = self.make_branch_and_tree('tree')
299
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
300
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
301
        rev_id1 = tree.commit('one')
302
303
        tree.rename_one('b', 'd')
304
        tree.rename_one('a', 'd/a')
305
306
        dlg = commit.CommitDialog(tree)
307
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
308
        self.assertEqual([(None, None, True, 'All Files', ''),
309
                          ('b-id', 'd', True, 'b/ => d/', 'renamed'),
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
310
                          ('a-id', 'd/a', True, 'a => d/a', 'renamed'),
311
                         ], values)
312
313
    def test_filelist_modified(self):
314
        tree = self.make_branch_and_tree('tree')
315
        self.build_tree(['tree/a'])
316
        tree.add(['a'], ['a-id'])
317
        rev_id1 = tree.commit('one')
318
319
        self.build_tree_contents([('tree/a', 'new contents for a\n')])
320
321
        dlg = commit.CommitDialog(tree)
322
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
323
        self.assertEqual([(None, None, True, 'All Files', ''),
324
                          ('a-id', 'a', True, 'a', 'modified'),
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
325
                         ], values)
326
327
    def test_filelist_renamed_and_modified(self):
328
        tree = self.make_branch_and_tree('tree')
329
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
330
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
331
        rev_id1 = tree.commit('one')
332
333
        tree.rename_one('b', 'd')
334
        tree.rename_one('a', 'd/a')
335
        self.build_tree_contents([('tree/d/a', 'new contents for a\n'),
336
                                  ('tree/d/c', 'new contents for c\n'),
337
                                 ])
338
        # 'c' is not considered renamed, because only its parent was moved, it
339
        # stayed in the same directory
340
341
        dlg = commit.CommitDialog(tree)
342
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
343
        self.assertEqual([(None, None, True, 'All Files', ''),
344
                          ('b-id', 'd', True, 'b/ => d/', 'renamed'),
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
345
                          ('a-id', 'd/a', True, 'a => d/a', 'renamed and modified'),
346
                          ('c-id', 'd/c', True, 'd/c', 'modified'),
347
                         ], values)
348
349
    def test_filelist_kind_changed(self):
350
        tree = self.make_branch_and_tree('tree')
351
        self.build_tree(['tree/a', 'tree/b'])
352
        tree.add(['a', 'b'], ['a-id', 'b-id'])
353
        tree.commit('one')
354
355
        os.remove('tree/a')
356
        self.build_tree(['tree/a/'])
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
357
        # XXX:  This is technically valid, and the file list handles it fine,
358
        #       but 'show_diff_trees()' does not, so we skip this part of the
359
        #       test for now.
360
        # tree.rename_one('b', 'c')
361
        # os.remove('tree/c')
362
        # self.build_tree(['tree/c/'])
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
363
364
        dlg = commit.CommitDialog(tree)
365
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
366
        self.assertEqual([(None, None, True, 'All Files', ''),
367
                          ('a-id', 'a', True, 'a => a/', 'kind changed'),
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
368
                          # ('b-id', 'c', True, 'b => c/', 'renamed and modified'),
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
369
                         ], values)
370
371
    def test_filelist_removed(self):
372
        tree = self.make_branch_and_tree('tree')
373
        self.build_tree(['tree/a', 'tree/b/'])
374
        tree.add(['a', 'b'], ['a-id', 'b-id'])
375
        tree.commit('one')
376
377
        os.remove('tree/a')
378
        tree.remove('b', force=True)
379
380
        dlg = commit.CommitDialog(tree)
381
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
382
        self.assertEqual([(None, None, True, 'All Files', ''),
383
                          ('a-id', 'a', True, 'a', 'removed'),
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
384
                          ('b-id', 'b', True, 'b/', 'removed'),
385
                         ], values)
278.1.35 by John Arbash Meinel
Make use of the 'selected' parameter to CommitDialog.
386
        # All Files should be selected
387
        self.assertEqual(((0,), None), dlg._treeview_files.get_cursor())
388
389
    def test_filelist_with_selected(self):
390
        tree = self.make_branch_and_tree('tree')
391
        self.build_tree(['tree/a', 'tree/b/'])
392
        tree.add(['a', 'b'], ['a-id', 'b-id'])
393
394
        dlg = commit.CommitDialog(tree, selected='a')
395
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
396
        self.assertEqual([(None, None, False, 'All Files', ''),
397
                          ('a-id', 'a', True, 'a', 'added'),
398
                          ('b-id', 'b', False, 'b/', 'added'),
399
                         ], values)
400
        # This file should also be selected in the file list, rather than the
401
        # 'All Files' selection
402
        self.assertEqual(((1,), None), dlg._treeview_files.get_cursor())
278.1.18 by John Arbash Meinel
Start checking the diff view is correct.
403
404
    def test_diff_view(self):
405
        tree = self.make_branch_and_tree('tree')
406
        self.build_tree(['tree/a', 'tree/b'])
407
        tree.add(['a', 'b'], ['a-id', 'b-id'])
408
        tree.commit('one')
409
410
        self.build_tree_contents([('tree/a', 'new contents for a\n')])
411
        tree.remove('b')
412
413
        dlg = commit.CommitDialog(tree)
414
        diff_buffer = dlg._diff_view.buffer
415
        text = diff_buffer.get_text(diff_buffer.get_start_iter(),
734.1.7 by Curtis Hovey
Updated buffer.getText() calls and ModifierType enums.
416
                                    diff_buffer.get_end_iter(),
417
                                    True).splitlines(True)
278.1.18 by John Arbash Meinel
Start checking the diff view is correct.
418
483 by Jelmer Vernooij
Fix diff test.
419
        self.assertEqual("=== modified file 'a'\n", text[0])
278.1.18 by John Arbash Meinel
Start checking the diff view is correct.
420
        self.assertContainsRe(text[1],
421
            r"--- a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
483 by Jelmer Vernooij
Fix diff test.
422
        self.assertContainsRe(text[2],
423
            r"\+\+\+ a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
424
        self.assertEqual('@@ -1,1 +1,1 @@\n', text[3])
425
        self.assertEqual('-contents of tree/a\n', text[4])
426
        self.assertEqual('+new contents for a\n', text[5])
427
        self.assertEqual('\n', text[6])
428
429
        self.assertEqual("=== removed file 'b'\n", text[7])
278.1.18 by John Arbash Meinel
Start checking the diff view is correct.
430
        self.assertContainsRe(text[8],
483 by Jelmer Vernooij
Fix diff test.
431
            r"--- b\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
432
        self.assertEqual('+++ b\t1970-01-01 00:00:00 +0000\n', text[9])
433
        self.assertEqual('@@ -1,1 +0,0 @@\n', text[10])
434
        self.assertEqual('-contents of tree/b\n', text[11])
278.1.18 by John Arbash Meinel
Start checking the diff view is correct.
435
        self.assertEqual('\n', text[12])
436
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
437
        self.assertEqual('Diff for All Files', dlg._diff_label.get_text())
278.1.19 by John Arbash Meinel
Test what happens when a specific file is selected.
438
278.1.43 by John Arbash Meinel
Finish connecting the 'Commit all changes' radio buttons.
439
    def test_commit_partial_toggle(self):
440
        tree = self.make_branch_and_tree('tree')
441
        self.build_tree(['tree/a', 'tree/b'])
442
        tree.add(['a', 'b'], ['a-id', 'b-id'])
443
444
        dlg = commit.CommitDialog(tree)
445
        checked_col = dlg._treeview_files.get_column(0)
446
        self.assertFalse(checked_col.get_property('visible'))
447
        self.assertTrue(dlg._commit_all_changes)
448
449
        dlg._commit_selected_radio.set_active(True)
450
        self.assertTrue(checked_col.get_property('visible'))
451
        self.assertFalse(dlg._commit_all_changes)
452
278.1.19 by John Arbash Meinel
Test what happens when a specific file is selected.
453
    def test_file_selection(self):
454
        """Several things should happen when a file has been selected."""
455
        tree = self.make_branch_and_tree('tree')
278.1.33 by John Arbash Meinel
Only enable the per-file dialog if 'per_file_commits' is enabled in the config.
456
        tree.branch.get_config().set_user_option('per_file_commits', 'true')
278.1.19 by John Arbash Meinel
Test what happens when a specific file is selected.
457
        self.build_tree(['tree/a', 'tree/b'])
458
        tree.add(['a', 'b'], ['a-id', 'b-id'])
459
460
        dlg = commit.CommitDialog(tree)
461
        diff_buffer = dlg._diff_view.buffer
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
462
        self.assertEqual('Diff for All Files', dlg._diff_label.get_text())
278.1.21 by John Arbash Meinel
Start tracking the per-file commit messages.
463
        self.assertEqual('File commit message',
464
                         dlg._file_message_expander.get_label())
465
        self.assertFalse(dlg._file_message_expander.get_expanded())
466
        self.assertFalse(dlg._file_message_expander.get_property('sensitive'))
278.1.19 by John Arbash Meinel
Test what happens when a specific file is selected.
467
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
468
        dlg._treeview_files.set_cursor((1,))
278.1.19 by John Arbash Meinel
Test what happens when a specific file is selected.
469
        self.assertEqual('Diff for a', dlg._diff_label.get_text())
470
        text = diff_buffer.get_text(diff_buffer.get_start_iter(),
734.1.7 by Curtis Hovey
Updated buffer.getText() calls and ModifierType enums.
471
                                    diff_buffer.get_end_iter(),
472
                                    True).splitlines(True)
278.1.19 by John Arbash Meinel
Test what happens when a specific file is selected.
473
        self.assertEqual("=== added file 'a'\n", text[0])
474
        self.assertContainsRe(text[1],
475
            r"--- a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
476
        self.assertContainsRe(text[2],
477
            r"\+\+\+ a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
478
        self.assertEqual('@@ -0,0 +1,1 @@\n', text[3])
479
        self.assertEqual('+contents of tree/a\n', text[4])
480
        self.assertEqual('\n', text[5])
278.1.21 by John Arbash Meinel
Start tracking the per-file commit messages.
481
        self.assertEqual('Commit message for a',
482
                         dlg._file_message_expander.get_label())
483
        self.assertTrue(dlg._file_message_expander.get_expanded())
484
        self.assertTrue(dlg._file_message_expander.get_property('sensitive'))
278.1.19 by John Arbash Meinel
Test what happens when a specific file is selected.
485
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
486
        dlg._treeview_files.set_cursor((2,))
278.1.19 by John Arbash Meinel
Test what happens when a specific file is selected.
487
        self.assertEqual('Diff for b', dlg._diff_label.get_text())
488
        text = diff_buffer.get_text(diff_buffer.get_start_iter(),
734.1.7 by Curtis Hovey
Updated buffer.getText() calls and ModifierType enums.
489
                                    diff_buffer.get_end_iter(),
490
                                    True).splitlines(True)
278.1.19 by John Arbash Meinel
Test what happens when a specific file is selected.
491
        self.assertEqual("=== added file 'b'\n", text[0])
492
        self.assertContainsRe(text[1],
493
            r"--- b\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
494
        self.assertContainsRe(text[2],
495
            r"\+\+\+ b\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
496
        self.assertEqual('@@ -0,0 +1,1 @@\n', text[3])
497
        self.assertEqual('+contents of tree/b\n', text[4])
498
        self.assertEqual('\n', text[5])
278.1.21 by John Arbash Meinel
Start tracking the per-file commit messages.
499
        self.assertEqual('Commit message for b',
500
                         dlg._file_message_expander.get_label())
501
        self.assertTrue(dlg._file_message_expander.get_expanded())
502
        self.assertTrue(dlg._file_message_expander.get_property('sensitive'))
503
504
        dlg._treeview_files.set_cursor((0,))
505
        self.assertEqual('Diff for All Files', dlg._diff_label.get_text())
506
        self.assertEqual('File commit message',
507
                         dlg._file_message_expander.get_label())
508
        self.assertFalse(dlg._file_message_expander.get_expanded())
509
        self.assertFalse(dlg._file_message_expander.get_property('sensitive'))
510
511
    def test_file_selection_message(self):
512
        """Selecting a file should bring up its commit message."""
513
        tree = self.make_branch_and_tree('tree')
278.1.33 by John Arbash Meinel
Only enable the per-file dialog if 'per_file_commits' is enabled in the config.
514
        tree.branch.get_config().set_user_option('per_file_commits', 'true')
278.1.21 by John Arbash Meinel
Start tracking the per-file commit messages.
515
        self.build_tree(['tree/a', 'tree/b/'])
516
        tree.add(['a', 'b'], ['a-id', 'b-id'])
517
518
        def get_file_text():
519
            buf = dlg._file_message_text_view.get_buffer()
734.1.7 by Curtis Hovey
Updated buffer.getText() calls and ModifierType enums.
520
            return buf.get_text(
521
                buf.get_start_iter(), buf.get_end_iter(), True)
278.1.21 by John Arbash Meinel
Start tracking the per-file commit messages.
522
523
        def get_saved_text(path):
524
            """Get the saved text for a given record."""
525
            return dlg._files_store.get_value(dlg._files_store.get_iter(path), 5)
526
527
        dlg = commit.CommitDialog(tree)
528
        self.assertEqual('File commit message',
529
                         dlg._file_message_expander.get_label())
530
        self.assertFalse(dlg._file_message_expander.get_expanded())
531
        self.assertFalse(dlg._file_message_expander.get_property('sensitive'))
532
        self.assertEqual('', get_file_text())
533
534
        dlg._treeview_files.set_cursor((1,))
535
        self.assertEqual('Commit message for a',
536
                         dlg._file_message_expander.get_label())
537
        self.assertTrue(dlg._file_message_expander.get_expanded())
538
        self.assertTrue(dlg._file_message_expander.get_property('sensitive'))
539
        self.assertEqual('', get_file_text())
540
541
        self.assertEqual('', get_saved_text(1))
278.1.27 by John Arbash Meinel
Add the ability to commit just specific files.
542
        dlg._set_file_commit_message('Some text\nfor a\n')
278.1.21 by John Arbash Meinel
Start tracking the per-file commit messages.
543
        dlg._save_current_file_message()
544
        # We should have updated the ListStore with the new file commit info
545
        self.assertEqual('Some text\nfor a\n', get_saved_text(1))
546
547
        dlg._treeview_files.set_cursor((2,))
548
        self.assertEqual('Commit message for b/',
549
                         dlg._file_message_expander.get_label())
550
        self.assertTrue(dlg._file_message_expander.get_expanded())
551
        self.assertTrue(dlg._file_message_expander.get_property('sensitive'))
552
        self.assertEqual('', get_file_text())
553
554
        self.assertEqual('', get_saved_text(2))
278.1.27 by John Arbash Meinel
Add the ability to commit just specific files.
555
        dlg._set_file_commit_message('More text\nfor b\n')
278.1.21 by John Arbash Meinel
Start tracking the per-file commit messages.
556
        # Now switch back to 'a'. The message should be saved, and the buffer
557
        # should be updated with the other text
558
        dlg._treeview_files.set_cursor((1,))
559
        self.assertEqual('More text\nfor b\n', get_saved_text(2))
560
        self.assertEqual('Commit message for a',
561
                         dlg._file_message_expander.get_label())
562
        self.assertTrue(dlg._file_message_expander.get_expanded())
563
        self.assertTrue(dlg._file_message_expander.get_property('sensitive'))
564
        self.assertEqual('Some text\nfor a\n', get_file_text())
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
565
566
    def test_toggle_all_files(self):
567
        """When checking the All Files entry, it should toggle all fields"""
568
        tree = self.make_branch_and_tree('tree')
569
        self.build_tree(['tree/a', 'tree/b/'])
570
        tree.add(['a', 'b'], ['a-id', 'b-id'])
571
572
        dlg = commit.CommitDialog(tree)
573
        self.assertEqual([(None, None, True),
574
                          ('a-id', 'a', True),
575
                          ('b-id', 'b', True),
576
                         ], [(r[0], r[1], r[2]) for r in dlg._files_store])
577
578
        # TODO: jam 20071002 I'm not sure how to exactly trigger a toggle, it
579
        #       looks like we need to call renderer.activate() and pass an
580
        #       event and widget, and lots of other stuff I'm not sure what to
581
        #       do with. So instead, we just call toggle directly, and assume
582
        #       that toggle is hooked in correctly
583
        # column = dlg._treeview_files.get_column(0)
584
        # renderer = column.get_cell_renderers()[0]
585
586
        # Toggle a single entry should set just that entry to False
587
        dlg._toggle_commit(None, 1, dlg._files_store)
588
        self.assertEqual([(None, None, True),
589
                          ('a-id', 'a', False),
590
                          ('b-id', 'b', True),
591
                         ], [(r[0], r[1], r[2]) for r in dlg._files_store])
592
593
        # Toggling the main entry should set all entries
594
        dlg._toggle_commit(None, 0, dlg._files_store)
595
        self.assertEqual([(None, None, False),
596
                          ('a-id', 'a', False),
597
                          ('b-id', 'b', False),
598
                         ], [(r[0], r[1], r[2]) for r in dlg._files_store])
599
600
        dlg._toggle_commit(None, 2, dlg._files_store)
601
        self.assertEqual([(None, None, False),
602
                          ('a-id', 'a', False),
603
                          ('b-id', 'b', True),
604
                         ], [(r[0], r[1], r[2]) for r in dlg._files_store])
605
606
        dlg._toggle_commit(None, 0, dlg._files_store)
607
        self.assertEqual([(None, None, True),
608
                          ('a-id', 'a', True),
609
                          ('b-id', 'b', True),
610
                         ], [(r[0], r[1], r[2]) for r in dlg._files_store])
278.1.23 by John Arbash Meinel
Beginning to support actual commit.
611
278.1.27 by John Arbash Meinel
Add the ability to commit just specific files.
612
    def test_specific_files(self):
613
        tree = self.make_branch_and_tree('tree')
614
        self.build_tree(['tree/a', 'tree/b/'])
615
        tree.add(['a', 'b'], ['a-id', 'b-id'])
616
617
        dlg = commit.CommitDialog(tree)
618
        self.assertEqual((['a', 'b'], []), dlg._get_specific_files())
619
278.1.43 by John Arbash Meinel
Finish connecting the 'Commit all changes' radio buttons.
620
        dlg._commit_selected_radio.set_active(True)
278.1.27 by John Arbash Meinel
Add the ability to commit just specific files.
621
        dlg._toggle_commit(None, 0, dlg._files_store)
622
        self.assertEqual(([], []), dlg._get_specific_files())
623
624
        dlg._toggle_commit(None, 1, dlg._files_store)
625
        self.assertEqual((['a'], []), dlg._get_specific_files())
626
627
    def test_specific_files_with_messages(self):
628
        tree = self.make_branch_and_tree('tree')
278.1.33 by John Arbash Meinel
Only enable the per-file dialog if 'per_file_commits' is enabled in the config.
629
        tree.branch.get_config().set_user_option('per_file_commits', 'true')
278.1.27 by John Arbash Meinel
Add the ability to commit just specific files.
630
        self.build_tree(['tree/a_file', 'tree/b_dir/'])
631
        tree.add(['a_file', 'b_dir'], ['1a-id', '0b-id'])
632
633
        dlg = commit.CommitDialog(tree)
278.1.43 by John Arbash Meinel
Finish connecting the 'Commit all changes' radio buttons.
634
        dlg._commit_selected_radio.set_active(True)
278.1.27 by John Arbash Meinel
Add the ability to commit just specific files.
635
        self.assertEqual((['a_file', 'b_dir'], []), dlg._get_specific_files())
636
637
        dlg._treeview_files.set_cursor((1,))
638
        dlg._set_file_commit_message('Test\nmessage\nfor a_file\n')
639
        dlg._treeview_files.set_cursor((2,))
640
        dlg._set_file_commit_message('message\nfor b_dir\n')
641
642
        self.assertEqual((['a_file', 'b_dir'],
643
                          [{'path':'a_file', 'file_id':'1a-id',
644
                            'message':'Test\nmessage\nfor a_file\n'},
645
                           {'path':'b_dir', 'file_id':'0b-id',
646
                            'message':'message\nfor b_dir\n'},
647
                          ]), dlg._get_specific_files())
648
649
        dlg._toggle_commit(None, 1, dlg._files_store)
650
        self.assertEqual((['b_dir'],
651
                          [{'path':'b_dir', 'file_id':'0b-id',
652
                            'message':'message\nfor b_dir\n'},
653
                          ]), dlg._get_specific_files())
654
622.1.1 by John Arbash Meinel
Ensure that per-file commit messages and global commit messages get sanitized.
655
    def test_specific_files_sanitizes_messages(self):
656
        tree = self.make_branch_and_tree('tree')
657
        tree.branch.get_config().set_user_option('per_file_commits', 'true')
658
        self.build_tree(['tree/a_file', 'tree/b_dir/'])
659
        tree.add(['a_file', 'b_dir'], ['1a-id', '0b-id'])
660
661
        dlg = commit.CommitDialog(tree)
662
        dlg._commit_selected_radio.set_active(True)
663
        self.assertEqual((['a_file', 'b_dir'], []), dlg._get_specific_files())
664
665
        dlg._treeview_files.set_cursor((1,))
666
        dlg._set_file_commit_message('Test\r\nmessage\rfor a_file\n')
667
        dlg._treeview_files.set_cursor((2,))
668
        dlg._set_file_commit_message('message\r\nfor\nb_dir\r')
669
670
        self.assertEqual((['a_file', 'b_dir'],
671
                          [{'path':'a_file', 'file_id':'1a-id',
672
                            'message':'Test\nmessage\nfor a_file\n'},
673
                           {'path':'b_dir', 'file_id':'0b-id',
674
                            'message':'message\nfor\nb_dir\n'},
675
                          ]), dlg._get_specific_files())
676
278.1.23 by John Arbash Meinel
Beginning to support actual commit.
677
635.2.10 by Vincent Ladeuil
Complete tests around saved commit messages.
678
class QuestionHelpers(object):
278.1.23 by John Arbash Meinel
Beginning to support actual commit.
679
278.1.26 by John Arbash Meinel
Handle pointless commits and trees with unknown files.
680
    def _set_question_yes(self, dlg):
681
        """Set the dialog to answer YES to any questions."""
682
        self.questions = []
606 by Vincent Ladeuil
Fix gtk dialogs popping up and asking for input during selftest.
683
        def _question_yes(*args, **kwargs):
278.1.26 by John Arbash Meinel
Handle pointless commits and trees with unknown files.
684
            self.questions.append(args)
685
            self.questions.append('YES')
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
686
            return Gtk.ResponseType.YES
278.1.26 by John Arbash Meinel
Handle pointless commits and trees with unknown files.
687
        dlg._question_dialog = _question_yes
688
689
    def _set_question_no(self, dlg):
690
        """Set the dialog to answer NO to any questions."""
691
        self.questions = []
606 by Vincent Ladeuil
Fix gtk dialogs popping up and asking for input during selftest.
692
        def _question_no(*args, **kwargs):
278.1.26 by John Arbash Meinel
Handle pointless commits and trees with unknown files.
693
            self.questions.append(args)
694
            self.questions.append('NO')
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
695
            return Gtk.ResponseType.NO
278.1.26 by John Arbash Meinel
Handle pointless commits and trees with unknown files.
696
        dlg._question_dialog = _question_no
697
635.2.10 by Vincent Ladeuil
Complete tests around saved commit messages.
698
699
class TestCommitDialog_Commit(tests.TestCaseWithTransport, QuestionHelpers):
700
    """Tests on the actual 'commit' button being pushed."""
701
278.1.25 by John Arbash Meinel
Add the 'Only Commit Locally' checkbox, we may want to put it elsewhere, though.
702
    def test_bound_commit_local(self):
703
        tree = self.make_branch_and_tree('tree')
704
        self.build_tree(['tree/a'])
705
        tree.add(['a'], ['a-id'])
706
        rev_id1 = tree.commit('one')
707
708
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
709
        self.build_tree(['tree2/b'])
710
        tree2.add(['b'], ['b-id'])
711
        tree2.branch.bind(tree.branch)
712
713
        dlg = commit.CommitDialog(tree2)
714
        # With the check box set, it should only effect the local branch
715
        dlg._check_local.set_active(True)
716
        dlg._set_global_commit_message('Commit message\n')
717
        dlg._do_commit()
718
719
        last_rev = tree2.last_revision()
720
        self.assertEqual(last_rev, dlg.committed_revision_id)
721
        self.assertEqual(rev_id1, tree.branch.last_revision())
722
622.1.1 by John Arbash Meinel
Ensure that per-file commit messages and global commit messages get sanitized.
723
    def test_commit_global_sanitizes_message(self):
724
        tree = self.make_branch_and_tree('tree')
725
        self.build_tree(['tree/a'])
726
        tree.add(['a'], ['a-id'])
727
        rev_id1 = tree.commit('one')
728
729
        self.build_tree(['tree/b'])
730
        tree.add(['b'], ['b-id'])
731
        dlg = commit.CommitDialog(tree)
732
        # With the check box set, it should only effect the local branch
733
        dlg._set_global_commit_message('Commit\r\nmessage\rfoo\n')
734
        dlg._do_commit()
735
        rev = tree.branch.repository.get_revision(tree.last_revision())
736
        self.assertEqual('Commit\nmessage\nfoo\n', rev.message)
737
278.1.25 by John Arbash Meinel
Add the 'Only Commit Locally' checkbox, we may want to put it elsewhere, though.
738
    def test_bound_commit_both(self):
739
        tree = self.make_branch_and_tree('tree')
740
        self.build_tree(['tree/a'])
741
        tree.add(['a'], ['a-id'])
742
        rev_id1 = tree.commit('one')
743
744
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
745
        self.build_tree(['tree2/b'])
746
        tree2.add(['b'], ['b-id'])
747
        tree2.branch.bind(tree.branch)
748
749
        dlg = commit.CommitDialog(tree2)
750
        # With the check box set, it should only effect the local branch
751
        dlg._check_local.set_active(False)
752
        dlg._set_global_commit_message('Commit message\n')
753
        dlg._do_commit()
754
755
        last_rev = tree2.last_revision()
756
        self.assertEqual(last_rev, dlg.committed_revision_id)
757
        self.assertEqual(last_rev, tree.branch.last_revision())
758
606 by Vincent Ladeuil
Fix gtk dialogs popping up and asking for input during selftest.
759
    def test_commit_empty_message(self):
278.1.23 by John Arbash Meinel
Beginning to support actual commit.
760
        tree = self.make_branch_and_tree('tree')
761
        self.build_tree(['tree/a', 'tree/b'])
762
        tree.add(['a'], ['a-id'])
763
        rev_id = tree.commit('one')
764
765
        tree.add(['b'], ['b-id'])
766
767
        dlg = commit.CommitDialog(tree)
278.1.26 by John Arbash Meinel
Handle pointless commits and trees with unknown files.
768
        self._set_question_no(dlg)
278.1.23 by John Arbash Meinel
Beginning to support actual commit.
769
        dlg._do_commit()
770
        self.assertEqual(
771
            [('Commit with an empty message?',
772
              'You can describe your commit intent in the message.'),
773
              'NO',
278.1.26 by John Arbash Meinel
Handle pointless commits and trees with unknown files.
774
            ], self.questions)
278.1.23 by John Arbash Meinel
Beginning to support actual commit.
775
        # By saying NO, nothing should be committed.
776
        self.assertEqual(rev_id, tree.last_revision())
777
        self.assertIs(None, dlg.committed_revision_id)
278.1.25 by John Arbash Meinel
Add the 'Only Commit Locally' checkbox, we may want to put it elsewhere, though.
778
        self.assertTrue(dlg._global_message_text_view.get_property('is-focus'))
278.1.23 by John Arbash Meinel
Beginning to support actual commit.
779
278.1.26 by John Arbash Meinel
Handle pointless commits and trees with unknown files.
780
        self._set_question_yes(dlg)
278.1.23 by John Arbash Meinel
Beginning to support actual commit.
781
782
        dlg._do_commit()
783
        self.assertEqual(
784
            [('Commit with an empty message?',
785
              'You can describe your commit intent in the message.'),
278.1.26 by John Arbash Meinel
Handle pointless commits and trees with unknown files.
786
              'YES',
787
            ], self.questions)
278.1.23 by John Arbash Meinel
Beginning to support actual commit.
788
        committed = tree.last_revision()
789
        self.assertNotEqual(rev_id, committed)
790
        self.assertEqual(committed, dlg.committed_revision_id)
791
792
    def test_initial_commit(self):
793
        tree = self.make_branch_and_tree('tree')
794
        self.build_tree(['tree/a'])
795
        tree.add(['a'], ['a-id'])
796
797
        dlg = commit.CommitDialog(tree)
278.1.25 by John Arbash Meinel
Add the 'Only Commit Locally' checkbox, we may want to put it elsewhere, though.
798
        dlg._set_global_commit_message('Some text\n')
278.1.23 by John Arbash Meinel
Beginning to support actual commit.
799
        dlg._do_commit()
800
801
        last_rev = tree.last_revision()
802
        self.assertEqual(last_rev, dlg.committed_revision_id)
803
        rev = tree.branch.repository.get_revision(last_rev)
804
        self.assertEqual(last_rev, rev.revision_id)
805
        self.assertEqual('Some text\n', rev.message)
278.1.26 by John Arbash Meinel
Handle pointless commits and trees with unknown files.
806
807
    def test_pointless_commit(self):
808
        tree = self.make_branch_and_tree('tree')
809
        self.build_tree(['tree/a'])
810
        tree.add(['a'], ['a-id'])
811
        rev_id1 = tree.commit('one')
812
813
        dlg = commit.CommitDialog(tree)
814
        dlg._set_global_commit_message('Some text\n')
815
816
        self._set_question_no(dlg)
817
        dlg._do_commit()
818
819
        self.assertIs(None, dlg.committed_revision_id)
820
        self.assertEqual(rev_id1, tree.last_revision())
821
        self.assertEqual(
822
            [('Commit with no changes?',
823
              'There are no changes in the working tree.'
824
              ' Do you want to commit anyway?'),
825
              'NO',
826
            ], self.questions)
827
828
        self._set_question_yes(dlg)
829
        dlg._do_commit()
830
831
        rev_id2 = tree.last_revision()
832
        self.assertEqual(rev_id2, dlg.committed_revision_id)
833
        self.assertNotEqual(rev_id1, rev_id2)
834
        self.assertEqual(
835
            [('Commit with no changes?',
836
              'There are no changes in the working tree.'
837
              ' Do you want to commit anyway?'),
838
              'YES',
839
            ], self.questions)
840
841
    def test_unknowns(self):
842
        """We should check if there are unknown files."""
843
        tree = self.make_branch_and_tree('tree')
844
        rev_id1 = tree.commit('one')
845
        self.build_tree(['tree/a', 'tree/b'])
846
        tree.add(['a'], ['a-id'])
847
848
        dlg = commit.CommitDialog(tree)
849
        dlg._set_global_commit_message('Some text\n')
850
        self._set_question_no(dlg)
851
852
        dlg._do_commit()
853
854
        self.assertIs(None, dlg.committed_revision_id)
855
        self.assertEqual(rev_id1, tree.last_revision())
856
        self.assertEqual(
857
            [("Commit with unknowns?",
858
              "Unknown files exist in the working tree. Commit anyway?"),
859
              "NO",
860
            ], self.questions)
861
862
        self._set_question_yes(dlg)
863
        dlg._do_commit()
864
865
        rev_id2 = tree.last_revision()
866
        self.assertNotEqual(rev_id1, rev_id2)
867
        self.assertEqual(rev_id2, dlg.committed_revision_id)
868
        self.assertEqual(
869
            [("Commit with unknowns?",
870
              "Unknown files exist in the working tree. Commit anyway?"),
871
              "YES",
872
            ], self.questions)
873
278.1.27 by John Arbash Meinel
Add the ability to commit just specific files.
874
    def test_commit_specific_files(self):
875
        tree = self.make_branch_and_tree('tree')
876
        rev_id1 = tree.commit('one')
877
        self.build_tree(['tree/a', 'tree/b'])
878
        tree.add(['a', 'b'], ['a-id', 'b-id'])
879
880
        dlg = commit.CommitDialog(tree)
278.1.43 by John Arbash Meinel
Finish connecting the 'Commit all changes' radio buttons.
881
        dlg._commit_selected_radio.set_active(True) # enable partial
278.1.27 by John Arbash Meinel
Add the ability to commit just specific files.
882
        dlg._toggle_commit(None, 2, dlg._files_store) # unset 'b'
883
884
        dlg._set_global_commit_message('Committing just "a"\n')
885
        dlg._do_commit()
886
887
        rev_id2 = dlg.committed_revision_id
888
        self.assertIsNot(None, rev_id2)
889
        self.assertEqual(rev_id2, tree.last_revision())
890
891
        rt = tree.branch.repository.revision_tree(rev_id2)
892
        entries = [(path, ie.file_id) for path, ie in rt.iter_entries_by_dir()
893
                                       if path] # Ignore the root entry
894
        self.assertEqual([('a', 'a-id')], entries)
895
278.1.43 by John Arbash Meinel
Finish connecting the 'Commit all changes' radio buttons.
896
    def test_commit_partial_no_partial(self):
897
        """Ignore the checkboxes if committing all files."""
898
        tree = self.make_branch_and_tree('tree')
899
        rev_id1 = tree.commit('one')
900
        self.build_tree(['tree/a', 'tree/b'])
901
        tree.add(['a', 'b'], ['a-id', 'b-id'])
902
903
        dlg = commit.CommitDialog(tree)
904
        dlg._commit_selected_radio.set_active(True) # enable partial
905
        dlg._toggle_commit(None, 2, dlg._files_store) # unset 'b'
906
907
        # Switch back to committing all changes
908
        dlg._commit_all_files_radio.set_active(True)
909
910
        dlg._set_global_commit_message('Committing everything\n')
911
        dlg._do_commit()
912
913
        rev_id2 = dlg.committed_revision_id
914
        self.assertIsNot(None, rev_id2)
915
        self.assertEqual(rev_id2, tree.last_revision())
916
917
        rt = tree.branch.repository.revision_tree(rev_id2)
918
        entries = [(path, ie.file_id) for path, ie in rt.iter_entries_by_dir()
919
                                       if path] # Ignore the root entry
920
        self.assertEqual([('a', 'a-id'), ('b', 'b-id')], entries)
921
278.1.27 by John Arbash Meinel
Add the ability to commit just specific files.
922
    def test_commit_no_messages(self):
923
        tree = self.make_branch_and_tree('tree')
924
        rev_id1 = tree.commit('one')
925
        self.build_tree(['tree/a', 'tree/b'])
926
        tree.add(['a', 'b'], ['a-id', 'b-id'])
927
928
        dlg = commit.CommitDialog(tree)
929
        dlg._set_global_commit_message('Simple commit\n')
930
        dlg._do_commit()
931
932
        rev = tree.branch.repository.get_revision(dlg.committed_revision_id)
933
        self.failIf('file-info' in rev.properties)
934
278.1.33 by John Arbash Meinel
Only enable the per-file dialog if 'per_file_commits' is enabled in the config.
935
    def test_commit_disabled_messages(self):
936
        tree = self.make_branch_and_tree('tree')
937
        rev_id1 = tree.commit('one')
938
939
        self.build_tree(['tree/a', 'tree/b'])
940
        tree.add(['a', 'b'], ['a-id', 'b-id'])
941
942
        dlg = commit.CommitDialog(tree)
943
        self.assertFalse(dlg._file_message_expander.get_property('visible'))
278.1.38 by John Arbash Meinel
Add tests that when per-file messages are disabled
944
        self.assertEqual('Commit Message',
945
                         dlg._global_message_label.get_text())
278.1.33 by John Arbash Meinel
Only enable the per-file dialog if 'per_file_commits' is enabled in the config.
946
947
        tree.branch.get_config().set_user_option('per_file_commits', 'true')
948
        dlg = commit.CommitDialog(tree)
949
        self.assertTrue(dlg._file_message_expander.get_property('visible'))
278.1.38 by John Arbash Meinel
Add tests that when per-file messages are disabled
950
        self.assertEqual('Global Commit Message',
951
                         dlg._global_message_label.get_text())
278.1.33 by John Arbash Meinel
Only enable the per-file dialog if 'per_file_commits' is enabled in the config.
952
953
        tree.branch.get_config().set_user_option('per_file_commits', 'on')
954
        dlg = commit.CommitDialog(tree)
955
        self.assertTrue(dlg._file_message_expander.get_property('visible'))
278.1.38 by John Arbash Meinel
Add tests that when per-file messages are disabled
956
        self.assertEqual('Global Commit Message',
957
                         dlg._global_message_label.get_text())
278.1.33 by John Arbash Meinel
Only enable the per-file dialog if 'per_file_commits' is enabled in the config.
958
959
        tree.branch.get_config().set_user_option('per_file_commits', 'y')
960
        dlg = commit.CommitDialog(tree)
961
        self.assertTrue(dlg._file_message_expander.get_property('visible'))
278.1.38 by John Arbash Meinel
Add tests that when per-file messages are disabled
962
        self.assertEqual('Global Commit Message',
963
                         dlg._global_message_label.get_text())
278.1.33 by John Arbash Meinel
Only enable the per-file dialog if 'per_file_commits' is enabled in the config.
964
965
        tree.branch.get_config().set_user_option('per_file_commits', 'n')
966
        dlg = commit.CommitDialog(tree)
967
        self.assertFalse(dlg._file_message_expander.get_property('visible'))
278.1.38 by John Arbash Meinel
Add tests that when per-file messages are disabled
968
        self.assertEqual('Commit Message',
969
                         dlg._global_message_label.get_text())
278.1.33 by John Arbash Meinel
Only enable the per-file dialog if 'per_file_commits' is enabled in the config.
970
278.1.27 by John Arbash Meinel
Add the ability to commit just specific files.
971
    def test_commit_specific_files_with_messages(self):
972
        tree = self.make_branch_and_tree('tree')
278.1.33 by John Arbash Meinel
Only enable the per-file dialog if 'per_file_commits' is enabled in the config.
973
        tree.branch.get_config().set_user_option('per_file_commits', 'true')
278.1.27 by John Arbash Meinel
Add the ability to commit just specific files.
974
        rev_id1 = tree.commit('one')
975
        self.build_tree(['tree/a', 'tree/b'])
976
        tree.add(['a', 'b'], ['a-id', 'b-id'])
977
978
        dlg = commit.CommitDialog(tree)
278.1.43 by John Arbash Meinel
Finish connecting the 'Commit all changes' radio buttons.
979
        dlg._commit_selected_radio.set_active(True) # enable partial
278.1.27 by John Arbash Meinel
Add the ability to commit just specific files.
980
        dlg._treeview_files.set_cursor((1,))
981
        dlg._set_file_commit_message('Message for A\n')
982
        dlg._treeview_files.set_cursor((2,))
983
        dlg._set_file_commit_message('Message for B\n')
984
        dlg._toggle_commit(None, 2, dlg._files_store) # unset 'b'
985
        dlg._set_global_commit_message('Commit just "a"')
986
987
        dlg._do_commit()
988
989
        rev_id2 = dlg.committed_revision_id
990
        self.assertEqual(rev_id2, tree.last_revision())
991
        rev = tree.branch.repository.get_revision(rev_id2)
992
        self.assertEqual('Commit just "a"', rev.message)
993
        file_info = rev.properties['file-info']
662 by Vincent Ladeuil
Fix test failures.
994
        self.assertEqual(u'ld7:file_id4:a-id'
995
                         '7:message14:Message for A\n'
996
                         '4:path1:a'
997
                         'ee',
998
                         file_info)
278.1.27 by John Arbash Meinel
Add the ability to commit just specific files.
999
        self.assertEqual([{'path':'a', 'file_id':'a-id',
662 by Vincent Ladeuil
Fix test failures.
1000
                           'message':'Message for A\n'},],
1001
                         bencode.bdecode(file_info.encode('UTF-8')))
278.1.28 by John Arbash Meinel
Ensure that we can set per-file messages even during a merge.
1002
1003
    def test_commit_messages_after_merge(self):
1004
        tree = self.make_branch_and_tree('tree')
278.1.33 by John Arbash Meinel
Only enable the per-file dialog if 'per_file_commits' is enabled in the config.
1005
        tree.branch.get_config().set_user_option('per_file_commits', 'true')
278.1.28 by John Arbash Meinel
Ensure that we can set per-file messages even during a merge.
1006
        rev_id1 = tree.commit('one')
1007
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
1008
        self.build_tree(['tree2/a', 'tree2/b'])
1009
        tree2.add(['a', 'b'], ['a-id', 'b-id'])
1010
        rev_id2 = tree2.commit('two')
1011
1012
        tree.merge_from_branch(tree2.branch)
1013
1014
        dlg = commit.CommitDialog(tree)
1015
        dlg._treeview_files.set_cursor((1,)) # 'a'
1016
        dlg._set_file_commit_message('Message for A\n')
1017
        # No message for 'B'
1018
        dlg._set_global_commit_message('Merging from "tree2"\n')
1019
1020
        dlg._do_commit()
1021
1022
        rev_id3 = dlg.committed_revision_id
1023
        self.assertEqual(rev_id3, tree.last_revision())
1024
        rev = tree.branch.repository.get_revision(rev_id3)
1025
        self.assertEqual('Merging from "tree2"\n', rev.message)
1026
        self.assertEqual([rev_id1, rev_id2], rev.parent_ids)
1027
        file_info = rev.properties['file-info']
662 by Vincent Ladeuil
Fix test failures.
1028
        self.assertEqual(u'ld7:file_id4:a-id'
1029
                         '7:message14:Message for A\n'
1030
                         '4:path1:a'
1031
                         'ee',
1032
                         file_info)
278.1.28 by John Arbash Meinel
Ensure that we can set per-file messages even during a merge.
1033
        self.assertEqual([{'path':'a', 'file_id':'a-id',
662 by Vincent Ladeuil
Fix test failures.
1034
                           'message':'Message for A\n'},],
1035
                         bencode.bdecode(file_info.encode('UTF-8')))
278.1.29 by John Arbash Meinel
Start testing with Unicode data.
1036
1037
    def test_commit_unicode_messages(self):
500.1.1 by Vincent Ladeuil
Fix test failing after a feature rename in bzr.
1038
        self.requireFeature(tests.UnicodeFilenameFeature)
278.1.29 by John Arbash Meinel
Start testing with Unicode data.
1039
1040
        tree = self.make_branch_and_tree('tree')
278.1.33 by John Arbash Meinel
Only enable the per-file dialog if 'per_file_commits' is enabled in the config.
1041
        tree.branch.get_config().set_user_option('per_file_commits', 'true')
278.1.29 by John Arbash Meinel
Start testing with Unicode data.
1042
        self.build_tree(['tree/a', u'tree/\u03a9'])
1043
        tree.add(['a', u'\u03a9'], ['a-id', 'omega-id'])
1044
1045
        dlg = commit.CommitDialog(tree)
1046
        dlg._treeview_files.set_cursor((1,)) # 'a'
1047
        dlg._set_file_commit_message(u'Test \xfan\xecc\xf6de\n')
1048
        dlg._treeview_files.set_cursor((2,)) # omega
1049
        dlg._set_file_commit_message(u'\u03a9 is the end of all things.\n')
1050
        dlg._set_global_commit_message(u'\u03a9 and \xfan\xecc\xf6de\n')
1051
1052
        self.assertEqual(([u'a', u'\u03a9'],
1053
                          [{'path':'a', 'file_id':'a-id',
1054
                            'message':'Test \xc3\xban\xc3\xacc\xc3\xb6de\n'},
1055
                           {'path':'\xce\xa9', 'file_id':'omega-id',
1056
                            'message':'\xce\xa9 is the end of all things.\n'},
1057
                          ]), dlg._get_specific_files())
1058
1059
        dlg._do_commit()
1060
1061
        rev = tree.branch.repository.get_revision(dlg.committed_revision_id)
278.1.31 by John Arbash Meinel
We can make bencode work again by a simple decode/encode step.
1062
        file_info = rev.properties['file-info'].encode('UTF-8')
278.1.29 by John Arbash Meinel
Start testing with Unicode data.
1063
        value = ('ld7:file_id4:a-id'
1064
                   '7:message16:Test \xc3\xban\xc3\xacc\xc3\xb6de\n'
1065
                   '4:path1:a'
1066
                  'e'
1067
                  'd7:file_id8:omega-id'
1068
                   '7:message29:\xce\xa9 is the end of all things.\n'
1069
                   '4:path2:\xce\xa9'
1070
                  'e'
1071
                 'e')
1072
        self.assertEqual(value, file_info)
1073
        file_info_decoded = bencode.bdecode(file_info)
1074
        for d in file_info_decoded:
278.1.31 by John Arbash Meinel
We can make bencode work again by a simple decode/encode step.
1075
            d['path'] = d['path'].decode('UTF-8')
1076
            d['message'] = d['message'].decode('UTF-8')
278.1.29 by John Arbash Meinel
Start testing with Unicode data.
1077
1078
        self.assertEqual([{'path':u'a', 'file_id':'a-id',
1079
                           'message':u'Test \xfan\xecc\xf6de\n'},
1080
                          {'path':u'\u03a9', 'file_id':'omega-id',
1081
                           'message':u'\u03a9 is the end of all things.\n'},
1082
                         ], file_info_decoded)
622.1.1 by John Arbash Meinel
Ensure that per-file commit messages and global commit messages get sanitized.
1083
1084
1085
class TestSanitizeMessage(tests.TestCase):
1086
1087
    def assertSanitize(self, expected, original):
1088
        self.assertEqual(expected,
1089
                         commit._sanitize_and_decode_message(original))
1090
1091
    def test_untouched(self):
1092
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\nbar\nbaz\n')
1093
1094
    def test_converts_cr_to_lf(self):
1095
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\rbar\rbaz\r')
1096
1097
    def test_converts_crlf_to_lf(self):
1098
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\r\nbaz\r\n')
1099
1100
    def test_converts_mixed_to_lf(self):
1101
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\rbaz\n')
635.2.8 by Vincent Ladeuil
Start testing patch behavior.
1102
1103
635.2.10 by Vincent Ladeuil
Complete tests around saved commit messages.
1104
class TestSavedCommitMessages(tests.TestCaseWithTransport):
635.2.9 by Vincent Ladeuil
Tests completed for uncommit.
1105
635.2.12 by Vincent Ladeuil
Implement commit message saving without modifying bzrlib.
1106
    def setUp(self):
1107
        super(TestSavedCommitMessages, self).setUp()
1108
        # Install our hook
1109
        branch.Branch.hooks.install_named_hook(
1110
            'post_uncommit', commit.save_commit_messages, None)
1111
635.2.9 by Vincent Ladeuil
Tests completed for uncommit.
1112
    def _get_file_info_dict(self, rank):
1113
        file_info = [dict(path='a', file_id='a-id', message='a msg %d' % rank),
1114
                     dict(path='b', file_id='b-id', message='b msg %d' % rank)]
1115
        return file_info
1116
1117
    def _get_file_info_revprops(self, rank):
1118
        file_info_prop = self._get_file_info_dict(rank)
1119
        return {'file-info': bencode.bencode(file_info_prop).decode('UTF-8')}
1120
1121
    def _get_commit_message(self):
1122
        return self.config.get_user_option('gtk_global_commit_message')
1123
1124
    def _get_file_commit_messages(self):
1125
        return self.config.get_user_option('gtk_file_commit_messages')
1126
635.2.10 by Vincent Ladeuil
Complete tests around saved commit messages.
1127
1128
class TestUncommitHook(TestSavedCommitMessages):
1129
1130
    def setUp(self):
1131
        super(TestUncommitHook, self).setUp()
1132
        self.tree = self.make_branch_and_tree('tree')
1133
        self.config = self.tree.branch.get_config()
1134
        self.build_tree(['tree/a', 'tree/b'])
1135
        self.tree.add(['a'], ['a-id'])
1136
        self.tree.add(['b'], ['b-id'])
635.2.12 by Vincent Ladeuil
Implement commit message saving without modifying bzrlib.
1137
        rev1 = self.tree.commit('one', rev_id='one-id',
1138
                                revprops=self._get_file_info_revprops(1))
1139
        rev2 = self.tree.commit('two', rev_id='two-id',
1140
                                revprops=self._get_file_info_revprops(2))
1141
        rev3 = self.tree.commit('three', rev_id='three-id',
635.2.10 by Vincent Ladeuil
Complete tests around saved commit messages.
1142
                                revprops=self._get_file_info_revprops(3))
1143
635.2.9 by Vincent Ladeuil
Tests completed for uncommit.
1144
    def test_uncommit_one_by_one(self):
1145
        uncommit.uncommit(self.tree.branch, tree=self.tree)
1146
        self.assertEquals(u'three', self._get_commit_message())
1147
        self.assertEquals(u'd4:a-id7:a msg 34:b-id7:b msg 3e',
1148
                          self._get_file_commit_messages())
1149
1150
        uncommit.uncommit(self.tree.branch, tree=self.tree)
1151
        self.assertEquals(u'two\n******\nthree', self._get_commit_message())
1152
        self.assertEquals(u'd4:a-id22:a msg 2\n******\na msg 3'
1153
                          '4:b-id22:b msg 2\n******\nb msg 3e',
1154
                          self._get_file_commit_messages())
1155
1156
        uncommit.uncommit(self.tree.branch, tree=self.tree)
1157
        self.assertEquals(u'one\n******\ntwo\n******\nthree',
1158
                          self._get_commit_message())
1159
        self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1160
                          '4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1161
                          self._get_file_commit_messages())
1162
1163
    def test_uncommit_all_at_once(self):
1164
        uncommit.uncommit(self.tree.branch, tree=self.tree, revno=1)
1165
        self.assertEquals(u'one\n******\ntwo\n******\nthree',
1166
                          self._get_commit_message())
1167
        self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1168
                          '4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1169
                          self._get_file_commit_messages())
635.2.10 by Vincent Ladeuil
Complete tests around saved commit messages.
1170
1171
1172
class TestReusingSavedCommitMessages(TestSavedCommitMessages, QuestionHelpers):
1173
1174
    def setUp(self):
1175
        super(TestReusingSavedCommitMessages, self).setUp()
1176
        self.tree = self.make_branch_and_tree('tree')
1177
        self.config = self.tree.branch.get_config()
1178
        self.config.set_user_option('per_file_commits', 'true')
1179
        self.build_tree(['tree/a', 'tree/b'])
1180
        self.tree.add(['a'], ['a-id'])
1181
        self.tree.add(['b'], ['b-id'])
1182
        rev1 = self.tree.commit('one', revprops=self._get_file_info_revprops(1))
1183
        rev2 = self.tree.commit('two', revprops=self._get_file_info_revprops(2))
1184
        uncommit.uncommit(self.tree.branch, tree=self.tree)
1185
        self.build_tree_contents([('tree/a', 'new a content\n'),
1186
                                  ('tree/b', 'new b content'),])
1187
635.2.11 by Vincent Ladeuil
Fix a leaking dialog windows appearing during the test suite.
1188
    def _get_commit_dialog(self, tree):
1189
        # Ensure we will never use a dialog that can actually prompt the user
1190
        # during the test suite. Test *can* and *should* override with the
1191
        # correct question dialog type.
1192
        dlg = commit.CommitDialog(tree)
1193
        self._set_question_no(dlg)
1194
        return dlg
1195
635.2.10 by Vincent Ladeuil
Complete tests around saved commit messages.
1196
    def test_setup_saved_messages(self):
1197
        # Check the initial setup
1198
        self.assertEquals(u'two', self._get_commit_message())
1199
        self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1200
                          self._get_file_commit_messages())
1201
1202
    def test_messages_are_reloaded(self):
635.2.11 by Vincent Ladeuil
Fix a leaking dialog windows appearing during the test suite.
1203
        dlg = self._get_commit_dialog(self.tree)
635.2.10 by Vincent Ladeuil
Complete tests around saved commit messages.
1204
        self.assertEquals(u'two', dlg._get_global_commit_message())
1205
        self.assertEquals(([u'a', u'b'],
1206
                           [{ 'path': 'a',
1207
                             'file_id': 'a-id', 'message': 'a msg 2',},
1208
                           {'path': 'b',
1209
                            'file_id': 'b-id', 'message': 'b msg 2',}],),
1210
                          dlg._get_specific_files())
1211
1212
    def test_messages_are_consumed(self):
635.2.11 by Vincent Ladeuil
Fix a leaking dialog windows appearing during the test suite.
1213
        dlg = self._get_commit_dialog(self.tree)
635.2.10 by Vincent Ladeuil
Complete tests around saved commit messages.
1214
        dlg._do_commit()
1215
        self.assertEquals(u'', self._get_commit_message())
1216
        self.assertEquals(u'de', self._get_file_commit_messages())
1217
1218
    def test_messages_are_saved_on_cancel_if_required(self):
635.2.11 by Vincent Ladeuil
Fix a leaking dialog windows appearing during the test suite.
1219
        dlg = self._get_commit_dialog(self.tree)
635.2.10 by Vincent Ladeuil
Complete tests around saved commit messages.
1220
        self._set_question_yes(dlg) # Save messages
1221
        dlg._do_cancel()
1222
        self.assertEquals(u'two', self._get_commit_message())
1223
        self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1224
                          self._get_file_commit_messages())
1225
1226
    def test_messages_are_cleared_on_cancel_if_required(self):
635.2.11 by Vincent Ladeuil
Fix a leaking dialog windows appearing during the test suite.
1227
        dlg = self._get_commit_dialog(self.tree)
635.2.10 by Vincent Ladeuil
Complete tests around saved commit messages.
1228
        self._set_question_no(dlg) # Don't save messages
1229
        dlg._do_cancel()
1230
        self.assertEquals(u'', self._get_commit_message())
1231
        self.assertEquals(u'de',
1232
                          self._get_file_commit_messages())