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