/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
1
# Copyright (C) 2007 John Arbash Meinel <john@arbash-meinel.com>
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
278.1.23 by John Arbash Meinel
Beginning to support actual commit.
21
import gtk
22
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
23
from bzrlib import (
24
    tests,
25
    revision,
26
    )
27
28
from bzrlib.plugins.gtk import commit
29
30
31
# TODO: All we need is basic ancestry code to test this, we shouldn't need a
32
# TestCaseWithTransport, just a TestCaseWithMemoryTransport or somesuch.
33
34
class TestPendingRevisions(tests.TestCaseWithTransport):
35
36
    def test_pending_revisions_none(self):
37
        tree = self.make_branch_and_tree('.')
38
        tree.commit('one')
39
40
        self.assertIs(None, commit.pending_revisions(tree))
41
42
    def test_pending_revisions_simple(self):
43
        tree = self.make_branch_and_tree('tree')
44
        rev_id1 = tree.commit('one')
45
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
46
        rev_id2 = tree2.commit('two')
47
        tree.merge_from_branch(tree2.branch)
48
        self.assertEqual([rev_id1, rev_id2], tree.get_parent_ids())
49
50
        pending_revisions = commit.pending_revisions(tree)
51
        # One primary merge
52
        self.assertEqual(1, len(pending_revisions))
53
        # Revision == rev_id2
54
        self.assertEqual(rev_id2, pending_revisions[0][0].revision_id)
55
        # No children of this revision.
56
        self.assertEqual([], pending_revisions[0][1])
57
58
    def test_pending_revisions_with_children(self):
59
        tree = self.make_branch_and_tree('tree')
60
        rev_id1 = tree.commit('one')
61
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
62
        rev_id2 = tree2.commit('two')
63
        rev_id3 = tree2.commit('three')
64
        rev_id4 = tree2.commit('four')
65
        tree.merge_from_branch(tree2.branch)
66
        self.assertEqual([rev_id1, rev_id4], tree.get_parent_ids())
67
68
        pending_revisions = commit.pending_revisions(tree)
69
        # One primary merge
70
        self.assertEqual(1, len(pending_revisions))
71
        # Revision == rev_id2
72
        self.assertEqual(rev_id4, pending_revisions[0][0].revision_id)
73
        # Two children for this revision
74
        self.assertEqual(2, len(pending_revisions[0][1]))
75
        self.assertEqual(rev_id3, pending_revisions[0][1][0].revision_id)
76
        self.assertEqual(rev_id2, pending_revisions[0][1][1].revision_id)
77
78
    def test_pending_revisions_multi_merge(self):
79
        tree = self.make_branch_and_tree('tree')
80
        rev_id1 = tree.commit('one')
81
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
82
        rev_id2 = tree2.commit('two')
83
        rev_id3 = tree2.commit('three')
84
        tree3 = tree2.bzrdir.sprout('tree3').open_workingtree()
85
        rev_id4 = tree3.commit('four')
86
        rev_id5 = tree3.commit('five')
87
        tree.merge_from_branch(tree2.branch)
88
        tree.merge_from_branch(tree3.branch)
89
        self.assertEqual([rev_id1, rev_id3, rev_id5], tree.get_parent_ids())
90
91
        pending_revisions = commit.pending_revisions(tree)
92
        # Two primary merges
93
        self.assertEqual(2, len(pending_revisions))
94
        # Revision == rev_id2
95
        self.assertEqual(rev_id3, pending_revisions[0][0].revision_id)
96
        self.assertEqual(rev_id5, pending_revisions[1][0].revision_id)
97
        # One child for the first merge
98
        self.assertEqual(1, len(pending_revisions[0][1]))
99
        self.assertEqual(rev_id2, pending_revisions[0][1][0].revision_id)
100
        # One child for the second merge
101
        self.assertEqual(1, len(pending_revisions[1][1]))
102
        self.assertEqual(rev_id4, pending_revisions[1][1][0].revision_id)
103
104
105
class Test_RevToPendingInfo(tests.TestCaseWithTransport):
106
107
    def test_basic_info(self):
108
        tree = self.make_branch_and_tree('tree')
109
        rev_id = tree.commit('Multiline\ncommit\nmessage',
110
                             committer='Joe Foo <joe@foo.com>',
111
                             timestamp=1191012408.674,
112
                             timezone=-18000
113
                             )
