644
666
'message':'message\nfor b_dir\n'},
645
667
]), dlg._get_specific_files())
648
class TestCommitDialog_Commit(tests.TestCaseWithTransport):
649
"""Tests on the actual 'commit' button being pushed."""
669
def test_specific_files_sanitizes_messages(self):
670
tree = self.make_branch_and_tree('tree')
671
tree.branch.get_config().set_user_option('per_file_commits', 'true')
672
self.build_tree(['tree/a_file', 'tree/b_dir/'])
673
tree.add(['a_file', 'b_dir'], ['1a-id', '0b-id'])
675
dlg = commit.CommitDialog(tree)
676
dlg._commit_selected_radio.set_active(True)
677
self.assertEqual((['a_file', 'b_dir'], []), dlg._get_specific_files())
679
dlg._treeview_files.set_cursor(
680
Gtk.TreePath(path=1), None, False)
681
dlg._set_file_commit_message('Test\r\nmessage\rfor a_file\n')
682
dlg._treeview_files.set_cursor(
683
Gtk.TreePath(path=2), None, False)
684
dlg._set_file_commit_message('message\r\nfor\nb_dir\r')
686
self.assertEqual((['a_file', 'b_dir'],
687
[{'path':'a_file', 'file_id':'1a-id',
688
'message':'Test\nmessage\nfor a_file\n'},
689
{'path':'b_dir', 'file_id':'0b-id',
690
'message':'message\nfor\nb_dir\n'},
691
]), dlg._get_specific_files())
694
class QuestionHelpers(object):
651
696
def _set_question_yes(self, dlg):
652
697
"""Set the dialog to answer YES to any questions."""
653
698
self.questions = []
654
def _question_yes(*args):
699
def _question_yes(*args, **kwargs):
655
700
self.questions.append(args)
656
701
self.questions.append('YES')
657
return gtk.RESPONSE_YES
702
return Gtk.ResponseType.YES
658
703
dlg._question_dialog = _question_yes
660
705
def _set_question_no(self, dlg):
661
706
"""Set the dialog to answer NO to any questions."""
662
707
self.questions = []
663
def _question_no(*args):
708
def _question_no(*args, **kwargs):
664
709
self.questions.append(args)
665
710
self.questions.append('NO')
666
return gtk.RESPONSE_NO
711
return Gtk.ResponseType.NO
667
712
dlg._question_dialog = _question_no
715
class TestCommitDialog_Commit(tests.TestCaseWithTransport, QuestionHelpers):
716
"""Tests on the actual 'commit' button being pushed."""
669
718
def test_bound_commit_local(self):
670
719
tree = self.make_branch_and_tree('tree')
671
720
self.build_tree(['tree/a'])
1030
1101
{'path':u'\u03a9', 'file_id':'omega-id',
1031
1102
'message':u'\u03a9 is the end of all things.\n'},
1032
1103
], file_info_decoded)
1106
class TestSanitizeMessage(tests.TestCase):
1108
def assertSanitize(self, expected, original):
1109
self.assertEqual(expected,
1110
commit._sanitize_and_decode_message(original))
1112
def test_untouched(self):
1113
self.assertSanitize('foo\nbar\nbaz\n', 'foo\nbar\nbaz\n')
1115
def test_converts_cr_to_lf(self):
1116
self.assertSanitize('foo\nbar\nbaz\n', 'foo\rbar\rbaz\r')
1118
def test_converts_crlf_to_lf(self):
1119
self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\r\nbaz\r\n')
1121
def test_converts_mixed_to_lf(self):
1122
self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\rbaz\n')
1125
class TestSavedCommitMessages(tests.TestCaseWithTransport):
1128
super(TestSavedCommitMessages, self).setUp()
1130
branch.Branch.hooks.install_named_hook(
1131
'post_uncommit', commit.save_commit_messages, None)
1133
def _get_file_info_dict(self, rank):
1134
file_info = [dict(path='a', file_id='a-id', message='a msg %d' % rank),
1135
dict(path='b', file_id='b-id', message='b msg %d' % rank)]
1138
def _get_file_info_revprops(self, rank):
1139
file_info_prop = self._get_file_info_dict(rank)
1140
return {'file-info': bencode.bencode(file_info_prop).decode('UTF-8')}
1142
def _get_commit_message(self):
1143
return self.config.get_user_option('gtk_global_commit_message')
1145
def _get_file_commit_messages(self):
1146
return self.config.get_user_option('gtk_file_commit_messages')
1149
class TestUncommitHook(TestSavedCommitMessages):
1152
super(TestUncommitHook, self).setUp()
1153
self.tree = self.make_branch_and_tree('tree')
1154
self.config = self.tree.branch.get_config()
1155
self.build_tree(['tree/a', 'tree/b'])
1156
self.tree.add(['a'], ['a-id'])
1157
self.tree.add(['b'], ['b-id'])
1158
rev1 = self.tree.commit('one', rev_id='one-id',
1159
revprops=self._get_file_info_revprops(1))
1160
rev2 = self.tree.commit('two', rev_id='two-id',
1161
revprops=self._get_file_info_revprops(2))
1162
rev3 = self.tree.commit('three', rev_id='three-id',
1163
revprops=self._get_file_info_revprops(3))
1165
def test_uncommit_one_by_one(self):
1166
uncommit.uncommit(self.tree.branch, tree=self.tree)
1167
self.assertEquals(u'three', self._get_commit_message())
1168
self.assertEquals(u'd4:a-id7:a msg 34:b-id7:b msg 3e',
1169
self._get_file_commit_messages())
1171
uncommit.uncommit(self.tree.branch, tree=self.tree)
1172
self.assertEquals(u'two\n******\nthree', self._get_commit_message())
1173
self.assertEquals(u'd4:a-id22:a msg 2\n******\na msg 3'
1174
'4:b-id22:b msg 2\n******\nb msg 3e',
1175
self._get_file_commit_messages())
1177
uncommit.uncommit(self.tree.branch, tree=self.tree)
1178
self.assertEquals(u'one\n******\ntwo\n******\nthree',
1179
self._get_commit_message())
1180
self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1181
'4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1182
self._get_file_commit_messages())
1184
def test_uncommit_all_at_once(self):
1185
uncommit.uncommit(self.tree.branch, tree=self.tree, revno=1)
1186
self.assertEquals(u'one\n******\ntwo\n******\nthree',
1187
self._get_commit_message())
1188
self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1189
'4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1190
self._get_file_commit_messages())
1193
class TestReusingSavedCommitMessages(TestSavedCommitMessages, QuestionHelpers):
1196
super(TestReusingSavedCommitMessages, self).setUp()
1197
self.tree = self.make_branch_and_tree('tree')
1198
self.config = self.tree.branch.get_config()
1199
self.config.set_user_option('per_file_commits', 'true')
1200
self.build_tree(['tree/a', 'tree/b'])
1201
self.tree.add(['a'], ['a-id'])
1202
self.tree.add(['b'], ['b-id'])
1203
rev1 = self.tree.commit('one', revprops=self._get_file_info_revprops(1))
1204
rev2 = self.tree.commit('two', revprops=self._get_file_info_revprops(2))
1205
uncommit.uncommit(self.tree.branch, tree=self.tree)
1206
self.build_tree_contents([('tree/a', 'new a content\n'),
1207
('tree/b', 'new b content'),])
1209
def _get_commit_dialog(self, tree):
1210
# Ensure we will never use a dialog that can actually prompt the user
1211
# during the test suite. Test *can* and *should* override with the
1212
# correct question dialog type.
1213
dlg = commit.CommitDialog(tree)
1214
self._set_question_no(dlg)
1217
def test_setup_saved_messages(self):
1218
# Check the initial setup
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_reloaded(self):
1224
dlg = self._get_commit_dialog(self.tree)
1225
self.assertEquals(u'two', dlg._get_global_commit_message())
1226
self.assertEquals(([u'a', u'b'],
1228
'file_id': 'a-id', 'message': 'a msg 2',},
1230
'file_id': 'b-id', 'message': 'b msg 2',}],),
1231
dlg._get_specific_files())
1233
def test_messages_are_consumed(self):
1234
dlg = self._get_commit_dialog(self.tree)
1236
self.assertEquals(u'', self._get_commit_message())
1237
self.assertEquals(u'de', self._get_file_commit_messages())
1239
def test_messages_are_saved_on_cancel_if_required(self):
1240
dlg = self._get_commit_dialog(self.tree)
1241
self._set_question_yes(dlg) # Save messages
1243
self.assertEquals(u'two', self._get_commit_message())
1244
self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1245
self._get_file_commit_messages())
1247
def test_messages_are_cleared_on_cancel_if_required(self):
1248
dlg = self._get_commit_dialog(self.tree)
1249
self._set_question_no(dlg) # Don't save messages
1251
self.assertEquals(u'', self._get_commit_message())
1252
self.assertEquals(u'de',
1253
self._get_file_commit_messages())