~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/teststatus.py

[merge] fix \t in commit messages

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
 
24
24
from bzrlib.selftest import TestCaseInTempDir
 
25
from bzrlib.revisionspec import RevisionSpec
 
26
from bzrlib.merge import merge
 
27
from cStringIO import StringIO
 
28
from bzrlib.status import show_status
 
29
from bzrlib.branch import Branch
 
30
from os import mkdir
 
31
from bzrlib.clone import copy_branch
25
32
 
26
33
class BranchStatus(TestCaseInTempDir):
27
34
    
28
35
    def test_branch_status(self): 
29
 
        """Basic 'bzr mkdir' operation"""
 
36
        """Test basic branch status"""
30
37
        from cStringIO import StringIO
31
38
        from bzrlib.status import show_status
32
39
        from bzrlib.branch import Branch
33
40
        
34
 
        b = Branch('.', init=True)
 
41
        b = Branch.initialize('.')
35
42
 
36
43
        # status with nothing
37
44
        tof = StringIO()
40
47
 
41
48
        tof = StringIO()
42
49
        self.build_tree(['hello.c', 'bye.c'])
43
 
        b.add_pending_merge('pending@pending-0-0')
 
50
        b.working_tree().add_pending_merge('pending@pending-0-0')
44
51
        show_status(b, to_file=tof)
45
52
        tof.seek(0)
46
53
        self.assertEquals(tof.readlines(),
51
58
                           '  pending@pending-0-0\n'
52
59
                           ])
53
60
 
 
61
    def test_branch_status_revisions(self):
 
62
        """Tests branch status with revisions"""
 
63
        
 
64
        b = Branch.initialize('.')
 
65
 
 
66
        tof = StringIO()
 
67
        self.build_tree(['hello.c', 'bye.c'])
 
68
        b.add('hello.c')
 
69
        b.add('bye.c')
 
70
        b.working_tree().commit('Test message')
 
71
 
 
72
        tof = StringIO()
 
73
        revs =[]
 
74
        revs.append(RevisionSpec(0))
 
75
        
 
76
        show_status(b, to_file=tof, revision=revs)
 
77
        
 
78
        tof.seek(0)
 
79
        self.assertEquals(tof.readlines(),
 
80
                          ['added:\n',
 
81
                           '  bye.c\n',
 
82
                           '  hello.c\n'])
 
83
 
 
84
        self.build_tree(['more.c'])
 
85
        b.add('more.c')
 
86
        b.working_tree().commit('Another test message')
 
87
        
 
88
        tof = StringIO()
 
89
        revs.append(RevisionSpec(1))
 
90
        
 
91
        show_status(b, to_file=tof, revision=revs)
 
92
        
 
93
        tof.seek(0)
 
94
        self.assertEquals(tof.readlines(),
 
95
                          ['added:\n',
 
96
                           '  bye.c\n',
 
97
                           '  hello.c\n'])
 
98
 
 
99
    def status_string(self, branch):
 
100
        tof = StringIO()
 
101
        show_status(branch, to_file=tof)
 
102
        tof.seek(0)
 
103
        return tof.getvalue()
 
104
 
 
105
    def test_pending(self):
 
106
        """Pending merges display works"""
 
107
        mkdir("./branch")
 
108
        b = Branch.initialize('./branch')
 
109
        b.working_tree().commit("Empty commit 1")
 
110
        b_2 = copy_branch(b, './copy')
 
111
        b.working_tree().commit("Empty commit 2")
 
112
        merge(["./branch", -1], [None, None], this_dir = './copy')
 
113
        message = self.status_string(b_2)
 
114
        self.assert_(message.startswith("pending merges:\n"))
 
115
        self.assert_(message.endswith("Empty commit 2\n")) 
 
116
        b_2.working_tree().commit("merged")
 
117
        # must be long to make sure we see elipsis at the end
 
118
        b.working_tree().commit("Empty commit 3 blah blah blah blah blah blah blah blah blah"
 
119
                 " blah blah blah blah blah blah bleh")
 
120
        merge(["./branch", -1], [None, None], this_dir = './copy')
 
121
        message = self.status_string(b_2)
 
122
        self.assert_(message.startswith("pending merges:\n"))
 
123
        self.assert_("Empty commit 3" in message)
 
124
        self.assert_(message.endswith("...\n")) 
 
125
 
 
126
    def test_branch_status_specific_files(self): 
 
127
        """Tests branch status with given specific files"""
 
128
        from cStringIO import StringIO
 
129
        from bzrlib.status import show_status
 
130
        from bzrlib.branch import Branch
 
131
        
 
132
        b = Branch.initialize('.')
 
133
 
 
134
        self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
 
135
        b.add('directory')
 
136
        b.add('test.c')
 
137
        b.working_tree().commit('testing')
 
138
        
 
139
        tof = StringIO()
 
140
        show_status(b, to_file=tof)
 
141
        tof.seek(0)
 
142
        self.assertEquals(tof.readlines(),
 
143
                          ['unknown:\n',
 
144
                           '  bye.c\n',
 
145
                           '  dir2\n',
 
146
                           '  directory/hello.c\n'
 
147
                           ])
 
148
 
 
149
        tof = StringIO()
 
150
        show_status(b, specific_files=['bye.c','test.c','absent.c'], to_file=tof)
 
151
        tof.seek(0)
 
152
        self.assertEquals(tof.readlines(),
 
153
                          ['unknown:\n',
 
154
                           '  bye.c\n'
 
155
                           ])
 
156
        
 
157
        tof = StringIO()
 
158
        show_status(b, specific_files=['directory'], to_file=tof)
 
159
        tof.seek(0)
 
160
        self.assertEquals(tof.readlines(),
 
161
                          ['unknown:\n',
 
162
                           '  directory/hello.c\n'
 
163
                           ])
 
164
        tof = StringIO()
 
165
        show_status(b, specific_files=['dir2'], to_file=tof)
 
166
        tof.seek(0)
 
167
        self.assertEquals(tof.readlines(),
 
168
                          ['unknown:\n',
 
169
                           '  dir2\n'
 
170
                           ])