114
        rev = tree.branch.repository.get_revision(rev_id)
115
        rev_dict = commit.CommitDialog._rev_to_pending_info(rev)
116
        self.assertEqual({'committer':'Joe Foo',
117
                          'summary':'Multiline',
118
                          'date':'2007-09-28',
119
                          'revision_id':rev_id,
120
                         }, rev_dict)
121
122
123
class CommitDialogNoWidgets(commit.CommitDialog):
124
125
    def construct(self):
126
        pass # Don't create any widgets here
127
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
128
    def fill_in_data(self):
129
        pass # With no widgets, there are no widgets to fill out
130
131
132
class TestCommitDialogSimple(tests.TestCaseWithTransport):
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
133
134
    def test_setup_parameters_no_pending(self):
135
        tree = self.make_branch_and_tree('tree')
136
        rev_id = tree.commit('first')
137
138
        dlg = CommitDialogNoWidgets(tree)
139
        self.assertEqual(rev_id, dlg._basis_tree.get_revision_id())
140
        self.assertIs(None, dlg._pending)
141
        self.assertFalse(dlg._is_checkout)
142
143
    def test_setup_parameters_checkout(self):
144
        tree = self.make_branch_and_tree('tree')
145
        rev_id = tree.commit('first')
146
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
147
        tree2.branch.bind(tree.branch)
148
149
        dlg = CommitDialogNoWidgets(tree2)
150
        self.assertEqual(rev_id, dlg._basis_tree.get_revision_id())
151
        self.assertIs(None, dlg._pending)
152
        self.assertTrue(dlg._is_checkout)
153
154
    def test_setup_parameters_pending(self):
155
        tree = self.make_branch_and_tree('tree')
156
        rev_id1 = tree.commit('one')
157
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
158
        rev_id2 = tree2.commit('two')
159
        tree.merge_from_branch(tree2.branch)
160
161
        dlg = CommitDialogNoWidgets(tree)
162
        self.assertEqual(rev_id1, dlg._basis_tree.get_revision_id())
163
        self.assertIsNot(None, dlg._pending)
164
        self.assertEqual(1, len(dlg._pending))
165
        self.assertEqual(rev_id2, dlg._pending[0][0].revision_id)
166
167
    def test_setup_parameters_delta(self):
168
        tree = self.make_branch_and_tree('tree')
169
        self.build_tree(['tree/a'])
170
        tree.add(['a'], ['a-id'])
171
172
        dlg = CommitDialogNoWidgets(tree)
278.1.12 by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names.
173
        self.assertIs(None, dlg._delta)
174
        dlg._compute_delta()
175
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
176
        delta = dlg._delta
177
        self.assertEqual([], delta.modified)
178
        self.assertEqual([], delta.renamed)
179
        self.assertEqual([], delta.removed)
180
        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.
181
182
183
class TestCommitDialog(tests.TestCaseWithTransport):
184
185
    def test_no_pending(self):
186
        tree = self.make_branch_and_tree('tree')
187
        rev_id1 = tree.commit('one')
188
189
        dlg = commit.CommitDialog(tree)
190
        # TODO: assert that the pending box is hidden
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
191
        commit_col = dlg._treeview_files.get_column(0)
192
        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,
193
        renderer = commit_col.get_cell_renderers()[0]
194
        self.assertTrue(renderer.get_active())
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
195
196
    def test_pending(self):
197
        tree = self.make_branch_and_tree('tree')
198
        rev_id1 = tree.commit('one')
199
200
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
201
        rev_id2 = tree2.commit('two',
202
                               committer='Joe Foo <joe@foo.com>',
203
                               timestamp=1191264271.05,
204
                               timezone=+7200)
205
        tree.merge_from_branch(tree2.branch)
206
207
        dlg = commit.CommitDialog(tree)
208
        # TODO: assert that the pending box is set to show
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
209
        commit_col = dlg._treeview_files.get_column(0)
210
        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,
211
        renderer = commit_col.get_cell_renderers()[0]
212
        self.assertFalse(renderer.get_active())
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
213
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
214
        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.
215
        self.assertEqual([(rev_id2, '2007-10-01', 'Joe Foo', 'two')], values)
216
217
    def test_pending_multiple(self):
218
        tree = self.make_branch_and_tree('tree')
219
        rev_id1 = tree.commit('one')
