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  | 
||
| 
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 (  | 
| 
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(),  | 
|
416  | 
diff_buffer.get_end_iter()).splitlines(True)  | 
|
417  | 
||
| 
483
by Jelmer Vernooij
 Fix diff test.  | 
418  | 
self.assertEqual("=== modified file 'a'\n", text[0])  | 
| 
278.1.18
by John Arbash Meinel
 Start checking the diff view is correct.  | 
419  | 
self.assertContainsRe(text[1],  | 
420  | 
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.  | 
421  | 
self.assertContainsRe(text[2],  | 
422  | 
r"\+\+\+ a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")  | 
|
423  | 
self.assertEqual('@@ -1,1 +1,1 @@\n', text[3])  | 
|
424  | 
self.assertEqual('-contents of tree/a\n', text[4])  | 
|
425  | 
self.assertEqual('+new contents for a\n', text[5])  | 
|
426  | 
self.assertEqual('\n', text[6])  | 
|
427  | 
||
428  | 
self.assertEqual("=== removed file 'b'\n", text[7])  | 
|
| 
278.1.18
by John Arbash Meinel
 Start checking the diff view is correct.  | 
429  | 
self.assertContainsRe(text[8],  | 
| 
483
by Jelmer Vernooij
 Fix diff test.  | 
430  | 
r"--- b\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")  | 
431  | 
self.assertEqual('+++ b\t1970-01-01 00:00:00 +0000\n', text[9])  | 
|
432  | 
self.assertEqual('@@ -1,1 +0,0 @@\n', text[10])  | 
|
433  | 
self.assertEqual('-contents of tree/b\n', text[11])  | 
|
| 
278.1.18
by John Arbash Meinel
 Start checking the diff view is correct.  | 
434  | 
self.assertEqual('\n', text[12])  | 
435  | 
||
| 
278.1.20
by John Arbash Meinel
 We always select the All Files record in the files view,  | 
436  | 
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.  | 
437  | 
|
| 
278.1.43
by John Arbash Meinel
 Finish connecting the 'Commit all changes' radio buttons.  | 
438  | 
def test_commit_partial_toggle(self):  | 
439  | 
tree = self.make_branch_and_tree('tree')  | 
|
440  | 
self.build_tree(['tree/a', 'tree/b'])  | 
|
441  | 
tree.add(['a', 'b'], ['a-id', 'b-id'])  | 
|
442  | 
||
443  | 
dlg = commit.CommitDialog(tree)  | 
|
444  | 
checked_col = dlg._treeview_files.get_column(0)  | 
|
445  | 
self.assertFalse(checked_col.get_property('visible'))  | 
|
446  | 
self.assertTrue(dlg._commit_all_changes)  | 
|
447  | 
||
448  | 
dlg._commit_selected_radio.set_active(True)  | 
|
449  | 
self.assertTrue(checked_col.get_property('visible'))  | 
|
450  | 
self.assertFalse(dlg._commit_all_changes)  | 
|
451  | 
||
| 
278.1.19
by John Arbash Meinel
 Test what happens when a specific file is selected.  | 
452  | 
def test_file_selection(self):  | 
453  | 
"""Several things should happen when a file has been selected."""  | 
|
454  | 
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.  | 
455  | 
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.  | 
456  | 
self.build_tree(['tree/a', 'tree/b'])  | 
457  | 
tree.add(['a', 'b'], ['a-id', 'b-id'])  | 
|
458  | 
||
459  | 
dlg = commit.CommitDialog(tree)  | 
|
460  | 
diff_buffer = dlg._diff_view.buffer  | 
|
| 
278.1.20
by John Arbash Meinel
 We always select the All Files record in the files view,  | 
461  | 
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.  | 
462  | 
self.assertEqual('File commit message',  | 
463  | 
dlg._file_message_expander.get_label())  | 
|
464  | 
self.assertFalse(dlg._file_message_expander.get_expanded())  | 
|
465  | 
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.  | 
466  | 
|
| 
278.1.20
by John Arbash Meinel
 We always select the All Files record in the files view,  | 
467  | 
dlg._treeview_files.set_cursor((1,))  | 
| 
278.1.19
by John Arbash Meinel
 Test what happens when a specific file is selected.  | 
468  | 
self.assertEqual('Diff for a', dlg._diff_label.get_text())  | 
469  | 
text = diff_buffer.get_text(diff_buffer.get_start_iter(),  | 
|
470  | 
diff_buffer.get_end_iter()).splitlines(True)  | 
|
471  | 
self.assertEqual("=== added file 'a'\n", text[0])  | 
|
472  | 
self.assertContainsRe(text[1],  | 
|
473  | 
r"--- a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")  | 
|
474  | 
self.assertContainsRe(text[2],  | 
|
475  | 
r"\+\+\+ a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")  | 
|
476  | 
self.assertEqual('@@ -0,0 +1,1 @@\n', text[3])  | 
|
477  | 
self.assertEqual('+contents of tree/a\n', text[4])  | 
|
478  | 
self.assertEqual('\n', text[5])  | 
|
| 
278.1.21
by John Arbash Meinel
 Start tracking the per-file commit messages.  | 
479  | 
self.assertEqual('Commit message for a',  | 
480  | 
dlg._file_message_expander.get_label())  | 
|
481  | 
self.assertTrue(dlg._file_message_expander.get_expanded())  | 
|
482  | 
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.  | 
483  | 
|
| 
278.1.20
by John Arbash Meinel
 We always select the All Files record in the files view,  | 
484  | 
dlg._treeview_files.set_cursor((2,))  | 
| 
278.1.19
by John Arbash Meinel
 Test what happens when a specific file is selected.  | 
485  | 
self.assertEqual('Diff for b', dlg._diff_label.get_text())  | 
486  | 
text = diff_buffer.get_text(diff_buffer.get_start_iter(),  | 
|
487  | 
diff_buffer.get_end_iter()).splitlines(True)  | 
|
488  | 
self.assertEqual("=== added file 'b'\n", text[0])  | 
|
489  | 
self.assertContainsRe(text[1],  | 
|
490  | 
r"--- b\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")  | 
|
491  | 
self.assertContainsRe(text[2],  | 
|
492  | 
r"\+\+\+ b\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")  | 
|
493  | 
self.assertEqual('@@ -0,0 +1,1 @@\n', text[3])  | 
|
494  | 
self.assertEqual('+contents of tree/b\n', text[4])  | 
|
495  | 
self.assertEqual('\n', text[5])  | 
|
| 
278.1.21
by John Arbash Meinel
 Start tracking the per-file commit messages.  | 
496  | 
self.assertEqual('Commit message for b',  | 
497  | 
dlg._file_message_expander.get_label())  | 
|
498  | 
self.assertTrue(dlg._file_message_expander.get_expanded())  | 
|
499  | 
self.assertTrue(dlg._file_message_expander.get_property('sensitive'))  | 
|
500  | 
||
501  | 
dlg._treeview_files.set_cursor((0,))  | 
|
502  | 
self.assertEqual('Diff for All Files', dlg._diff_label.get_text())  | 
|
503  | 
self.assertEqual('File commit message',  | 
|
504  | 
dlg._file_message_expander.get_label())  | 
|
505  | 
self.assertFalse(dlg._file_message_expander.get_expanded())  | 
|
506  | 
self.assertFalse(dlg._file_message_expander.get_property('sensitive'))  | 
|
507  | 
||
508  | 
def test_file_selection_message(self):  | 
|
509  | 
"""Selecting a file should bring up its commit message."""  | 
|
510  | 
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.  | 
511  | 
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.  | 
512  | 
self.build_tree(['tree/a', 'tree/b/'])  | 
513  | 
tree.add(['a', 'b'], ['a-id', 'b-id'])  | 
|
514  | 
||
515  | 
def get_file_text():  | 
|
516  | 
buf = dlg._file_message_text_view.get_buffer()  | 
|
517  | 
return buf.get_text(buf.get_start_iter(), buf.get_end_iter())  | 
|
518  | 
||
519  | 
def get_saved_text(path):  | 
|
520  | 
"""Get the saved text for a given record."""  | 
|
521  | 
return dlg._files_store.get_value(dlg._files_store.get_iter(path), 5)  | 
|
522  | 
||
523  | 
dlg = commit.CommitDialog(tree)  | 
|
524  | 
self.assertEqual('File commit message',  | 
|
525  | 
dlg._file_message_expander.get_label())  | 
|
526  | 
self.assertFalse(dlg._file_message_expander.get_expanded())  | 
|
527  | 
self.assertFalse(dlg._file_message_expander.get_property('sensitive'))  | 
|
528  | 
self.assertEqual('', get_file_text())  | 
|
529  | 
||
530  | 
dlg._treeview_files.set_cursor((1,))  | 
|
531  | 
self.assertEqual('Commit message for a',  | 
|
532  | 
dlg._file_message_expander.get_label())  | 
|
533  | 
self.assertTrue(dlg._file_message_expander.get_expanded())  | 
|
534  | 
self.assertTrue(dlg._file_message_expander.get_property('sensitive'))  | 
|
535  | 
self.assertEqual('', get_file_text())  | 
|
536  | 
||
537  | 
self.assertEqual('', get_saved_text(1))  | 
|
| 
278.1.27
by John Arbash Meinel
 Add the ability to commit just specific files.  | 
538  | 
dlg._set_file_commit_message('Some text\nfor a\n')  | 
| 
278.1.21
by John Arbash Meinel
 Start tracking the per-file commit messages.  | 
539  | 
dlg._save_current_file_message()  | 
540  | 
        # We should have updated the ListStore with the new file commit info
 | 
|
541  | 
self.assertEqual('Some text\nfor a\n', get_saved_text(1))  | 
|
542  | 
||
543  | 
dlg._treeview_files.set_cursor((2,))  | 
|
544  | 
self.assertEqual('Commit message for b/',  | 
|
545  | 
dlg._file_message_expander.get_label())  | 
|
546  | 
self.assertTrue(dlg._file_message_expander.get_expanded())  | 
|
547  | 
self.assertTrue(dlg._file_message_expander.get_property('sensitive'))  | 
|
548  | 
self.assertEqual('', get_file_text())  | 
|
549  | 
||
550  | 
self.assertEqual('', get_saved_text(2))  | 
|
| 
278.1.27
by John Arbash Meinel
 Add the ability to commit just specific files.  | 
551  | 
dlg._set_file_commit_message('More text\nfor b\n')  | 
| 
278.1.21
by John Arbash Meinel
 Start tracking the per-file commit messages.  | 
552  | 
        # Now switch back to 'a'. The message should be saved, and the buffer
 | 
553  | 
        # should be updated with the other text
 | 
|
554  | 
dlg._treeview_files.set_cursor((1,))  | 
|
555  | 
self.assertEqual('More text\nfor b\n', get_saved_text(2))  | 
|
556  | 
self.assertEqual('Commit message for a',  | 
|
557  | 
dlg._file_message_expander.get_label())  | 
|
558  | 
self.assertTrue(dlg._file_message_expander.get_expanded())  | 
|
559  | 
self.assertTrue(dlg._file_message_expander.get_property('sensitive'))  | 
|
560  | 
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,  | 
561  | 
|
562  | 
def test_toggle_all_files(self):  | 
|
563  | 
"""When checking the All Files entry, it should toggle all fields"""  | 
|
564  | 
tree = self.make_branch_and_tree('tree')  | 
|
565  | 
self.build_tree(['tree/a', 'tree/b/'])  | 
|
566  | 
tree.add(['a', 'b'], ['a-id', 'b-id'])  | 
|
567  | 
||
568  | 
dlg = commit.CommitDialog(tree)  | 
|
569  | 
self.assertEqual([(None, None, True),  | 
|
570  | 
('a-id', 'a', True),  | 
|
571  | 
('b-id', 'b', True),  | 
|
572  | 
], [(r[0], r[1], r[2]) for r in dlg._files_store])  | 
|
573  | 
||
574  | 
        # TODO: jam 20071002 I'm not sure how to exactly trigger a toggle, it
 | 
|
575  | 
        #       looks like we need to call renderer.activate() and pass an
 | 
|
576  | 
        #       event and widget, and lots of other stuff I'm not sure what to
 | 
|
577  | 
        #       do with. So instead, we just call toggle directly, and assume
 | 
|
578  | 
        #       that toggle is hooked in correctly
 | 
|
579  | 
        # column = dlg._treeview_files.get_column(0)
 | 
|
580  | 
        # renderer = column.get_cell_renderers()[0]
 | 
|
581  | 
||
582  | 
        # Toggle a single entry should set just that entry to False
 | 
|
583  | 
dlg._toggle_commit(None, 1, dlg._files_store)  | 
|
584  | 
self.assertEqual([(None, None, True),  | 
|
585  | 
('a-id', 'a', False),  | 
|
586  | 
('b-id', 'b', True),  | 
|
587  | 
], [(r[0], r[1], r[2]) for r in dlg._files_store])  | 
|
588  | 
||
589  | 
        # Toggling the main entry should set all entries
 | 
|
590  | 
dlg._toggle_commit(None, 0, dlg._files_store)  | 
|
591  | 
self.assertEqual([(None, None, False),  | 
|
592  | 
('a-id', 'a', False),  | 
|
593  | 
('b-id', 'b', False),  | 
|
594  | 
], [(r[0], r[1], r[2]) for r in dlg._files_store])  | 
|
595  | 
||
596  | 
dlg._toggle_commit(None, 2, dlg._files_store)  | 
|
597  | 
self.assertEqual([(None, None, False),  | 
|
598  | 
('a-id', 'a', False),  | 
|
599  | 
('b-id', 'b', True),  | 
|
600  | 
], [(r[0], r[1], r[2]) for r in dlg._files_store])  | 
|
601  | 
||
602  | 
dlg._toggle_commit(None, 0, dlg._files_store)  | 
|
603  | 
self.assertEqual([(None, None, True),  | 
|
604  | 
('a-id', 'a', True),  | 
|
605  | 
('b-id', 'b', True),  | 
|
606  | 
], [(r[0], r[1], r[2]) for r in dlg._files_store])  | 
|
| 
278.1.23
by John Arbash Meinel
 Beginning to support actual commit.  | 
607  | 
|
| 
278.1.27
by John Arbash Meinel
 Add the ability to commit just specific files.  | 
608  | 
def test_specific_files(self):  | 
609  | 
tree = self.make_branch_and_tree('tree')  | 
|
610  | 
self.build_tree(['tree/a', 'tree/b/'])  | 
|
611  | 
tree.add(['a', 'b'], ['a-id', 'b-id'])  | 
|
612  | 
||
613  | 
dlg = commit.CommitDialog(tree)  | 
|
614  | 
self.assertEqual((['a', 'b'], []), dlg._get_specific_files())  | 
|
615  | 
||
| 
278.1.43
by John Arbash Meinel
 Finish connecting the 'Commit all changes' radio buttons.  | 
616  | 
dlg._commit_selected_radio.set_active(True)  | 
| 
278.1.27
by John Arbash Meinel
 Add the ability to commit just specific files.  | 
617  | 
dlg._toggle_commit(None, 0, dlg._files_store)  | 
618  | 
self.assertEqual(([], []), dlg._get_specific_files())  | 
|
619  | 
||
620  | 
dlg._toggle_commit(None, 1, dlg._files_store)  | 
|
621  | 
self.assertEqual((['a'], []), dlg._get_specific_files())  | 
|
622  | 
||
623  | 
def test_specific_files_with_messages(self):  | 
|
624  | 
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.  | 
625  | 
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.  | 
626  | 
self.build_tree(['tree/a_file', 'tree/b_dir/'])  | 
627  | 
tree.add(['a_file', 'b_dir'], ['1a-id', '0b-id'])  | 
|
628  | 
||
629  | 
dlg = commit.CommitDialog(tree)  | 
|
| 
278.1.43
by John Arbash Meinel
 Finish connecting the 'Commit all changes' radio buttons.  | 
630  | 
dlg._commit_selected_radio.set_active(True)  | 
| 
278.1.27
by John Arbash Meinel
 Add the ability to commit just specific files.  | 
631  | 
self.assertEqual((['a_file', 'b_dir'], []), dlg._get_specific_files())  | 
632  | 
||
633  | 
dlg._treeview_files.set_cursor((1,))  | 
|
634  | 
dlg._set_file_commit_message('Test\nmessage\nfor a_file\n')  | 
|
635  | 
dlg._treeview_files.set_cursor((2,))  | 
|
636  | 
dlg._set_file_commit_message('message\nfor b_dir\n')  | 
|
637  | 
||
638  | 
self.assertEqual((['a_file', 'b_dir'],  | 
|
639  | 
[{'path':'a_file', 'file_id':'1a-id',  | 
|
640  | 
'message':'Test\nmessage\nfor a_file\n'},  | 
|
641  | 
{'path':'b_dir', 'file_id':'0b-id',  | 
|
642  | 
'message':'message\nfor b_dir\n'},  | 
|
643  | 
]), dlg._get_specific_files())  | 
|
644  | 
||
645  | 
dlg._toggle_commit(None, 1, dlg._files_store)  | 
|
646  | 
self.assertEqual((['b_dir'],  | 
|
647  | 
[{'path':'b_dir', 'file_id':'0b-id',  | 
|
648  | 
'message':'message\nfor b_dir\n'},  | 
|
649  | 
]), dlg._get_specific_files())  | 
|
650  | 
||
| 
622.1.1
by John Arbash Meinel
 Ensure that per-file commit messages and global commit messages get sanitized.  | 
651  | 
def test_specific_files_sanitizes_messages(self):  | 
652  | 
tree = self.make_branch_and_tree('tree')  | 
|
653  | 
tree.branch.get_config().set_user_option('per_file_commits', 'true')  | 
|
654  | 
self.build_tree(['tree/a_file', 'tree/b_dir/'])  | 
|
655  | 
tree.add(['a_file', 'b_dir'], ['1a-id', '0b-id'])  | 
|
656  | 
||
657  | 
dlg = commit.CommitDialog(tree)  | 
|
658  | 
dlg._commit_selected_radio.set_active(True)  | 
|
659  | 
self.assertEqual((['a_file', 'b_dir'], []), dlg._get_specific_files())  | 
|
660  | 
||
661  | 
dlg._treeview_files.set_cursor((1,))  | 
|
662  | 
dlg._set_file_commit_message('Test\r\nmessage\rfor a_file\n')  | 
|
663  | 
dlg._treeview_files.set_cursor((2,))  | 
|
664  | 
dlg._set_file_commit_message('message\r\nfor\nb_dir\r')  | 
|
665  | 
||
666  | 
self.assertEqual((['a_file', 'b_dir'],  | 
|
667  | 
[{'path':'a_file', 'file_id':'1a-id',  | 
|
668  | 
'message':'Test\nmessage\nfor a_file\n'},  | 
|
669  | 
{'path':'b_dir', 'file_id':'0b-id',  | 
|
670  | 
'message':'message\nfor\nb_dir\n'},  | 
|
671  | 
]), dlg._get_specific_files())  | 
|
672  | 
||
| 
278.1.23
by John Arbash Meinel
 Beginning to support actual commit.  | 
673  | 
|
| 
635.2.10
by Vincent Ladeuil
 Complete tests around saved commit messages.  | 
674  | 
class QuestionHelpers(object):  | 
| 
278.1.23
by John Arbash Meinel
 Beginning to support actual commit.  | 
675  | 
|
| 
278.1.26
by John Arbash Meinel
 Handle pointless commits and trees with unknown files.  | 
676  | 
def _set_question_yes(self, dlg):  | 
677  | 
"""Set the dialog to answer YES to any questions."""  | 
|
678  | 
self.questions = []  | 
|
| 
606
by Vincent Ladeuil
 Fix gtk dialogs popping up and asking for input during selftest.  | 
679  | 
def _question_yes(*args, **kwargs):  | 
| 
278.1.26
by John Arbash Meinel
 Handle pointless commits and trees with unknown files.  | 
680  | 
self.questions.append(args)  | 
681  | 
self.questions.append('YES')  | 
|
682  | 
return gtk.RESPONSE_YES  | 
|
683  | 
dlg._question_dialog = _question_yes  | 
|
684  | 
||
685  | 
def _set_question_no(self, dlg):  | 
|
686  | 
"""Set the dialog to answer NO to any questions."""  | 
|
687  | 
self.questions = []  | 
|
| 
606
by Vincent Ladeuil
 Fix gtk dialogs popping up and asking for input during selftest.  | 
688  | 
def _question_no(*args, **kwargs):  | 
| 
278.1.26
by John Arbash Meinel
 Handle pointless commits and trees with unknown files.  | 
689  | 
self.questions.append(args)  | 
690  | 
self.questions.append('NO')  | 
|
691  | 
return gtk.RESPONSE_NO  | 
|
692  | 
dlg._question_dialog = _question_no  | 
|
693  | 
||
| 
635.2.10
by Vincent Ladeuil
 Complete tests around saved commit messages.  | 
694  | 
|
695  | 
class TestCommitDialog_Commit(tests.TestCaseWithTransport, QuestionHelpers):  | 
|
696  | 
"""Tests on the actual 'commit' button being pushed."""  | 
|
697  | 
||
| 
278.1.25
by John Arbash Meinel
 Add the 'Only Commit Locally' checkbox, we may want to put it elsewhere, though.  | 
698  | 
def test_bound_commit_local(self):  | 
699  | 
tree = self.make_branch_and_tree('tree')  | 
|
700  | 
self.build_tree(['tree/a'])  | 
|
701  | 
tree.add(['a'], ['a-id'])  | 
|
702  | 
rev_id1 = tree.commit('one')  | 
|
703  | 
||
704  | 
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()  | 
|
705  | 
self.build_tree(['tree2/b'])  | 
|
706  | 
tree2.add(['b'], ['b-id'])  | 
|
707  | 
tree2.branch.bind(tree.branch)  | 
|
708  | 
||
709  | 
dlg = commit.CommitDialog(tree2)  | 
|
710  | 
        # With the check box set, it should only effect the local branch
 | 
|
711  | 
dlg._check_local.set_active(True)  | 
|
712  | 
dlg._set_global_commit_message('Commit message\n')  | 
|
713  | 
dlg._do_commit()  | 
|
714  | 
||
715  | 
last_rev = tree2.last_revision()  | 
|
716  | 
self.assertEqual(last_rev, dlg.committed_revision_id)  | 
|
717  | 
self.assertEqual(rev_id1, tree.branch.last_revision())  | 
|
718  | 
||
| 
622.1.1
by John Arbash Meinel
 Ensure that per-file commit messages and global commit messages get sanitized.  | 
719  | 
def test_commit_global_sanitizes_message(self):  | 
720  | 
tree = self.make_branch_and_tree('tree')  | 
|
721  | 
self.build_tree(['tree/a'])  | 
|
722  | 
tree.add(['a'], ['a-id'])  | 
|
723  | 
rev_id1 = tree.commit('one')  | 
|
724  | 
||
725  | 
self.build_tree(['tree/b'])  | 
|
726  | 
tree.add(['b'], ['b-id'])  | 
|
727  | 
dlg = commit.CommitDialog(tree)  | 
|
728  | 
        # With the check box set, it should only effect the local branch
 | 
|
729  | 
dlg._set_global_commit_message('Commit\r\nmessage\rfoo\n')  | 
|
730  | 
dlg._do_commit()  | 
|
731  | 
rev = tree.branch.repository.get_revision(tree.last_revision())  | 
|
732  | 
self.assertEqual('Commit\nmessage\nfoo\n', rev.message)  | 
|
733  | 
||
| 
278.1.25
by John Arbash Meinel
 Add the 'Only Commit Locally' checkbox, we may want to put it elsewhere, though.  | 
734  | 
def test_bound_commit_both(self):  | 
735  | 
tree = self.make_branch_and_tree('tree')  | 
|
736  | 
self.build_tree(['tree/a'])  | 
|
737  | 
tree.add(['a'], ['a-id'])  | 
|
738  | 
rev_id1 = tree.commit('one')  | 
|
739  | 
||
740  | 
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()  | 
|
741  | 
self.build_tree(['tree2/b'])  | 
|
742  | 
tree2.add(['b'], ['b-id'])  | 
|
743  | 
tree2.branch.bind(tree.branch)  | 
|
744  | 
||
745  | 
dlg = commit.CommitDialog(tree2)  | 
|
746  | 
        # With the check box set, it should only effect the local branch
 | 
|
747  | 
dlg._check_local.set_active(False)  | 
|
748  | 
dlg._set_global_commit_message('Commit message\n')  | 
|
749  | 
dlg._do_commit()  | 
|
750  | 
||
751  | 
last_rev = tree2.last_revision()  | 
|
752  | 
self.assertEqual(last_rev, dlg.committed_revision_id)  | 
|
753  | 
self.assertEqual(last_rev, tree.branch.last_revision())  | 
|
754  | 
||
| 
606
by Vincent Ladeuil
 Fix gtk dialogs popping up and asking for input during selftest.  | 
755  | 
def test_commit_empty_message(self):  | 
| 
278.1.23
by John Arbash Meinel
 Beginning to support actual commit.  | 
756  | 
tree = self.make_branch_and_tree('tree')  | 
757  | 
self.build_tree(['tree/a', 'tree/b'])  | 
|
758  | 
tree.add(['a'], ['a-id'])  | 
|
759  | 
rev_id = tree.commit('one')  | 
|
760  | 
||
761  | 
tree.add(['b'], ['b-id'])  | 
|
762  | 
||
763  | 
dlg = commit.CommitDialog(tree)  | 
|
| 
278.1.26
by John Arbash Meinel
 Handle pointless commits and trees with unknown files.  | 
764  | 
self._set_question_no(dlg)  | 
| 
278.1.23
by John Arbash Meinel
 Beginning to support actual commit.  | 
765  | 
dlg._do_commit()  | 
766  | 
self.assertEqual(  | 
|
767  | 
[('Commit with an empty message?',  | 
|
768  | 
'You can describe your commit intent in the message.'),  | 
|
769  | 
'NO',  | 
|
| 
278.1.26
by John Arbash Meinel
 Handle pointless commits and trees with unknown files.  | 
770  | 
], self.questions)  | 
| 
278.1.23
by John Arbash Meinel
 Beginning to support actual commit.  | 
771  | 
        # By saying NO, nothing should be committed.
 | 
772  | 
self.assertEqual(rev_id, tree.last_revision())  | 
|
773  | 
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.  | 
774  | 
self.assertTrue(dlg._global_message_text_view.get_property('is-focus'))  | 
| 
278.1.23
by John Arbash Meinel
 Beginning to support actual commit.  | 
775  | 
|
| 
278.1.26
by John Arbash Meinel
 Handle pointless commits and trees with unknown files.  | 
776  | 
self._set_question_yes(dlg)  | 
| 
278.1.23
by John Arbash Meinel
 Beginning to support actual commit.  | 
777  | 
|
778  | 
dlg._do_commit()  | 
|
779  | 
self.assertEqual(  | 
|
780  | 
[('Commit with an empty message?',  | 
|
781  | 
'You can describe your commit intent in the message.'),  | 
|
| 
278.1.26
by John Arbash Meinel
 Handle pointless commits and trees with unknown files.  | 
782  | 
'YES',  | 
783  | 
], self.questions)  | 
|
| 
278.1.23
by John Arbash Meinel
 Beginning to support actual commit.  | 
784  | 
committed = tree.last_revision()  | 
785  | 
self.assertNotEqual(rev_id, committed)  | 
|
786  | 
self.assertEqual(committed, dlg.committed_revision_id)  | 
|
787  | 
||
788  | 
def test_initial_commit(self):  | 
|
789  | 
tree = self.make_branch_and_tree('tree')  | 
|
790  | 
self.build_tree(['tree/a'])  | 
|
791  | 
tree.add(['a'], ['a-id'])  | 
|
792  | 
||
793  | 
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.  | 
794  | 
dlg._set_global_commit_message('Some text\n')  | 
| 
278.1.23
by John Arbash Meinel
 Beginning to support actual commit.  | 
795  | 
dlg._do_commit()  | 
796  | 
||
797  | 
last_rev = tree.last_revision()  | 
|
798  | 
self.assertEqual(last_rev, dlg.committed_revision_id)  | 
|
799  | 
rev = tree.branch.repository.get_revision(last_rev)  | 
|
800  | 
self.assertEqual(last_rev, rev.revision_id)  | 
|
801  | 
self.assertEqual('Some text\n', rev.message)  | 
|
| 
278.1.26
by John Arbash Meinel
 Handle pointless commits and trees with unknown files.  | 
802  | 
|
803  | 
def test_pointless_commit(self):  | 
|
804  | 
tree = self.make_branch_and_tree('tree')  | 
|
805  | 
self.build_tree(['tree/a'])  | 
|
806  | 
tree.add(['a'], ['a-id'])  | 
|
807  | 
rev_id1 = tree.commit('one')  | 
|
808  | 
||
809  | 
dlg = commit.CommitDialog(tree)  | 
|
810  | 
dlg._set_global_commit_message('Some text\n')  | 
|
811  | 
||
812  | 
self._set_question_no(dlg)  | 
|
813  | 
dlg._do_commit()  | 
|
814  | 
||
815  | 
self.assertIs(None, dlg.committed_revision_id)  | 
|
816  | 
self.assertEqual(rev_id1, tree.last_revision())  | 
|
817  | 
self.assertEqual(  | 
|
818  | 
[('Commit with no changes?',  | 
|
819  | 
              'There are no changes in the working tree.'
 | 
|
820  | 
' Do you want to commit anyway?'),  | 
|
821  | 
'NO',  | 
|
822  | 
], self.questions)  | 
|
823  | 
||
824  | 
self._set_question_yes(dlg)  | 
|
825  | 
dlg._do_commit()  | 
|
826  | 
||
827  | 
rev_id2 = tree.last_revision()  | 
|
828  | 
self.assertEqual(rev_id2, dlg.committed_revision_id)  | 
|
829  | 
self.assertNotEqual(rev_id1, rev_id2)  | 
|
830  | 
self.assertEqual(  | 
|
831  | 
[('Commit with no changes?',  | 
|
832  | 
              'There are no changes in the working tree.'
 | 
|
833  | 
' Do you want to commit anyway?'),  | 
|
834  | 
'YES',  | 
|
835  | 
], self.questions)  | 
|
836  | 
||
837  | 
def test_unknowns(self):  | 
|
838  | 
"""We should check if there are unknown files."""  | 
|
839  | 
tree = self.make_branch_and_tree('tree')  | 
|
840  | 
rev_id1 = tree.commit('one')  | 
|
841  | 
self.build_tree(['tree/a', 'tree/b'])  | 
|
842  | 
tree.add(['a'], ['a-id'])  | 
|
843  | 
||
844  | 
dlg = commit.CommitDialog(tree)  | 
|
845  | 
dlg._set_global_commit_message('Some text\n')  | 
|
846  | 
self._set_question_no(dlg)  | 
|
847  | 
||
848  | 
dlg._do_commit()  | 
|
849  | 
||
850  | 
self.assertIs(None, dlg.committed_revision_id)  | 
|
851  | 
self.assertEqual(rev_id1, tree.last_revision())  | 
|
852  | 
self.assertEqual(  | 
|
853  | 
[("Commit with unknowns?",  | 
|
854  | 
"Unknown files exist in the working tree. Commit anyway?"),  | 
|
855  | 
"NO",  | 
|
856  | 
], self.questions)  | 
|
857  | 
||
858  | 
self._set_question_yes(dlg)  | 
|
859  | 
dlg._do_commit()  | 
|
860  | 
||
861  | 
rev_id2 = tree.last_revision()  | 
|
862  | 
self.assertNotEqual(rev_id1, rev_id2)  | 
|
863  | 
self.assertEqual(rev_id2, dlg.committed_revision_id)  | 
|
864  | 
self.assertEqual(  | 
|
865  | 
[("Commit with unknowns?",  | 
|
866  | 
"Unknown files exist in the working tree. Commit anyway?"),  | 
|
867  | 
"YES",  | 
|
868  | 
], self.questions)  | 
|
869  | 
||
| 
278.1.27
by John Arbash Meinel
 Add the ability to commit just specific files.  | 
870  | 
def test_commit_specific_files(self):  | 
871  | 
tree = self.make_branch_and_tree('tree')  | 
|
872  | 
rev_id1 = tree.commit('one')  | 
|
873  | 
self.build_tree(['tree/a', 'tree/b'])  | 
|
874  | 
tree.add(['a', 'b'], ['a-id', 'b-id'])  | 
|
875  | 
||
876  | 
dlg = commit.CommitDialog(tree)  | 
|
| 
278.1.43
by John Arbash Meinel
 Finish connecting the 'Commit all changes' radio buttons.  | 
877  | 
dlg._commit_selected_radio.set_active(True) # enable partial  | 
| 
278.1.27
by John Arbash Meinel
 Add the ability to commit just specific files.  | 
878  | 
dlg._toggle_commit(None, 2, dlg._files_store) # unset 'b'  | 
879  | 
||
880  | 
dlg._set_global_commit_message('Committing just "a"\n')  | 
|
881  | 
dlg._do_commit()  | 
|
882  | 
||
883  | 
rev_id2 = dlg.committed_revision_id  | 
|
884  | 
self.assertIsNot(None, rev_id2)  | 
|
885  | 
self.assertEqual(rev_id2, tree.last_revision())  | 
|
886  | 
||
887  | 
rt = tree.branch.repository.revision_tree(rev_id2)  | 
|
888  | 
entries = [(path, ie.file_id) for path, ie in rt.iter_entries_by_dir()  | 
|
889  | 
if path] # Ignore the root entry  | 
|
890  | 
self.assertEqual([('a', 'a-id')], entries)  | 
|
891  | 
||
| 
278.1.43
by John Arbash Meinel
 Finish connecting the 'Commit all changes' radio buttons.  | 
892  | 
def test_commit_partial_no_partial(self):  | 
893  | 
"""Ignore the checkboxes if committing all files."""  | 
|
894  | 
tree = self.make_branch_and_tree('tree')  | 
|
895  | 
rev_id1 = tree.commit('one')  | 
|
896  | 
self.build_tree(['tree/a', 'tree/b'])  | 
|
897  | 
tree.add(['a', 'b'], ['a-id', 'b-id'])  | 
|
898  | 
||
899  | 
dlg = commit.CommitDialog(tree)  | 
|
900  | 
dlg._commit_selected_radio.set_active(True) # enable partial  | 
|
901  | 
dlg._toggle_commit(None, 2, dlg._files_store) # unset 'b'  | 
|
902  | 
||
903  | 
        # Switch back to committing all changes
 | 
|
904  | 
dlg._commit_all_files_radio.set_active(True)  | 
|
905  | 
||
906  | 
dlg._set_global_commit_message('Committing everything\n')  | 
|
907  | 
dlg._do_commit()  | 
|
908  | 
||
909  | 
rev_id2 = dlg.committed_revision_id  | 
|
910  | 
self.assertIsNot(None, rev_id2)  | 
|
911  | 
self.assertEqual(rev_id2, tree.last_revision())  | 
|
912  | 
||
913  | 
rt = tree.branch.repository.revision_tree(rev_id2)  | 
|
914  | 
entries = [(path, ie.file_id) for path, ie in rt.iter_entries_by_dir()  | 
|
915  | 
if path] # Ignore the root entry  | 
|
916  | 
self.assertEqual([('a', 'a-id'), ('b', 'b-id')], entries)  | 
|
917  | 
||
| 
278.1.27
by John Arbash Meinel
 Add the ability to commit just specific files.  | 
918  | 
def test_commit_no_messages(self):  | 
919  | 
tree = self.make_branch_and_tree('tree')  | 
|
920  | 
rev_id1 = tree.commit('one')  | 
|
921  | 
self.build_tree(['tree/a', 'tree/b'])  | 
|
922  | 
tree.add(['a', 'b'], ['a-id', 'b-id'])  | 
|
923  | 
||
924  | 
dlg = commit.CommitDialog(tree)  | 
|
925  | 
dlg._set_global_commit_message('Simple commit\n')  | 
|
926  | 
dlg._do_commit()  | 
|
927  | 
||
928  | 
rev = tree.branch.repository.get_revision(dlg.committed_revision_id)  | 
|
929  | 
self.failIf('file-info' in rev.properties)  | 
|
930  | 
||
| 
278.1.33
by John Arbash Meinel
 Only enable the per-file dialog if 'per_file_commits' is enabled in the config.  | 
931  | 
def test_commit_disabled_messages(self):  | 
932  | 
tree = self.make_branch_and_tree('tree')  | 
|
933  | 
rev_id1 = tree.commit('one')  | 
|
934  | 
||
935  | 
self.build_tree(['tree/a', 'tree/b'])  | 
|
936  | 
tree.add(['a', 'b'], ['a-id', 'b-id'])  | 
|
937  | 
||
938  | 
dlg = commit.CommitDialog(tree)  | 
|
939  | 
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  | 
940  | 
self.assertEqual('Commit Message',  | 
941  | 
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.  | 
942  | 
|
943  | 
tree.branch.get_config().set_user_option('per_file_commits', 'true')  | 
|
944  | 
dlg = commit.CommitDialog(tree)  | 
|
945  | 
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  | 
946  | 
self.assertEqual('Global Commit Message',  | 
947  | 
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.  | 
948  | 
|
949  | 
tree.branch.get_config().set_user_option('per_file_commits', 'on')  | 
|
950  | 
dlg = commit.CommitDialog(tree)  | 
|
951  | 
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  | 
952  | 
self.assertEqual('Global Commit Message',  | 
953  | 
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.  | 
954  | 
|
955  | 
tree.branch.get_config().set_user_option('per_file_commits', 'y')  | 
|
956  | 
dlg = commit.CommitDialog(tree)  | 
|
957  | 
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  | 
958  | 
self.assertEqual('Global Commit Message',  | 
959  | 
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.  | 
960  | 
|
961  | 
tree.branch.get_config().set_user_option('per_file_commits', 'n')  | 
|
962  | 
dlg = commit.CommitDialog(tree)  | 
|
963  | 
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  | 
964  | 
self.assertEqual('Commit Message',  | 
965  | 
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.  | 
966  | 
|
| 
278.1.27
by John Arbash Meinel
 Add the ability to commit just specific files.  | 
967  | 
def test_commit_specific_files_with_messages(self):  | 
968  | 
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.  | 
969  | 
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.  | 
970  | 
rev_id1 = tree.commit('one')  | 
971  | 
self.build_tree(['tree/a', 'tree/b'])  | 
|
972  | 
tree.add(['a', 'b'], ['a-id', 'b-id'])  | 
|
973  | 
||
974  | 
dlg = commit.CommitDialog(tree)  | 
|
| 
278.1.43
by John Arbash Meinel
 Finish connecting the 'Commit all changes' radio buttons.  | 
975  | 
dlg._commit_selected_radio.set_active(True) # enable partial  | 
| 
278.1.27
by John Arbash Meinel
 Add the ability to commit just specific files.  | 
976  | 
dlg._treeview_files.set_cursor((1,))  | 
977  | 
dlg._set_file_commit_message('Message for A\n')  | 
|
978  | 
dlg._treeview_files.set_cursor((2,))  | 
|
979  | 
dlg._set_file_commit_message('Message for B\n')  | 
|
980  | 
dlg._toggle_commit(None, 2, dlg._files_store) # unset 'b'  | 
|
981  | 
dlg._set_global_commit_message('Commit just "a"')  | 
|
982  | 
||
983  | 
dlg._do_commit()  | 
|
984  | 
||
985  | 
rev_id2 = dlg.committed_revision_id  | 
|
986  | 
self.assertEqual(rev_id2, tree.last_revision())  | 
|
987  | 
rev = tree.branch.repository.get_revision(rev_id2)  | 
|
988  | 
self.assertEqual('Commit just "a"', rev.message)  | 
|
989  | 
file_info = rev.properties['file-info']  | 
|
| 
662
by Vincent Ladeuil
 Fix test failures.  | 
990  | 
self.assertEqual(u'ld7:file_id4:a-id'  | 
991  | 
'7:message14:Message for A\n'  | 
|
992  | 
                         '4:path1:a'
 | 
|
993  | 
'ee',  | 
|
994  | 
file_info)  | 
|
| 
278.1.27
by John Arbash Meinel
 Add the ability to commit just specific files.  | 
995  | 
self.assertEqual([{'path':'a', 'file_id':'a-id',  | 
| 
662
by Vincent Ladeuil
 Fix test failures.  | 
996  | 
'message':'Message for A\n'},],  | 
997  | 
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.  | 
998  | 
|
999  | 
def test_commit_messages_after_merge(self):  | 
|
1000  | 
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.  | 
1001  | 
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.  | 
1002  | 
rev_id1 = tree.commit('one')  | 
1003  | 
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()  | 
|
1004  | 
self.build_tree(['tree2/a', 'tree2/b'])  | 
|
1005  | 
tree2.add(['a', 'b'], ['a-id', 'b-id'])  | 
|
1006  | 
rev_id2 = tree2.commit('two')  | 
|
1007  | 
||
1008  | 
tree.merge_from_branch(tree2.branch)  | 
|
1009  | 
||
1010  | 
dlg = commit.CommitDialog(tree)  | 
|
1011  | 
dlg._treeview_files.set_cursor((1,)) # 'a'  | 
|
1012  | 
dlg._set_file_commit_message('Message for A\n')  | 
|
1013  | 
        # No message for 'B'
 | 
|
1014  | 
dlg._set_global_commit_message('Merging from "tree2"\n')  | 
|
1015  | 
||
1016  | 
dlg._do_commit()  | 
|
1017  | 
||
1018  | 
rev_id3 = dlg.committed_revision_id  | 
|
1019  | 
self.assertEqual(rev_id3, tree.last_revision())  | 
|
1020  | 
rev = tree.branch.repository.get_revision(rev_id3)  | 
|
1021  | 
self.assertEqual('Merging from "tree2"\n', rev.message)  | 
|
1022  | 
self.assertEqual([rev_id1, rev_id2], rev.parent_ids)  | 
|
1023  | 
file_info = rev.properties['file-info']  | 
|
| 
662
by Vincent Ladeuil
 Fix test failures.  | 
1024  | 
self.assertEqual(u'ld7:file_id4:a-id'  | 
1025  | 
'7:message14:Message for A\n'  | 
|
1026  | 
                         '4:path1:a'
 | 
|
1027  | 
'ee',  | 
|
1028  | 
file_info)  | 
|
| 
278.1.28
by John Arbash Meinel
 Ensure that we can set per-file messages even during a merge.  | 
1029  | 
self.assertEqual([{'path':'a', 'file_id':'a-id',  | 
| 
662
by Vincent Ladeuil
 Fix test failures.  | 
1030  | 
'message':'Message for A\n'},],  | 
1031  | 
bencode.bdecode(file_info.encode('UTF-8')))  | 
|
| 
278.1.29
by John Arbash Meinel
 Start testing with Unicode data.  | 
1032  | 
|
1033  | 
def test_commit_unicode_messages(self):  | 
|
| 
500.1.1
by Vincent Ladeuil
 Fix test failing after a feature rename in bzr.  | 
1034  | 
self.requireFeature(tests.UnicodeFilenameFeature)  | 
| 
278.1.29
by John Arbash Meinel
 Start testing with Unicode data.  | 
1035  | 
|
1036  | 
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.  | 
1037  | 
tree.branch.get_config().set_user_option('per_file_commits', 'true')  | 
| 
278.1.29
by John Arbash Meinel
 Start testing with Unicode data.  | 
1038  | 
self.build_tree(['tree/a', u'tree/\u03a9'])  | 
1039  | 
tree.add(['a', u'\u03a9'], ['a-id', 'omega-id'])  | 
|
1040  | 
||
1041  | 
dlg = commit.CommitDialog(tree)  | 
|
1042  | 
dlg._treeview_files.set_cursor((1,)) # 'a'  | 
|
1043  | 
dlg._set_file_commit_message(u'Test \xfan\xecc\xf6de\n')  | 
|
1044  | 
dlg._treeview_files.set_cursor((2,)) # omega  | 
|
1045  | 
dlg._set_file_commit_message(u'\u03a9 is the end of all things.\n')  | 
|
1046  | 
dlg._set_global_commit_message(u'\u03a9 and \xfan\xecc\xf6de\n')  | 
|
1047  | 
||
1048  | 
self.assertEqual(([u'a', u'\u03a9'],  | 
|
1049  | 
[{'path':'a', 'file_id':'a-id',  | 
|
1050  | 
'message':'Test \xc3\xban\xc3\xacc\xc3\xb6de\n'},  | 
|
1051  | 
{'path':'\xce\xa9', 'file_id':'omega-id',  | 
|
1052  | 
'message':'\xce\xa9 is the end of all things.\n'},  | 
|
1053  | 
]), dlg._get_specific_files())  | 
|
1054  | 
||
1055  | 
dlg._do_commit()  | 
|
1056  | 
||
1057  | 
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.  | 
1058  | 
file_info = rev.properties['file-info'].encode('UTF-8')  | 
| 
278.1.29
by John Arbash Meinel
 Start testing with Unicode data.  | 
1059  | 
value = ('ld7:file_id4:a-id'  | 
1060  | 
'7:message16:Test \xc3\xban\xc3\xacc\xc3\xb6de\n'  | 
|
1061  | 
                   '4:path1:a'
 | 
|
1062  | 
                  'e'
 | 
|
1063  | 
                  'd7:file_id8:omega-id'
 | 
|
1064  | 
'7:message29:\xce\xa9 is the end of all things.\n'  | 
|
1065  | 
'4:path2:\xce\xa9'  | 
|
1066  | 
                  'e'
 | 
|
1067  | 
'e')  | 
|
1068  | 
self.assertEqual(value, file_info)  | 
|
1069  | 
file_info_decoded = bencode.bdecode(file_info)  | 
|
1070  | 
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.  | 
1071  | 
d['path'] = d['path'].decode('UTF-8')  | 
1072  | 
d['message'] = d['message'].decode('UTF-8')  | 
|
| 
278.1.29
by John Arbash Meinel
 Start testing with Unicode data.  | 
1073  | 
|
1074  | 
self.assertEqual([{'path':u'a', 'file_id':'a-id',  | 
|
1075  | 
'message':u'Test \xfan\xecc\xf6de\n'},  | 
|
1076  | 
{'path':u'\u03a9', 'file_id':'omega-id',  | 
|
1077  | 
'message':u'\u03a9 is the end of all things.\n'},  | 
|
1078  | 
], file_info_decoded)  | 
|
| 
622.1.1
by John Arbash Meinel
 Ensure that per-file commit messages and global commit messages get sanitized.  | 
1079  | 
|
1080  | 
||
1081  | 
class TestSanitizeMessage(tests.TestCase):  | 
|
1082  | 
||
1083  | 
def assertSanitize(self, expected, original):  | 
|
1084  | 
self.assertEqual(expected,  | 
|
1085  | 
commit._sanitize_and_decode_message(original))  | 
|
1086  | 
||
1087  | 
def test_untouched(self):  | 
|
1088  | 
self.assertSanitize('foo\nbar\nbaz\n', 'foo\nbar\nbaz\n')  | 
|
1089  | 
||
1090  | 
def test_converts_cr_to_lf(self):  | 
|
1091  | 
self.assertSanitize('foo\nbar\nbaz\n', 'foo\rbar\rbaz\r')  | 
|
1092  | 
||
1093  | 
def test_converts_crlf_to_lf(self):  | 
|
1094  | 
self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\r\nbaz\r\n')  | 
|
1095  | 
||
1096  | 
def test_converts_mixed_to_lf(self):  | 
|
1097  | 
self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\rbaz\n')  | 
|
| 
635.2.8
by Vincent Ladeuil
 Start testing patch behavior.  | 
1098  | 
|
1099  | 
||
| 
635.2.10
by Vincent Ladeuil
 Complete tests around saved commit messages.  | 
1100  | 
class TestSavedCommitMessages(tests.TestCaseWithTransport):  | 
| 
635.2.9
by Vincent Ladeuil
 Tests completed for uncommit.  | 
1101  | 
|
| 
635.2.12
by Vincent Ladeuil
 Implement commit message saving without modifying bzrlib.  | 
1102  | 
def setUp(self):  | 
1103  | 
super(TestSavedCommitMessages, self).setUp()  | 
|
1104  | 
        # Install our hook
 | 
|
1105  | 
branch.Branch.hooks.install_named_hook(  | 
|
1106  | 
'post_uncommit', commit.save_commit_messages, None)  | 
|
1107  | 
||
| 
635.2.9
by Vincent Ladeuil
 Tests completed for uncommit.  | 
1108  | 
def _get_file_info_dict(self, rank):  | 
1109  | 
file_info = [dict(path='a', file_id='a-id', message='a msg %d' % rank),  | 
|
1110  | 
dict(path='b', file_id='b-id', message='b msg %d' % rank)]  | 
|
1111  | 
return file_info  | 
|
1112  | 
||
1113  | 
def _get_file_info_revprops(self, rank):  | 
|
1114  | 
file_info_prop = self._get_file_info_dict(rank)  | 
|
1115  | 
return {'file-info': bencode.bencode(file_info_prop).decode('UTF-8')}  | 
|
1116  | 
||
1117  | 
def _get_commit_message(self):  | 
|
1118  | 
return self.config.get_user_option('gtk_global_commit_message')  | 
|
1119  | 
||
1120  | 
def _get_file_commit_messages(self):  | 
|
1121  | 
return self.config.get_user_option('gtk_file_commit_messages')  | 
|
1122  | 
||
| 
635.2.10
by Vincent Ladeuil
 Complete tests around saved commit messages.  | 
1123  | 
|
1124  | 
class TestUncommitHook(TestSavedCommitMessages):  | 
|
1125  | 
||
1126  | 
def setUp(self):  | 
|
1127  | 
super(TestUncommitHook, self).setUp()  | 
|
1128  | 
self.tree = self.make_branch_and_tree('tree')  | 
|
1129  | 
self.config = self.tree.branch.get_config()  | 
|
1130  | 
self.build_tree(['tree/a', 'tree/b'])  | 
|
1131  | 
self.tree.add(['a'], ['a-id'])  | 
|
1132  | 
self.tree.add(['b'], ['b-id'])  | 
|
| 
635.2.12
by Vincent Ladeuil
 Implement commit message saving without modifying bzrlib.  | 
1133  | 
rev1 = self.tree.commit('one', rev_id='one-id',  | 
1134  | 
revprops=self._get_file_info_revprops(1))  | 
|
1135  | 
rev2 = self.tree.commit('two', rev_id='two-id',  | 
|
1136  | 
revprops=self._get_file_info_revprops(2))  | 
|
1137  | 
rev3 = self.tree.commit('three', rev_id='three-id',  | 
|
| 
635.2.10
by Vincent Ladeuil
 Complete tests around saved commit messages.  | 
1138  | 
revprops=self._get_file_info_revprops(3))  | 
1139  | 
||
| 
635.2.9
by Vincent Ladeuil
 Tests completed for uncommit.  | 
1140  | 
def test_uncommit_one_by_one(self):  | 
1141  | 
uncommit.uncommit(self.tree.branch, tree=self.tree)  | 
|
1142  | 
self.assertEquals(u'three', self._get_commit_message())  | 
|
1143  | 
self.assertEquals(u'd4:a-id7:a msg 34:b-id7:b msg 3e',  | 
|
1144  | 
self._get_file_commit_messages())  | 
|
1145  | 
||
1146  | 
uncommit.uncommit(self.tree.branch, tree=self.tree)  | 
|
1147  | 
self.assertEquals(u'two\n******\nthree', self._get_commit_message())  | 
|
1148  | 
self.assertEquals(u'd4:a-id22:a msg 2\n******\na msg 3'  | 
|
1149  | 
'4:b-id22:b msg 2\n******\nb msg 3e',  | 
|
1150  | 
self._get_file_commit_messages())  | 
|
1151  | 
||
1152  | 
uncommit.uncommit(self.tree.branch, tree=self.tree)  | 
|
1153  | 
self.assertEquals(u'one\n******\ntwo\n******\nthree',  | 
|
1154  | 
self._get_commit_message())  | 
|
1155  | 
self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'  | 
|
1156  | 
'4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',  | 
|
1157  | 
self._get_file_commit_messages())  | 
|
1158  | 
||
1159  | 
def test_uncommit_all_at_once(self):  | 
|
1160  | 
uncommit.uncommit(self.tree.branch, tree=self.tree, revno=1)  | 
|
1161  | 
self.assertEquals(u'one\n******\ntwo\n******\nthree',  | 
|
1162  | 
self._get_commit_message())  | 
|
1163  | 
self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'  | 
|
1164  | 
'4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',  | 
|
1165  | 
self._get_file_commit_messages())  | 
|
| 
635.2.10
by Vincent Ladeuil
 Complete tests around saved commit messages.  | 
1166  | 
|
1167  | 
||
1168  | 
class TestReusingSavedCommitMessages(TestSavedCommitMessages, QuestionHelpers):  | 
|
1169  | 
||
1170  | 
def setUp(self):  | 
|
1171  | 
super(TestReusingSavedCommitMessages, self).setUp()  | 
|
1172  | 
self.tree = self.make_branch_and_tree('tree')  | 
|
1173  | 
self.config = self.tree.branch.get_config()  | 
|
1174  | 
self.config.set_user_option('per_file_commits', 'true')  | 
|
1175  | 
self.build_tree(['tree/a', 'tree/b'])  | 
|
1176  | 
self.tree.add(['a'], ['a-id'])  | 
|
1177  | 
self.tree.add(['b'], ['b-id'])  | 
|
1178  | 
rev1 = self.tree.commit('one', revprops=self._get_file_info_revprops(1))  | 
|
1179  | 
rev2 = self.tree.commit('two', revprops=self._get_file_info_revprops(2))  | 
|
1180  | 
uncommit.uncommit(self.tree.branch, tree=self.tree)  | 
|
1181  | 
self.build_tree_contents([('tree/a', 'new a content\n'),  | 
|
1182  | 
('tree/b', 'new b content'),])  | 
|
1183  | 
||
| 
635.2.11
by Vincent Ladeuil
 Fix a leaking dialog windows appearing during the test suite.  | 
1184  | 
def _get_commit_dialog(self, tree):  | 
1185  | 
        # Ensure we will never use a dialog that can actually prompt the user
 | 
|
1186  | 
        # during the test suite. Test *can* and *should* override with the
 | 
|
1187  | 
        # correct question dialog type.
 | 
|
1188  | 
dlg = commit.CommitDialog(tree)  | 
|
1189  | 
self._set_question_no(dlg)  | 
|
1190  | 
return dlg  | 
|
1191  | 
||
| 
635.2.10
by Vincent Ladeuil
 Complete tests around saved commit messages.  | 
1192  | 
def test_setup_saved_messages(self):  | 
1193  | 
        # Check the initial setup
 | 
|
1194  | 
self.assertEquals(u'two', self._get_commit_message())  | 
|
1195  | 
self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',  | 
|
1196  | 
self._get_file_commit_messages())  | 
|
1197  | 
||
1198  | 
def test_messages_are_reloaded(self):  | 
|
| 
635.2.11
by Vincent Ladeuil
 Fix a leaking dialog windows appearing during the test suite.  | 
1199  | 
dlg = self._get_commit_dialog(self.tree)  | 
| 
635.2.10
by Vincent Ladeuil
 Complete tests around saved commit messages.  | 
1200  | 
self.assertEquals(u'two', dlg._get_global_commit_message())  | 
1201  | 
self.assertEquals(([u'a', u'b'],  | 
|
1202  | 
[{ 'path': 'a',  | 
|
1203  | 
'file_id': 'a-id', 'message': 'a msg 2',},  | 
|
1204  | 
{'path': 'b',  | 
|
1205  | 
'file_id': 'b-id', 'message': 'b msg 2',}],),  | 
|
1206  | 
dlg._get_specific_files())  | 
|
1207  | 
||
1208  | 
def test_messages_are_consumed(self):  | 
|
| 
635.2.11
by Vincent Ladeuil
 Fix a leaking dialog windows appearing during the test suite.  | 
1209  | 
dlg = self._get_commit_dialog(self.tree)  | 
| 
635.2.10
by Vincent Ladeuil
 Complete tests around saved commit messages.  | 
1210  | 
dlg._do_commit()  | 
1211  | 
self.assertEquals(u'', self._get_commit_message())  | 
|
1212  | 
self.assertEquals(u'de', self._get_file_commit_messages())  | 
|
1213  | 
||
1214  | 
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.  | 
1215  | 
dlg = self._get_commit_dialog(self.tree)  | 
| 
635.2.10
by Vincent Ladeuil
 Complete tests around saved commit messages.  | 
1216  | 
self._set_question_yes(dlg) # Save messages  | 
1217  | 
dlg._do_cancel()  | 
|
1218  | 
self.assertEquals(u'two', self._get_commit_message())  | 
|
1219  | 
self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',  | 
|
1220  | 
self._get_file_commit_messages())  | 
|
1221  | 
||
1222  | 
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.  | 
1223  | 
dlg = self._get_commit_dialog(self.tree)  | 
| 
635.2.10
by Vincent Ladeuil
 Complete tests around saved commit messages.  | 
1224  | 
self._set_question_no(dlg) # Don't save messages  | 
1225  | 
dlg._do_cancel()  | 
|
1226  | 
self.assertEquals(u'', self._get_commit_message())  | 
|
1227  | 
self.assertEquals(u'de',  | 
|
1228  | 
self._get_file_commit_messages())  |