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."""
1075
1030
{'path':u'\u03a9', 'file_id':'omega-id',
1076
1031
'message':u'\u03a9 is the end of all things.\n'},
1077
1032
], file_info_decoded)
1080
class TestSanitizeMessage(tests.TestCase):
1082
def assertSanitize(self, expected, original):
1083
self.assertEqual(expected,
1084
commit._sanitize_and_decode_message(original))
1086
def test_untouched(self):
1087
self.assertSanitize('foo\nbar\nbaz\n', 'foo\nbar\nbaz\n')
1089
def test_converts_cr_to_lf(self):
1090
self.assertSanitize('foo\nbar\nbaz\n', 'foo\rbar\rbaz\r')
1092
def test_converts_crlf_to_lf(self):
1093
self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\r\nbaz\r\n')
1095
def test_converts_mixed_to_lf(self):
1096
self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\rbaz\n')
1099
class TestSavedCommitMessages(tests.TestCaseWithTransport):
1102
super(TestSavedCommitMessages, self).setUp()
1104
branch.Branch.hooks.install_named_hook(
1105
'post_uncommit', commit.save_commit_messages, None)
1107
def _get_file_info_dict(self, rank):
1108
file_info = [dict(path='a', file_id='a-id', message='a msg %d' % rank),
1109
dict(path='b', file_id='b-id', message='b msg %d' % rank)]
1112
def _get_file_info_revprops(self, rank):
1113
file_info_prop = self._get_file_info_dict(rank)
1114
return {'file-info': bencode.bencode(file_info_prop).decode('UTF-8')}
1116
def _get_commit_message(self):
1117
return self.config.get_user_option('gtk_global_commit_message')
1119
def _get_file_commit_messages(self):
1120
return self.config.get_user_option('gtk_file_commit_messages')
1123
class TestUncommitHook(TestSavedCommitMessages):
1126
super(TestUncommitHook, self).setUp()
1127
self.tree = self.make_branch_and_tree('tree')
1128
self.config = self.tree.branch.get_config()
1129
self.build_tree(['tree/a', 'tree/b'])
1130
self.tree.add(['a'], ['a-id'])
1131
self.tree.add(['b'], ['b-id'])
1132
rev1 = self.tree.commit('one', rev_id='one-id',
1133
revprops=self._get_file_info_revprops(1))
1134
rev2 = self.tree.commit('two', rev_id='two-id',
1135
revprops=self._get_file_info_revprops(2))
1136
rev3 = self.tree.commit('three', rev_id='three-id',
1137
revprops=self._get_file_info_revprops(3))
1139
def test_uncommit_one_by_one(self):
1140
uncommit.uncommit(self.tree.branch, tree=self.tree)
1141
self.assertEquals(u'three', self._get_commit_message())
1142
self.assertEquals(u'd4:a-id7:a msg 34:b-id7:b msg 3e',
1143
self._get_file_commit_messages())
1145
uncommit.uncommit(self.tree.branch, tree=self.tree)
1146
self.assertEquals(u'two\n******\nthree', self._get_commit_message())
1147
self.assertEquals(u'd4:a-id22:a msg 2\n******\na msg 3'
1148
'4:b-id22:b msg 2\n******\nb msg 3e',
1149
self._get_file_commit_messages())
1151
uncommit.uncommit(self.tree.branch, tree=self.tree)
1152
self.assertEquals(u'one\n******\ntwo\n******\nthree',
1153
self._get_commit_message())
1154
self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1155
'4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1156
self._get_file_commit_messages())
1158
def test_uncommit_all_at_once(self):
1159
uncommit.uncommit(self.tree.branch, tree=self.tree, revno=1)
1160
self.assertEquals(u'one\n******\ntwo\n******\nthree',
1161
self._get_commit_message())
1162
self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1163
'4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1164
self._get_file_commit_messages())
1167
class TestReusingSavedCommitMessages(TestSavedCommitMessages, QuestionHelpers):
1170
super(TestReusingSavedCommitMessages, self).setUp()
1171
self.tree = self.make_branch_and_tree('tree')
1172
self.config = self.tree.branch.get_config()
1173
self.config.set_user_option('per_file_commits', 'true')
1174
self.build_tree(['tree/a', 'tree/b'])
1175
self.tree.add(['a'], ['a-id'])
1176
self.tree.add(['b'], ['b-id'])
1177
rev1 = self.tree.commit('one', revprops=self._get_file_info_revprops(1))
1178
rev2 = self.tree.commit('two', revprops=self._get_file_info_revprops(2))
1179
uncommit.uncommit(self.tree.branch, tree=self.tree)
1180
self.build_tree_contents([('tree/a', 'new a content\n'),
1181
('tree/b', 'new b content'),])
1183
def _get_commit_dialog(self, tree):
1184
# Ensure we will never use a dialog that can actually prompt the user
1185
# during the test suite. Test *can* and *should* override with the
1186
# correct question dialog type.
1187
dlg = commit.CommitDialog(tree)
1188
self._set_question_no(dlg)
1191
def test_setup_saved_messages(self):
1192
# Check the initial setup
1193
self.assertEquals(u'two', self._get_commit_message())
1194
self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1195
self._get_file_commit_messages())
1197
def test_messages_are_reloaded(self):
1198
dlg = self._get_commit_dialog(self.tree)
1199
self.assertEquals(u'two', dlg._get_global_commit_message())
1200
self.assertEquals(([u'a', u'b'],
1202
'file_id': 'a-id', 'message': 'a msg 2',},
1204
'file_id': 'b-id', 'message': 'b msg 2',}],),
1205
dlg._get_specific_files())
1207
def test_messages_are_consumed(self):
1208
dlg = self._get_commit_dialog(self.tree)
1210
self.assertEquals(u'', self._get_commit_message())
1211
self.assertEquals(u'de', self._get_file_commit_messages())
1213
def test_messages_are_saved_on_cancel_if_required(self):
1214
dlg = self._get_commit_dialog(self.tree)
1215
self._set_question_yes(dlg) # Save messages
1217
self.assertEquals(u'two', self._get_commit_message())
1218
self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1219
self._get_file_commit_messages())
1221
def test_messages_are_cleared_on_cancel_if_required(self):
1222
dlg = self._get_commit_dialog(self.tree)
1223
self._set_question_no(dlg) # Don't save messages
1225
self.assertEquals(u'', self._get_commit_message())
1226
self.assertEquals(u'de',
1227
self._get_file_commit_messages())