220
221
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
222
        rev_id2 = tree2.commit('two',
223
                               committer='Joe Foo <joe@foo.com>',
224
                               timestamp=1191264271.05,
225
                               timezone=+7200)
226
        rev_id3 = tree2.commit('three',
227
                               committer='Jerry Foo <jerry@foo.com>',
228
                               timestamp=1191264278.05,
229
                               timezone=+7200)
230
        tree.merge_from_branch(tree2.branch)
231
        tree3 = tree.bzrdir.sprout('tree3').open_workingtree()
232
        rev_id4 = tree3.commit('four',
233
                               committer='Joe Foo <joe@foo.com>',
234
                               timestamp=1191264279.05,
235
                               timezone=+7200)
236
        rev_id5 = tree3.commit('five',
237
                               committer='Jerry Foo <jerry@foo.com>',
238
                               timestamp=1191372278.05,
239
                               timezone=+7200)
240
        tree.merge_from_branch(tree3.branch)
241
242
        dlg = commit.CommitDialog(tree)
243
        # TODO: assert that the pending box is set to show
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
244
        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.
245
        self.assertEqual([(rev_id3, '2007-10-01', 'Jerry Foo', 'three'),
246
                          (rev_id2, '2007-10-01', 'Joe Foo', 'two'),
247
                          (rev_id5, '2007-10-03', 'Jerry Foo', 'five'),
248
                          (rev_id4, '2007-10-01', 'Joe Foo', 'four'),
249
                         ], values)
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
250
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
251
    def test_filelist_added(self):
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
252
        tree = self.make_branch_and_tree('tree')
253
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
254
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
255
256
        dlg = commit.CommitDialog(tree)
257
        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,
258
        self.assertEqual([(None, None, True, 'All Files', ''),
259
                          ('a-id', 'a', True, 'a', 'added'),
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
260
                          ('b-id', 'b', True, 'b/', 'added'),
261
                          ('c-id', 'b/c', True, 'b/c', 'added'),
262
                         ], values)
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
263
264
    def test_filelist_renamed(self):
265
        tree = self.make_branch_and_tree('tree')
266
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
267
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
268
        rev_id1 = tree.commit('one')
269
270
        tree.rename_one('b', 'd')
271
        tree.rename_one('a', 'd/a')
272
273
        dlg = commit.CommitDialog(tree)
274
        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,
