644
673
'message':'message\nfor b_dir\n'},
645
674
]), dlg._get_specific_files())
648
class TestCommitDialog_Commit(tests.TestCaseWithTransport):
649
"""Tests on the actual 'commit' button being pushed."""
676
def test_specific_files_sanitizes_messages(self):
677
tree = self.make_branch_and_tree('tree')
678
tree.branch.get_config().set_user_option('per_file_commits', 'true')
679
self.build_tree(['tree/a_file', 'tree/b_dir/'])
680
tree.add(['a_file', 'b_dir'], ['1a-id', '0b-id'])
682
dlg = commit.CommitDialog(tree)
683
dlg._commit_selected_radio.set_active(True)
684
self.assertEqual((['a_file', 'b_dir'], []), dlg._get_specific_files())
686
dlg._treeview_files.set_cursor(
687
Gtk.TreePath(path=1), None, False)
688
dlg._set_file_commit_message('Test\r\nmessage\rfor a_file\n')
689
dlg._treeview_files.set_cursor(
690
Gtk.TreePath(path=2), None, False)
691
dlg._set_file_commit_message('message\r\nfor\nb_dir\r')
693
self.assertEqual((['a_file', 'b_dir'],
694
[{'path':'a_file', 'file_id':'1a-id',
695
'message':'Test\nmessage\nfor a_file\n'},
696
{'path':'b_dir', 'file_id':'0b-id',
697
'message':'message\nfor\nb_dir\n'},
698
]), dlg._get_specific_files())
701
class QuestionHelpers(object):
651
703
def _set_question_yes(self, dlg):
652
704
"""Set the dialog to answer YES to any questions."""
653
705
self.questions = []
654
def _question_yes(*args):
706
def _question_yes(*args, **kwargs):
655
707
self.questions.append(args)
656
708
self.questions.append('YES')
657
return gtk.RESPONSE_YES
709
return Gtk.ResponseType.YES
658
710
dlg._question_dialog = _question_yes
660
712
def _set_question_no(self, dlg):
661
713
"""Set the dialog to answer NO to any questions."""
662
714
self.questions = []
663
def _question_no(*args):
715
def _question_no(*args, **kwargs):
664
716
self.questions.append(args)
665
717
self.questions.append('NO')
666
return gtk.RESPONSE_NO
718
return Gtk.ResponseType.NO
667
719
dlg._question_dialog = _question_no
722
class TestCommitDialog_Commit(tests.TestCaseWithTransport, QuestionHelpers):
723
"""Tests on the actual 'commit' button being pushed."""
669
725
def test_bound_commit_local(self):
670
726
tree = self.make_branch_and_tree('tree')
671
727
self.build_tree(['tree/a'])
1030
1108
{'path':u'\u03a9', 'file_id':'omega-id',
1031
1109
'message':u'\u03a9 is the end of all things.\n'},
1032
1110
], file_info_decoded)
1113
class TestSanitizeMessage(tests.TestCase):
1115
def assertSanitize(self, expected, original):
1116
self.assertEqual(expected,
1117
commit._sanitize_and_decode_message(original))
1119
def test_untouched(self):
1120
self.assertSanitize('foo\nbar\nbaz\n', 'foo\nbar\nbaz\n')
1122
def test_converts_cr_to_lf(self):
1123
self.assertSanitize('foo\nbar\nbaz\n', 'foo\rbar\rbaz\r')
1125
def test_converts_crlf_to_lf(self):
1126
self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\r\nbaz\r\n')
1128
def test_converts_mixed_to_lf(self):
1129
self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\rbaz\n')
1132
class TestSavedCommitMessages(tests.TestCaseWithTransport):
1135
super(TestSavedCommitMessages, self).setUp()
1137
branch.Branch.hooks.install_named_hook(
1138
'post_uncommit', commitmsgs.save_commit_messages, None)
1140
def _get_file_info_dict(self, rank):
1141
file_info = [dict(path='a', file_id='a-id', message='a msg %d' % rank),
1142
dict(path='b', file_id='b-id', message='b msg %d' % rank)]
1145
def _get_file_info_revprops(self, rank):
1146
file_info_prop = self._get_file_info_dict(rank)
1147
return {'file-info': bencode.bencode(file_info_prop).decode('UTF-8')}
1149
def _get_commit_message(self):
1150
return self.config.get_user_option('gtk_global_commit_message')
1152
def _get_file_commit_messages(self):
1153
return self.config.get_user_option('gtk_file_commit_messages')
1156
class TestUncommitHook(TestSavedCommitMessages):
1159
super(TestUncommitHook, self).setUp()
1160
self.tree = self.make_branch_and_tree('tree')
1161
self.config = self.tree.branch.get_config()
1162
self.build_tree(['tree/a', 'tree/b'])
1163
self.tree.add(['a'], ['a-id'])
1164
self.tree.add(['b'], ['b-id'])
1165
rev1 = self.tree.commit('one', rev_id='one-id',
1166
revprops=self._get_file_info_revprops(1))
1167
rev2 = self.tree.commit('two', rev_id='two-id',
1168
revprops=self._get_file_info_revprops(2))
1169
rev3 = self.tree.commit('three', rev_id='three-id',
1170
revprops=self._get_file_info_revprops(3))
1172
def test_uncommit_one_by_one(self):
1173
uncommit.uncommit(self.tree.branch, tree=self.tree)
1174
self.assertEquals(u'three', self._get_commit_message())
1175
self.assertEquals(u'd4:a-id7:a msg 34:b-id7:b msg 3e',
1176
self._get_file_commit_messages())
1178
uncommit.uncommit(self.tree.branch, tree=self.tree)
1179
self.assertEquals(u'two\n******\nthree', self._get_commit_message())
1180
self.assertEquals(u'd4:a-id22:a msg 2\n******\na msg 3'
1181
'4:b-id22:b msg 2\n******\nb msg 3e',
1182
self._get_file_commit_messages())
1184
uncommit.uncommit(self.tree.branch, tree=self.tree)
1185
self.assertEquals(u'one\n******\ntwo\n******\nthree',
1186
self._get_commit_message())
1187
self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1188
'4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1189
self._get_file_commit_messages())
1191
def test_uncommit_all_at_once(self):
1192
uncommit.uncommit(self.tree.branch, tree=self.tree, revno=1)
1193
self.assertEquals(u'one\n******\ntwo\n******\nthree',
1194
self._get_commit_message())
1195
self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1196
'4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1197
self._get_file_commit_messages())
1200
class TestReusingSavedCommitMessages(TestSavedCommitMessages, QuestionHelpers):
1203
super(TestReusingSavedCommitMessages, self).setUp()
1204
self.tree = self.make_branch_and_tree('tree')
1205
self.config = self.tree.branch.get_config()
1206
self.config.set_user_option('per_file_commits', 'true')
1207
self.build_tree(['tree/a', 'tree/b'])
1208
self.tree.add(['a'], ['a-id'])
1209
self.tree.add(['b'], ['b-id'])
1210
rev1 = self.tree.commit('one', revprops=self._get_file_info_revprops(1))
1211
rev2 = self.tree.commit('two', revprops=self._get_file_info_revprops(2))
1212
uncommit.uncommit(self.tree.branch, tree=self.tree)
1213
self.build_tree_contents([('tree/a', 'new a content\n'),
1214
('tree/b', 'new b content'),])
1216
def _get_commit_dialog(self, tree):
1217
# Ensure we will never use a dialog that can actually prompt the user
1218
# during the test suite. Test *can* and *should* override with the
1219
# correct question dialog type.
1220
dlg = commit.CommitDialog(tree)
1221
self._set_question_no(dlg)
1224
def test_setup_saved_messages(self):
1225
# Check the initial setup
1226
self.assertEquals(u'two', self._get_commit_message())
1227
self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1228
self._get_file_commit_messages())
1230
def test_messages_are_reloaded(self):
1231
dlg = self._get_commit_dialog(self.tree)
1232
self.assertEquals(u'two', dlg._get_global_commit_message())
1233
self.assertEquals(([u'a', u'b'],
1235
'file_id': 'a-id', 'message': 'a msg 2',},
1237
'file_id': 'b-id', 'message': 'b msg 2',}],),
1238
dlg._get_specific_files())
1240
def test_messages_are_consumed(self):
1241
dlg = self._get_commit_dialog(self.tree)
1243
self.assertEquals(u'', self._get_commit_message())
1244
self.assertEquals(u'de', self._get_file_commit_messages())
1246
def test_messages_are_saved_on_cancel_if_required(self):
1247
dlg = self._get_commit_dialog(self.tree)
1248
self._set_question_yes(dlg) # Save messages
1250
self.assertEquals(u'two', self._get_commit_message())
1251
self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1252
self._get_file_commit_messages())
1254
def test_messages_are_cleared_on_cancel_if_required(self):
1255
dlg = self._get_commit_dialog(self.tree)
1256
self._set_question_no(dlg) # Don't save messages
1258
self.assertEquals(u'', self._get_commit_message())
1259
self.assertEquals(u'de',
1260
self._get_file_commit_messages())