/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to tests/test_commit.py

  • Committer: John Arbash Meinel
  • Date: 2007-10-02 19:10:01 UTC
  • mto: (322.1.1 trunk) (330.3.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 368.
  • Revision ID: john@arbash-meinel.com-20071002191001-ezz7ejijs0e8tlg8
Add the ability to commit just specific files.
Also include the ability to save the file-info data.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    tests,
25
25
    revision,
26
26
    )
 
27
from bzrlib.util import bencode
27
28
 
28
29
from bzrlib.plugins.gtk import commit
29
30
 
487
488
        self.assertEqual('', get_file_text())
488
489
 
489
490
        self.assertEqual('', get_saved_text(1))
490
 
        dlg._file_message_text_view.get_buffer().set_text('Some text\nfor a\n')
 
491
        dlg._set_file_commit_message('Some text\nfor a\n')
491
492
        dlg._save_current_file_message()
492
493
        # We should have updated the ListStore with the new file commit info
493
494
        self.assertEqual('Some text\nfor a\n', get_saved_text(1))
500
501
        self.assertEqual('', get_file_text())
501
502
 
502
503
        self.assertEqual('', get_saved_text(2))
503
 
        dlg._file_message_text_view.get_buffer().set_text('More text\nfor b\n')
 
504
        dlg._set_file_commit_message('More text\nfor b\n')
504
505
        # Now switch back to 'a'. The message should be saved, and the buffer
505
506
        # should be updated with the other text
506
507
        dlg._treeview_files.set_cursor((1,))
557
558
                          ('b-id', 'b', True),
558
559
                         ], [(r[0], r[1], r[2]) for r in dlg._files_store])
559
560
 
 
561
    def test_specific_files(self):
 
562
        tree = self.make_branch_and_tree('tree')
 
563
        self.build_tree(['tree/a', 'tree/b/'])
 
564
        tree.add(['a', 'b'], ['a-id', 'b-id'])
 
565
 
 
566
        dlg = commit.CommitDialog(tree)
 
567
        self.assertEqual((['a', 'b'], []), dlg._get_specific_files())
 
568
 
 
569
        dlg._toggle_commit(None, 0, dlg._files_store)
 
570
        self.assertEqual(([], []), dlg._get_specific_files())
 
571
 
 
572
        dlg._toggle_commit(None, 1, dlg._files_store)
 
573
        self.assertEqual((['a'], []), dlg._get_specific_files())
 
574
 
 
575
    def test_specific_files_with_messages(self):
 
576
        tree = self.make_branch_and_tree('tree')
 
577
        self.build_tree(['tree/a_file', 'tree/b_dir/'])
 
578
        tree.add(['a_file', 'b_dir'], ['1a-id', '0b-id'])
 
579
 
 
580
        dlg = commit.CommitDialog(tree)
 
581
        self.assertEqual((['a_file', 'b_dir'], []), dlg._get_specific_files())
 
582
 
 
583
        dlg._treeview_files.set_cursor((1,))
 
584
        dlg._set_file_commit_message('Test\nmessage\nfor a_file\n')
 
585
        dlg._treeview_files.set_cursor((2,))
 
586
        dlg._set_file_commit_message('message\nfor b_dir\n')
 
587
 
 
588
        self.assertEqual((['a_file', 'b_dir'],
 
589
                          [{'path':'a_file', 'file_id':'1a-id',
 
590
                            'message':'Test\nmessage\nfor a_file\n'},
 
591
                           {'path':'b_dir', 'file_id':'0b-id',
 
592
                            'message':'message\nfor b_dir\n'},
 
593
                          ]), dlg._get_specific_files())
 
594
 
 
595
        dlg._toggle_commit(None, 1, dlg._files_store)
 
596
        self.assertEqual((['b_dir'],
 
597
                          [{'path':'b_dir', 'file_id':'0b-id',
 
598
                            'message':'message\nfor b_dir\n'},
 
599
                          ]), dlg._get_specific_files())
 
600
 
560
601
 
561
602
class TestCommitDialog_Commit(tests.TestCaseWithTransport):
562
603
    """Tests on the actual 'commit' button being pushed."""
736
777
              "YES",
737
778
            ], self.questions)
738
779
 
 
780
    def test_commit_specific_files(self):
 
781
        tree = self.make_branch_and_tree('tree')
 
782
        rev_id1 = tree.commit('one')
 
783
        self.build_tree(['tree/a', 'tree/b'])
 
784
        tree.add(['a', 'b'], ['a-id', 'b-id'])
 
785
 
 
786
        dlg = commit.CommitDialog(tree)
 
787
        dlg._toggle_commit(None, 2, dlg._files_store) # unset 'b'
 
788
 
 
789
        dlg._set_global_commit_message('Committing just "a"\n')
 
790
        dlg._do_commit()
 
791
 
 
792
        rev_id2 = dlg.committed_revision_id
 
793
        self.assertIsNot(None, rev_id2)
 
794
        self.assertEqual(rev_id2, tree.last_revision())
 
795
 
 
796
        rt = tree.branch.repository.revision_tree(rev_id2)
 
797
        entries = [(path, ie.file_id) for path, ie in rt.iter_entries_by_dir()
 
798
                                       if path] # Ignore the root entry
 
799
        self.assertEqual([('a', 'a-id')], entries)
 
800
 
 
801
    def test_commit_no_messages(self):
 
802
        tree = self.make_branch_and_tree('tree')
 
803
        rev_id1 = tree.commit('one')
 
804
        self.build_tree(['tree/a', 'tree/b'])
 
805
        tree.add(['a', 'b'], ['a-id', 'b-id'])
 
806
 
 
807
        dlg = commit.CommitDialog(tree)
 
808
        dlg._set_global_commit_message('Simple commit\n')
 
809
        dlg._do_commit()
 
810
 
 
811
        rev = tree.branch.repository.get_revision(dlg.committed_revision_id)
 
812
        self.failIf('file-info' in rev.properties)
 
813
 
 
814
    def test_commit_specific_files_with_messages(self):
 
815
        tree = self.make_branch_and_tree('tree')
 
816
        rev_id1 = tree.commit('one')
 
817
        self.build_tree(['tree/a', 'tree/b'])
 
818
        tree.add(['a', 'b'], ['a-id', 'b-id'])
 
819
 
 
820
        dlg = commit.CommitDialog(tree)
 
821
        dlg._treeview_files.set_cursor((1,))
 
822
        dlg._set_file_commit_message('Message for A\n')
 
823
        dlg._treeview_files.set_cursor((2,))
 
824
        dlg._set_file_commit_message('Message for B\n')
 
825
        dlg._toggle_commit(None, 2, dlg._files_store) # unset 'b'
 
826
        dlg._set_global_commit_message('Commit just "a"')
 
827
 
 
828
        dlg._do_commit()
 
829
 
 
830
        rev_id2 = dlg.committed_revision_id
 
831
        self.assertEqual(rev_id2, tree.last_revision())
 
832
        rev = tree.branch.repository.get_revision(rev_id2)
 
833
        self.assertEqual('Commit just "a"', rev.message)
 
834
        file_info = rev.properties['file-info']
 
835
        self.assertEqual('ld7:file_id4:a-id'
 
836
                           '7:message14:Message for A\n'
 
837
                           '4:path1:a'
 
838
                         'ee', file_info)
 
839
        self.assertEqual([{'path':'a', 'file_id':'a-id',
 
840
                           'message':'Message for A\n'},
 
841
                         ], bencode.bdecode(file_info))