662
644
'message':'message\nfor b_dir\n'},
663
645
]), dlg._get_specific_files())
665
def test_specific_files_sanitizes_messages(self):
666
tree = self.make_branch_and_tree('tree')
667
tree.branch.get_config().set_user_option('per_file_commits', 'true')
668
self.build_tree(['tree/a_file', 'tree/b_dir/'])
669
tree.add(['a_file', 'b_dir'], ['1a-id', '0b-id'])
671
dlg = commit.CommitDialog(tree)
672
dlg._commit_selected_radio.set_active(True)
673
self.assertEqual((['a_file', 'b_dir'], []), dlg._get_specific_files())
675
dlg._treeview_files.set_cursor(
676
Gtk.TreePath(path=1), None, False)
677
dlg._set_file_commit_message('Test\r\nmessage\rfor a_file\n')
678
dlg._treeview_files.set_cursor(
679
Gtk.TreePath(path=2), None, False)
680
dlg._set_file_commit_message('message\r\nfor\nb_dir\r')
682
self.assertEqual((['a_file', 'b_dir'],
683
[{'path':'a_file', 'file_id':'1a-id',
684
'message':'Test\nmessage\nfor a_file\n'},
685
{'path':'b_dir', 'file_id':'0b-id',
686
'message':'message\nfor\nb_dir\n'},
687
]), dlg._get_specific_files())
690
class QuestionHelpers(object):
648
class TestCommitDialog_Commit(tests.TestCaseWithTransport):
649
"""Tests on the actual 'commit' button being pushed."""
692
651
def _set_question_yes(self, dlg):
693
652
"""Set the dialog to answer YES to any questions."""
694
653
self.questions = []
695
def _question_yes(*args, **kwargs):
654
def _question_yes(*args):
696
655
self.questions.append(args)
697
656
self.questions.append('YES')
698
return Gtk.ResponseType.YES
657
return gtk.RESPONSE_YES
699
658
dlg._question_dialog = _question_yes
701
660
def _set_question_no(self, dlg):
702
661
"""Set the dialog to answer NO to any questions."""
703
662
self.questions = []
704
def _question_no(*args, **kwargs):
663
def _question_no(*args):
705
664
self.questions.append(args)
706
665
self.questions.append('NO')
707
return Gtk.ResponseType.NO
666
return gtk.RESPONSE_NO
708
667
dlg._question_dialog = _question_no
711
class TestCommitDialog_Commit(tests.TestCaseWithTransport, QuestionHelpers):
712
"""Tests on the actual 'commit' button being pushed."""
714
669
def test_bound_commit_local(self):
715
670
tree = self.make_branch_and_tree('tree')
716
671
self.build_tree(['tree/a'])
1097
1030
{'path':u'\u03a9', 'file_id':'omega-id',
1098
1031
'message':u'\u03a9 is the end of all things.\n'},
1099
1032
], file_info_decoded)
1102
class TestSanitizeMessage(tests.TestCase):
1104
def assertSanitize(self, expected, original):
1105
self.assertEqual(expected,
1106
commit._sanitize_and_decode_message(original))
1108
def test_untouched(self):
1109
self.assertSanitize('foo\nbar\nbaz\n', 'foo\nbar\nbaz\n')
1111
def test_converts_cr_to_lf(self):
1112
self.assertSanitize('foo\nbar\nbaz\n', 'foo\rbar\rbaz\r')
1114
def test_converts_crlf_to_lf(self):
1115
self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\r\nbaz\r\n')
1117
def test_converts_mixed_to_lf(self):
1118
self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\rbaz\n')
1121
class TestSavedCommitMessages(tests.TestCaseWithTransport):
1124
super(TestSavedCommitMessages, self).setUp()
1126
branch.Branch.hooks.install_named_hook(
1127
'post_uncommit', commit.save_commit_messages, None)
1129
def _get_file_info_dict(self, rank):
1130
file_info = [dict(path='a', file_id='a-id', message='a msg %d' % rank),
1131
dict(path='b', file_id='b-id', message='b msg %d' % rank)]
1134
def _get_file_info_revprops(self, rank):
1135
file_info_prop = self._get_file_info_dict(rank)
1136
return {'file-info': bencode.bencode(file_info_prop).decode('UTF-8')}
1138
def _get_commit_message(self):
1139
return self.config.get_user_option('gtk_global_commit_message')
1141
def _get_file_commit_messages(self):
1142
return self.config.get_user_option('gtk_file_commit_messages')
1145
class TestUncommitHook(TestSavedCommitMessages):
1148
super(TestUncommitHook, self).setUp()
1149
self.tree = self.make_branch_and_tree('tree')
1150
self.config = self.tree.branch.get_config()
1151
self.build_tree(['tree/a', 'tree/b'])
1152
self.tree.add(['a'], ['a-id'])
1153
self.tree.add(['b'], ['b-id'])
1154
rev1 = self.tree.commit('one', rev_id='one-id',
1155
revprops=self._get_file_info_revprops(1))
1156
rev2 = self.tree.commit('two', rev_id='two-id',
1157
revprops=self._get_file_info_revprops(2))
1158
rev3 = self.tree.commit('three', rev_id='three-id',
1159
revprops=self._get_file_info_revprops(3))
1161
def test_uncommit_one_by_one(self):
1162
uncommit.uncommit(self.tree.branch, tree=self.tree)
1163
self.assertEquals(u'three', self._get_commit_message())
1164
self.assertEquals(u'd4:a-id7:a msg 34:b-id7:b msg 3e',
1165
self._get_file_commit_messages())
1167
uncommit.uncommit(self.tree.branch, tree=self.tree)
1168
self.assertEquals(u'two\n******\nthree', self._get_commit_message())
1169
self.assertEquals(u'd4:a-id22:a msg 2\n******\na msg 3'
1170
'4:b-id22:b msg 2\n******\nb msg 3e',
1171
self._get_file_commit_messages())
1173
uncommit.uncommit(self.tree.branch, tree=self.tree)
1174
self.assertEquals(u'one\n******\ntwo\n******\nthree',
1175
self._get_commit_message())
1176
self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1177
'4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1178
self._get_file_commit_messages())
1180
def test_uncommit_all_at_once(self):
1181
uncommit.uncommit(self.tree.branch, tree=self.tree, revno=1)
1182
self.assertEquals(u'one\n******\ntwo\n******\nthree',
1183
self._get_commit_message())
1184
self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1185
'4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1186
self._get_file_commit_messages())
1189
class TestReusingSavedCommitMessages(TestSavedCommitMessages, QuestionHelpers):
1192
super(TestReusingSavedCommitMessages, self).setUp()
1193
self.tree = self.make_branch_and_tree('tree')
1194
self.config = self.tree.branch.get_config()
1195
self.config.set_user_option('per_file_commits', 'true')
1196
self.build_tree(['tree/a', 'tree/b'])
1197
self.tree.add(['a'], ['a-id'])
1198
self.tree.add(['b'], ['b-id'])
1199
rev1 = self.tree.commit('one', revprops=self._get_file_info_revprops(1))
1200
rev2 = self.tree.commit('two', revprops=self._get_file_info_revprops(2))
1201
uncommit.uncommit(self.tree.branch, tree=self.tree)
1202
self.build_tree_contents([('tree/a', 'new a content\n'),
1203
('tree/b', 'new b content'),])
1205
def _get_commit_dialog(self, tree):
1206
# Ensure we will never use a dialog that can actually prompt the user
1207
# during the test suite. Test *can* and *should* override with the
1208
# correct question dialog type.
1209
dlg = commit.CommitDialog(tree)
1210
self._set_question_no(dlg)
1213
def test_setup_saved_messages(self):
1214
# Check the initial setup
1215
self.assertEquals(u'two', self._get_commit_message())
1216
self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1217
self._get_file_commit_messages())
1219
def test_messages_are_reloaded(self):
1220
dlg = self._get_commit_dialog(self.tree)
1221
self.assertEquals(u'two', dlg._get_global_commit_message())
1222
self.assertEquals(([u'a', u'b'],
1224
'file_id': 'a-id', 'message': 'a msg 2',},
1226
'file_id': 'b-id', 'message': 'b msg 2',}],),
1227
dlg._get_specific_files())
1229
def test_messages_are_consumed(self):
1230
dlg = self._get_commit_dialog(self.tree)
1232
self.assertEquals(u'', self._get_commit_message())
1233
self.assertEquals(u'de', self._get_file_commit_messages())
1235
def test_messages_are_saved_on_cancel_if_required(self):
1236
dlg = self._get_commit_dialog(self.tree)
1237
self._set_question_yes(dlg) # Save messages
1239
self.assertEquals(u'two', self._get_commit_message())
1240
self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1241
self._get_file_commit_messages())
1243
def test_messages_are_cleared_on_cancel_if_required(self):
1244
dlg = self._get_commit_dialog(self.tree)
1245
self._set_question_no(dlg) # Don't save messages
1247
self.assertEquals(u'', self._get_commit_message())
1248
self.assertEquals(u'de',
1249
self._get_file_commit_messages())