649
644
'message':'message\nfor b_dir\n'},
650
645
]), dlg._get_specific_files())
652
def test_specific_files_sanitizes_messages(self):
653
tree = self.make_branch_and_tree('tree')
654
tree.branch.get_config().set_user_option('per_file_commits', 'true')
655
self.build_tree(['tree/a_file', 'tree/b_dir/'])
656
tree.add(['a_file', 'b_dir'], ['1a-id', '0b-id'])
658
dlg = commit.CommitDialog(tree)
659
dlg._commit_selected_radio.set_active(True)
660
self.assertEqual((['a_file', 'b_dir'], []), dlg._get_specific_files())
662
dlg._treeview_files.set_cursor((1,))
663
dlg._set_file_commit_message('Test\r\nmessage\rfor a_file\n')
664
dlg._treeview_files.set_cursor((2,))
665
dlg._set_file_commit_message('message\r\nfor\nb_dir\r')
667
self.assertEqual((['a_file', 'b_dir'],
668
[{'path':'a_file', 'file_id':'1a-id',
669
'message':'Test\nmessage\nfor a_file\n'},
670
{'path':'b_dir', 'file_id':'0b-id',
671
'message':'message\nfor\nb_dir\n'},
672
]), dlg._get_specific_files())
675
class QuestionHelpers(object):
648
class TestCommitDialog_Commit(tests.TestCaseWithTransport):
649
"""Tests on the actual 'commit' button being pushed."""
677
651
def _set_question_yes(self, dlg):
678
652
"""Set the dialog to answer YES to any questions."""
679
653
self.questions = []
680
def _question_yes(*args, **kwargs):
654
def _question_yes(*args):
681
655
self.questions.append(args)
682
656
self.questions.append('YES')
683
657
return gtk.RESPONSE_YES
1077
1030
{'path':u'\u03a9', 'file_id':'omega-id',
1078
1031
'message':u'\u03a9 is the end of all things.\n'},
1079
1032
], file_info_decoded)
1082
class TestSanitizeMessage(tests.TestCase):
1084
def assertSanitize(self, expected, original):
1085
self.assertEqual(expected,
1086
commit._sanitize_and_decode_message(original))
1088
def test_untouched(self):
1089
self.assertSanitize('foo\nbar\nbaz\n', 'foo\nbar\nbaz\n')
1091
def test_converts_cr_to_lf(self):
1092
self.assertSanitize('foo\nbar\nbaz\n', 'foo\rbar\rbaz\r')
1094
def test_converts_crlf_to_lf(self):
1095
self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\r\nbaz\r\n')
1097
def test_converts_mixed_to_lf(self):
1098
self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\rbaz\n')
1101
class TestSavedCommitMessages(tests.TestCaseWithTransport):
1104
super(TestSavedCommitMessages, self).setUp()
1106
branch.Branch.hooks.install_named_hook(
1107
'post_uncommit', commit.save_commit_messages, None)
1109
def _get_file_info_dict(self, rank):
1110
file_info = [dict(path='a', file_id='a-id', message='a msg %d' % rank),
1111
dict(path='b', file_id='b-id', message='b msg %d' % rank)]
1114
def _get_file_info_revprops(self, rank):
1115
file_info_prop = self._get_file_info_dict(rank)
1116
return {'file-info': bencode.bencode(file_info_prop).decode('UTF-8')}
1118
def _get_commit_message(self):
1119
return self.config.get_user_option('gtk_global_commit_message')
1121
def _get_file_commit_messages(self):
1122
return self.config.get_user_option('gtk_file_commit_messages')
1125
class TestUncommitHook(TestSavedCommitMessages):
1128
super(TestUncommitHook, self).setUp()
1129
self.tree = self.make_branch_and_tree('tree')
1130
self.config = self.tree.branch.get_config()
1131
self.build_tree(['tree/a', 'tree/b'])
1132
self.tree.add(['a'], ['a-id'])
1133
self.tree.add(['b'], ['b-id'])
1134
rev1 = self.tree.commit('one', rev_id='one-id',
1135
revprops=self._get_file_info_revprops(1))
1136
rev2 = self.tree.commit('two', rev_id='two-id',
1137
revprops=self._get_file_info_revprops(2))
1138
rev3 = self.tree.commit('three', rev_id='three-id',
1139
revprops=self._get_file_info_revprops(3))
1141
def test_uncommit_one_by_one(self):
1142
uncommit.uncommit(self.tree.branch, tree=self.tree)
1143
self.assertEquals(u'three', self._get_commit_message())
1144
self.assertEquals(u'd4:a-id7:a msg 34:b-id7:b msg 3e',
1145
self._get_file_commit_messages())
1147
uncommit.uncommit(self.tree.branch, tree=self.tree)
1148
self.assertEquals(u'two\n******\nthree', self._get_commit_message())
1149
self.assertEquals(u'd4:a-id22:a msg 2\n******\na msg 3'
1150
'4:b-id22:b msg 2\n******\nb msg 3e',
1151
self._get_file_commit_messages())
1153
uncommit.uncommit(self.tree.branch, tree=self.tree)
1154
self.assertEquals(u'one\n******\ntwo\n******\nthree',
1155
self._get_commit_message())
1156
self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1157
'4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1158
self._get_file_commit_messages())
1160
def test_uncommit_all_at_once(self):
1161
uncommit.uncommit(self.tree.branch, tree=self.tree, revno=1)
1162
self.assertEquals(u'one\n******\ntwo\n******\nthree',
1163
self._get_commit_message())
1164
self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1165
'4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1166
self._get_file_commit_messages())
1169
class TestReusingSavedCommitMessages(TestSavedCommitMessages, QuestionHelpers):
1172
super(TestReusingSavedCommitMessages, self).setUp()
1173
self.tree = self.make_branch_and_tree('tree')
1174
self.config = self.tree.branch.get_config()
1175
self.config.set_user_option('per_file_commits', 'true')
1176
self.build_tree(['tree/a', 'tree/b'])
1177
self.tree.add(['a'], ['a-id'])
1178
self.tree.add(['b'], ['b-id'])
1179
rev1 = self.tree.commit('one', revprops=self._get_file_info_revprops(1))
1180
rev2 = self.tree.commit('two', revprops=self._get_file_info_revprops(2))
1181
uncommit.uncommit(self.tree.branch, tree=self.tree)
1182
self.build_tree_contents([('tree/a', 'new a content\n'),
1183
('tree/b', 'new b content'),])
1185
def _get_commit_dialog(self, tree):
1186
# Ensure we will never use a dialog that can actually prompt the user
1187
# during the test suite. Test *can* and *should* override with the
1188
# correct question dialog type.
1189
dlg = commit.CommitDialog(tree)
1190
self._set_question_no(dlg)
1193
def test_setup_saved_messages(self):
1194
# Check the initial setup
1195
self.assertEquals(u'two', self._get_commit_message())
1196
self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1197
self._get_file_commit_messages())
1199
def test_messages_are_reloaded(self):
1200
dlg = self._get_commit_dialog(self.tree)
1201
self.assertEquals(u'two', dlg._get_global_commit_message())
1202
self.assertEquals(([u'a', u'b'],
1204
'file_id': 'a-id', 'message': 'a msg 2',},
1206
'file_id': 'b-id', 'message': 'b msg 2',}],),
1207
dlg._get_specific_files())
1209
def test_messages_are_consumed(self):
1210
dlg = self._get_commit_dialog(self.tree)
1212
self.assertEquals(u'', self._get_commit_message())
1213
self.assertEquals(u'de', self._get_file_commit_messages())
1215
def test_messages_are_saved_on_cancel_if_required(self):
1216
dlg = self._get_commit_dialog(self.tree)
1217
self._set_question_yes(dlg) # Save messages
1219
self.assertEquals(u'two', self._get_commit_message())
1220
self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1221
self._get_file_commit_messages())
1223
def test_messages_are_cleared_on_cancel_if_required(self):
1224
dlg = self._get_commit_dialog(self.tree)
1225
self._set_question_no(dlg) # Don't save messages
1227
self.assertEquals(u'', self._get_commit_message())
1228
self.assertEquals(u'de',
1229
self._get_file_commit_messages())