644
646
'message':'message\nfor b_dir\n'},
645
647
]), dlg._get_specific_files())
648
class TestCommitDialog_Commit(tests.TestCaseWithTransport):
649
"""Tests on the actual 'commit' button being pushed."""
649
def test_specific_files_sanitizes_messages(self):
650
tree = self.make_branch_and_tree('tree')
651
tree.branch.get_config().set_user_option('per_file_commits', 'true')
652
self.build_tree(['tree/a_file', 'tree/b_dir/'])
653
tree.add(['a_file', 'b_dir'], ['1a-id', '0b-id'])
655
dlg = commit.CommitDialog(tree)
656
dlg._commit_selected_radio.set_active(True)
657
self.assertEqual((['a_file', 'b_dir'], []), dlg._get_specific_files())
659
dlg._treeview_files.set_cursor((1,))
660
dlg._set_file_commit_message('Test\r\nmessage\rfor a_file\n')
661
dlg._treeview_files.set_cursor((2,))
662
dlg._set_file_commit_message('message\r\nfor\nb_dir\r')
664
self.assertEqual((['a_file', 'b_dir'],
665
[{'path':'a_file', 'file_id':'1a-id',
666
'message':'Test\nmessage\nfor a_file\n'},
667
{'path':'b_dir', 'file_id':'0b-id',
668
'message':'message\nfor\nb_dir\n'},
669
]), dlg._get_specific_files())
672
class QuestionHelpers(object):
651
674
def _set_question_yes(self, dlg):
652
675
"""Set the dialog to answer YES to any questions."""
653
676
self.questions = []
654
def _question_yes(*args):
677
def _question_yes(*args, **kwargs):
655
678
self.questions.append(args)
656
679
self.questions.append('YES')
657
680
return gtk.RESPONSE_YES
1030
1072
{'path':u'\u03a9', 'file_id':'omega-id',
1031
1073
'message':u'\u03a9 is the end of all things.\n'},
1032
1074
], file_info_decoded)
1077
class TestSanitizeMessage(tests.TestCase):
1079
def assertSanitize(self, expected, original):
1080
self.assertEqual(expected,
1081
commit._sanitize_and_decode_message(original))
1083
def test_untouched(self):
1084
self.assertSanitize('foo\nbar\nbaz\n', 'foo\nbar\nbaz\n')
1086
def test_converts_cr_to_lf(self):
1087
self.assertSanitize('foo\nbar\nbaz\n', 'foo\rbar\rbaz\r')
1089
def test_converts_crlf_to_lf(self):
1090
self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\r\nbaz\r\n')
1092
def test_converts_mixed_to_lf(self):
1093
self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\rbaz\n')
1096
class TestSavedCommitMessages(tests.TestCaseWithTransport):
1099
super(TestSavedCommitMessages, self).setUp()
1101
branch.Branch.hooks.install_named_hook(
1102
'post_uncommit', commit.save_commit_messages, None)
1104
def _get_file_info_dict(self, rank):
1105
file_info = [dict(path='a', file_id='a-id', message='a msg %d' % rank),
1106
dict(path='b', file_id='b-id', message='b msg %d' % rank)]
1109
def _get_file_info_revprops(self, rank):
1110
file_info_prop = self._get_file_info_dict(rank)
1111
return {'file-info': bencode.bencode(file_info_prop).decode('UTF-8')}
1113
def _get_commit_message(self):
1114
return self.config.get_user_option('gtk_global_commit_message')
1116
def _get_file_commit_messages(self):
1117
return self.config.get_user_option('gtk_file_commit_messages')
1120
class TestUncommitHook(TestSavedCommitMessages):
1123
super(TestUncommitHook, self).setUp()
1124
self.tree = self.make_branch_and_tree('tree')
1125
self.config = self.tree.branch.get_config()
1126
self.build_tree(['tree/a', 'tree/b'])
1127
self.tree.add(['a'], ['a-id'])
1128
self.tree.add(['b'], ['b-id'])
1129
rev1 = self.tree.commit('one', rev_id='one-id',
1130
revprops=self._get_file_info_revprops(1))
1131
rev2 = self.tree.commit('two', rev_id='two-id',
1132
revprops=self._get_file_info_revprops(2))
1133
rev3 = self.tree.commit('three', rev_id='three-id',
1134
revprops=self._get_file_info_revprops(3))
1136
def test_uncommit_one_by_one(self):
1137
uncommit.uncommit(self.tree.branch, tree=self.tree)
1138
self.assertEquals(u'three', self._get_commit_message())
1139
self.assertEquals(u'd4:a-id7:a msg 34:b-id7:b msg 3e',
1140
self._get_file_commit_messages())
1142
uncommit.uncommit(self.tree.branch, tree=self.tree)
1143
self.assertEquals(u'two\n******\nthree', self._get_commit_message())
1144
self.assertEquals(u'd4:a-id22:a msg 2\n******\na msg 3'
1145
'4:b-id22:b msg 2\n******\nb msg 3e',
1146
self._get_file_commit_messages())
1148
uncommit.uncommit(self.tree.branch, tree=self.tree)
1149
self.assertEquals(u'one\n******\ntwo\n******\nthree',
1150
self._get_commit_message())
1151
self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1152
'4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1153
self._get_file_commit_messages())
1155
def test_uncommit_all_at_once(self):
1156
uncommit.uncommit(self.tree.branch, tree=self.tree, revno=1)
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())
1164
class TestReusingSavedCommitMessages(TestSavedCommitMessages, QuestionHelpers):
1167
super(TestReusingSavedCommitMessages, self).setUp()
1168
self.tree = self.make_branch_and_tree('tree')
1169
self.config = self.tree.branch.get_config()
1170
self.config.set_user_option('per_file_commits', 'true')
1171
self.build_tree(['tree/a', 'tree/b'])
1172
self.tree.add(['a'], ['a-id'])
1173
self.tree.add(['b'], ['b-id'])
1174
rev1 = self.tree.commit('one', revprops=self._get_file_info_revprops(1))
1175
rev2 = self.tree.commit('two', revprops=self._get_file_info_revprops(2))
1176
uncommit.uncommit(self.tree.branch, tree=self.tree)
1177
self.build_tree_contents([('tree/a', 'new a content\n'),
1178
('tree/b', 'new b content'),])
1180
def _get_commit_dialog(self, tree):
1181
# Ensure we will never use a dialog that can actually prompt the user
1182
# during the test suite. Test *can* and *should* override with the
1183
# correct question dialog type.
1184
dlg = commit.CommitDialog(tree)
1185
self._set_question_no(dlg)
1188
def test_setup_saved_messages(self):
1189
# Check the initial setup
1190
self.assertEquals(u'two', self._get_commit_message())
1191
self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1192
self._get_file_commit_messages())
1194
def test_messages_are_reloaded(self):
1195
dlg = self._get_commit_dialog(self.tree)
1196
self.assertEquals(u'two', dlg._get_global_commit_message())
1197
self.assertEquals(([u'a', u'b'],
1199
'file_id': 'a-id', 'message': 'a msg 2',},
1201
'file_id': 'b-id', 'message': 'b msg 2',}],),
1202
dlg._get_specific_files())
1204
def test_messages_are_consumed(self):
1205
dlg = self._get_commit_dialog(self.tree)
1207
self.assertEquals(u'', self._get_commit_message())
1208
self.assertEquals(u'de', self._get_file_commit_messages())
1210
def test_messages_are_saved_on_cancel_if_required(self):
1211
dlg = self._get_commit_dialog(self.tree)
1212
self._set_question_yes(dlg) # Save messages
1214
self.assertEquals(u'two', self._get_commit_message())
1215
self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1216
self._get_file_commit_messages())
1218
def test_messages_are_cleared_on_cancel_if_required(self):
1219
dlg = self._get_commit_dialog(self.tree)
1220
self._set_question_no(dlg) # Don't save messages
1222
self.assertEquals(u'', self._get_commit_message())
1223
self.assertEquals(u'de',
1224
self._get_file_commit_messages())