275
        self.assertEqual([(None, None, True, 'All Files', ''),
276
                          ('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
277
                          ('a-id', 'd/a', True, 'a => d/a', 'renamed'),
278
                         ], values)
279
280
    def test_filelist_modified(self):
281
        tree = self.make_branch_and_tree('tree')
282
        self.build_tree(['tree/a'])
283
        tree.add(['a'], ['a-id'])
284
        rev_id1 = tree.commit('one')
285
286
        self.build_tree_contents([('tree/a', 'new contents for a\n')])
287
288
        dlg = commit.CommitDialog(tree)
289
        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,
290
        self.assertEqual([(None, None, True, 'All Files', ''),
291
                          ('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
292
                         ], values)
293
294
    def test_filelist_renamed_and_modified(self):
295
        tree = self.make_branch_and_tree('tree')
296
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
297
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
298
        rev_id1 = tree.commit('one')
299
300
        tree.rename_one('b', 'd')
301
        tree.rename_one('a', 'd/a')
302
        self.build_tree_contents([('tree/d/a', 'new contents for a\n'),
303
                                  ('tree/d/c', 'new contents for c\n'),
304
                                 ])
305
        # 'c' is not considered renamed, because only its parent was moved, it
306
        # stayed in the same directory
307
308
        dlg = commit.CommitDialog(tree)
309
        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,
310
        self.assertEqual([(None, None, True, 'All Files', ''),
311
                          ('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
312
                          ('a-id', 'd/a', True, 'a => d/a', 'renamed and modified'),
313
                          ('c-id', 'd/c', True, 'd/c', 'modified'),
314
                         ], values)
315
316
    def test_filelist_kind_changed(self):
317
        tree = self.make_branch_and_tree('tree')
318
        self.build_tree(['tree/a', 'tree/b'])
319
        tree.add(['a', 'b'], ['a-id', 'b-id'])
320
        tree.commit('one')
321
322
        os.remove('tree/a')
323
        self.build_tree(['tree/a/'])
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
324
        # XXX:  This is technically valid, and the file list handles it fine,
325
        #       but 'show_diff_trees()' does not, so we skip this part of the
326
        #       test for now.
327
        # tree.rename_one('b', 'c')
328
        # os.remove('tree/c')
329
        # self.build_tree(['tree/c/'])
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
330
331
        dlg = commit.CommitDialog(tree)
332
        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,
333
        self.assertEqual([(None, None, True, 'All Files', ''),
334
                          ('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.
335
                          # ('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
336
                         ], values)
337
338
    def test_filelist_removed(self):
339
        tree = self.make_branch_and_tree('tree')
340
        self.build_tree(['tree/a', 'tree/b/'])
341
        tree.add(['a', 'b'], ['a-id', 'b-id'])
342
        tree.commit('one')
343
344
        os.remove('tree/a')
345
        tree.remove('b', force=True)
346
347
        dlg = commit.CommitDialog(tree)
348
        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,
349
        self.assertEqual([(None, None, True, 'All Files', ''),
350
                          ('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
351
                          ('b-id', 'b', True, 'b/', 'removed'),
352
                         ], values)
278.1.18 by John Arbash Meinel
Start checking the diff view is correct.
353
354
    def test_diff_view(self):
355
        tree = self.make_branch_and_tree('tree')
356
        self.build_tree(['tree/a', 'tree/b'])
357
        tree.add(['a', 'b'], ['a-id', 'b-id'])
358
        tree.commit('one')
359
360
        self.build_tree_contents([('tree/a', 'new contents for a\n')])
361
        tree.remove('b')
362
363
        dlg = commit.CommitDialog(tree)
364
        diff_buffer = dlg._diff_view.buffer
365
        text = diff_buffer.get_text(diff_buffer.get_start_iter(),
366
                                    diff_buffer.get_end_iter()).splitlines(True)
367
368
        self.assertEqual("=== removed file 'b'\n", text[0])
369
        self.assertContainsRe(text[1],
370
            r"--- b\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
371
        self.assertEqual('+++ b\t1970-01-01 00:00:00 +0000\n', text[2])
372
        self.assertEqual('@@ -1,1 +0,0 @@\n', text[3])
373
        self.assertEqual('-contents of tree/b\n', text[4])
374
        self.assertEqual('\n', text[5])
375
376
        self.assertEqual("=== modified file 'a'\n", text[6])
377
        self.assertContainsRe(text[7],
378
            r"--- a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
379
        self.assertContainsRe(text[8],
380
            r"\+\+\+ a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
381
        self.assertEqual('@@ -1,1 +1,1 @@\n', text[9])
382
        self.assertEqual('-contents of tree/a\n', text[10])
383
        self.assertEqual('+new contents for a\n', text[11])
384
        self.assertEqual('\n', text[12])
385
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
386
        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.
387
388
    def test_file_selection(self):
389
        """Several things should happen when a file has been selected."""
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)
395
        diff_buffer = dlg._diff_view.buffer
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
396
        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.
397
        self.assertEqual('File commit message',
398
                         dlg._file_message_expander.get_label())
399
        self.assertFalse(dlg._file_message_expander.get_expanded())
400
        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.
401
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
402
        dlg._treeview_files.set_cursor((1,))
278.1.19 by John Arbash Meinel
Test what happens when a specific file is selected.
403
        self.assertEqual('Diff for a', dlg._diff_label.get_text())
404
        text = diff_buffer.get_text(diff_buffer.get_start_iter(),
405
                                    diff_buffer.get_end_iter()).splitlines(True)
406
        self.assertEqual("=== added file 'a'\n", text[0])
407
        self.assertContainsRe(text[1],
408
            r"--- a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
409
        self.assertContainsRe(text[2],
410
            r"\+\+\+ a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
411
        self.assertEqual('@@ -0,0 +1,1 @@\n', text[3])
412
        self.assertEqual('+contents of tree/a\n', text[4])
413
        self.assertEqual('\n', text[5])
278.1.21 by John Arbash Meinel
Start tracking the per-file commit messages.
414
        self.assertEqual('Commit message for a',
415
                         dlg._file_message_expander.get_label())
416
        self.assertTrue(dlg._file_message_expander.get_expanded())
417
        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.
418
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
419
        dlg._treeview_files.set_cursor((2,))
278.1.19 by John Arbash Meinel
Test what happens when a specific file is selected.
420
        self.assertEqual('Diff for b', dlg._diff_label.get_text())
421
        text = diff_buffer.get_text(diff_buffer.get_start_iter(),
422
                                    diff_buffer.get_end_iter()).splitlines(True)
423
        self.assertEqual("=== added file 'b'\n", text[0])
424
        self.assertContainsRe(text[1],
425
            r"--- b\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
426
        self.assertContainsRe(text[2],
427
            r"\+\+\+ b\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
428
        self.assertEqual('@@ -0,0 +1,1 @@\n', text[3])
429
        self.assertEqual('+contents of tree/b\n', text[4])
430
        self.assertEqual('\n', text[5])
278.1.21 by John Arbash Meinel
Start tracking the per-file commit messages.
431
        self.assertEqual('Commit message for b',
432
                         dlg._file_message_expander.get_label())
433
        self.assertTrue(dlg._file_message_expander.get_expanded())
434
        self.assertTrue(dlg._file_message_expander.get_property('sensitive'))
435
436
        dlg._treeview_files.set_cursor((0,))
437
        self.assertEqual('Diff for All Files', dlg._diff_label.get_text())
438
        self.assertEqual('File commit message',
439
                         dlg._file_message_expander.get_label())
440
        self.assertFalse(dlg._file_message_expander.get_expanded())
441
        self.assertFalse(dlg._file_message_expander.get_property('sensitive'))
442
443
    def test_file_selection_message(self):
444
        """Selecting a file should bring up its commit message."""
445
        tree = self.make_branch_and_tree('tree')
446
        self.build_tree(['tree/a', 'tree/b/'])
447
        tree.add(['a', 'b'], ['a-id', 'b-id'])
448
449
        def get_file_text():
450
            buf = dlg._file_message_text_view.get_buffer()
451
            return buf.get_text(buf.get_start_iter(), buf.get_end_iter())
452
453
        def get_saved_text(path):
454
            """Get the saved text for a given record."""
455
            return dlg._files_store.get_value(dlg._files_store.get_iter(path), 5)
456
457
        dlg = commit.CommitDialog(tree)
458
        self.assertEqual('File commit message',
459
                         dlg._file_message_expander.get_label())
460
        self.assertFalse(dlg._file_message_expander.get_expanded())
461
        self.assertFalse(dlg._file_message_expander.get_property('sensitive'))
462
        self.assertEqual('', get_file_text())
463
464
        dlg._treeview_files.set_cursor((1,))
465
        self.assertEqual('Commit message for a',
466
                         dlg._file_message_expander.get_label())
467
        self.assertTrue(dlg._file_message_expander.get_expanded())
468
        self.assertTrue(dlg._file_message_expander.get_property('sensitive'))
469
        self.assertEqual('', get_file_text())
470
471
        self.assertEqual('', get_saved_text(1))
472
        dlg._file_message_text_view.get_buffer().set_text('Some text\nfor a\n')
473
        dlg._save_current_file_message()
474
        # We should have updated the ListStore with the new file commit info
475
        self.assertEqual('Some text\nfor a\n', get_saved_text(1))
476
477
        dlg._treeview_files.set_cursor((2,))
478
        self.assertEqual('Commit message for b/',
479
                         dlg._file_message_expander.get_label())
480
        self.assertTrue(dlg._file_message_expander.get_expanded())
481
        self.assertTrue(dlg._file_message_expander.get_property('sensitive'))
482
        self.assertEqual('', get_file_text())
483
484
        self.assertEqual('', get_saved_text(2))
485
        dlg._file_message_text_view.get_buffer().set_text('More text\nfor b\n')
486
        # Now switch back to 'a'. The message should be saved, and the buffer
487
        # should be updated with the other text
488
        dlg._treeview_files.set_cursor((1,))
489
        self.assertEqual('More text\nfor b\n', get_saved_text(2))
490
        self.assertEqual('Commit message for a',
491
                         dlg._file_message_expander.get_label())
492
        self.assertTrue(dlg._file_message_expander.get_expanded())
493
        self.assertTrue(dlg._file_message_expander.get_property('sensitive'))
494
        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,
495
496
    def test_toggle_all_files(self):
497
        """When checking the All Files entry, it should toggle all fields"""
498
        tree = self.make_branch_and_tree('tree')
499
        self.build_tree(['tree/a', 'tree/b/'])
500
        tree.add(['a', 'b'], ['a-id', 'b-id'])
501
502
        dlg = commit.CommitDialog(tree)
503
        self.assertEqual([(None, None, True),
504
                          ('a-id', 'a', True),
505
                          ('b-id', 'b', True),
506
                         ], [(r[0], r[1], r[2]) for r in dlg._files_store])
507
508
        # TODO: jam 20071002 I'm not sure how to exactly trigger a toggle, it
509
        #       looks like we need to call renderer.activate() and pass an
510
        #       event and widget, and lots of other stuff I'm not sure what to
511
        #       do with. So instead, we just call toggle directly, and assume
512
        #       that toggle is hooked in correctly
513
        # column = dlg._treeview_files.get_column(0)
514
        # renderer = column.get_cell_renderers()[0]
515
516
        # Toggle a single entry should set just that entry to False
517
        dlg._toggle_commit(None, 1, dlg._files_store)
518
        self.assertEqual([(None, None, True),
519
                          ('a-id', 'a', False),
520
                          ('b-id', 'b', True),
521
                         ], [(r[0], r[1], r[2]) for r in dlg._files_store])
522
523
        # Toggling the main entry should set all entries
524
        dlg._toggle_commit(None, 0, dlg._files_store)
525
        self.assertEqual([(None, None, False),
526
                          ('a-id', 'a', False),
527
                          ('b-id', 'b', False),
528
                         ], [(r[0], r[1], r[2]) for r in dlg._files_store])
529
530
        dlg._toggle_commit(None, 2, dlg._files_store)
531
        self.assertEqual([(None, None, False),
532
                          ('a-id', 'a', False),
533
                          ('b-id', 'b', True),
534
                         ], [(r[0], r[1], r[2]) for r in dlg._files_store])
535
536
        dlg._toggle_commit(None, 0, dlg._files_store)
537
        self.assertEqual([(None, None, True),
538
                          ('a-id', 'a', True),
539
                          ('b-id', 'b', True),
540
                         ], [(r[0], r[1], r[2]) for r in dlg._files_store])
278.1.23 by John Arbash Meinel
Beginning to support actual commit.
541
542
543
class TestCommitDialog_Commit(tests.TestCaseWithTransport):
544
    """Tests on the actual 'commit' button being pushed."""
545
546
    def test_commit_no_message(self):
547
        tree = self.make_branch_and_tree('tree')
548
        self.build_tree(['tree/a', 'tree/b'])
549
        tree.add(['a'], ['a-id'])
550
        rev_id = tree.commit('one')
551
552
        tree.add(['b'], ['b-id'])
553
554
        dlg = commit.CommitDialog(tree)
555
        questions = []
556
        def _question_cancel(*args):
557
            questions.append(args)
558
            questions.append('NO')
559
            return gtk.RESPONSE_NO
560
561
        def _question_ok(*args):
562
            questions.append(args)
563
            questions.append('OK')
564
            return gtk.RESPONSE_OK
565
566
        dlg._question_dialog = _question_cancel
567
        dlg._do_commit()
568
        self.assertEqual(
569
            [('Commit with an empty message?',
570
              'You can describe your commit intent in the message.'),
571
              'NO',
572
            ], questions)
573
        # By saying NO, nothing should be committed.
574
        self.assertEqual(rev_id, tree.last_revision())
575
        self.assertIs(None, dlg.committed_revision_id)
576
577
        dlg._question_dialog = _question_ok
578
        del questions[:]
579
580
        dlg._do_commit()
581
        self.assertEqual(
582
            [('Commit with an empty message?',
583
              'You can describe your commit intent in the message.'),
584
              'OK',
585
            ], questions)
586
        committed = tree.last_revision()
587
        self.assertNotEqual(rev_id, committed)
588
        self.assertEqual(committed, dlg.committed_revision_id)
589
590
    def test_initial_commit(self):
591
        tree = self.make_branch_and_tree('tree')
592
        self.build_tree(['tree/a'])
593
        tree.add(['a'], ['a-id'])
594
595
        dlg = commit.CommitDialog(tree)
596
        dlg._global_message_text_view.get_buffer().set_text('Some text\n')
597
        dlg._do_commit()
598
599
        last_rev = tree.last_revision()
600
        self.assertEqual(last_rev, dlg.committed_revision_id)
601
        rev = tree.branch.repository.get_revision(last_rev)
602
        self.assertEqual(last_rev, rev.revision_id)
603
        self.assertEqual('Some text\n', rev.message)