~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_status.py

  • Committer: John Arbash Meinel
  • Date: 2008-05-19 21:35:52 UTC
  • mto: This revision was merged to the branch mainline in revision 3441.
  • Revision ID: john@arbash-meinel.com-20080519213552-8jc1yc4w8rqhgzri
switch find_unmerged to use the new function

The api is very compatible, so we don't really need to expose a new function.
So make it hidden, and leave find_unmerged to take out the write lock and call it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2005 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
from StringIO import StringIO
19
19
 
20
 
from bzrlib import (
21
 
    config,
22
 
    status as _mod_status,
23
 
    )
 
20
from bzrlib import config
24
21
from bzrlib.revisionspec import RevisionSpec
25
22
from bzrlib.status import show_pending_merges, show_tree_status
26
23
from bzrlib.tests import TestCaseWithTransport
45
42
            tree2.unlock()
46
43
        self.assertContainsRe(output.getvalue(), 'empty commit')
47
44
 
48
 
    def make_multiple_pending_tree(self):
49
 
        config.GlobalStack().set('email', 'Joe Foo <joe@foo.com>')
 
45
    def test_multiple_pending(self):
 
46
        config.GlobalConfig().set_user_option('email', 'Joe Foo <joe@foo.com>')
50
47
        tree = self.make_branch_and_tree('a')
51
48
        tree.commit('commit 1', timestamp=1196796819, timezone=0)
52
49
        tree2 = tree.bzrdir.clone('b').open_workingtree()
56
53
        tree2.commit('commit 3b', timestamp=1196796819, timezone=0)
57
54
        tree3.commit('commit 3c', timestamp=1196796819, timezone=0)
58
55
        tree.merge_from_branch(tree2.branch)
59
 
        tree.merge_from_branch(tree3.branch, force=True)
60
 
        return tree
61
 
 
62
 
    def test_multiple_pending(self):
63
 
        tree = self.make_multiple_pending_tree()
 
56
        tree.merge_from_branch(tree3.branch)
64
57
        output = StringIO()
65
58
        tree.lock_read()
66
59
        self.addCleanup(tree.unlock)
67
60
        show_pending_merges(tree, output)
68
 
        # 2b doesn't appear because it's an ancestor of 3b
69
 
        self.assertEqualDiff(
70
 
            'pending merge tips: (use -v to see all merge revisions)\n'
71
 
            '  Joe Foo 2007-12-04 commit 3b\n'
72
 
            '  Joe Foo 2007-12-04 commit 3c\n',
73
 
            output.getvalue())
74
 
 
75
 
    def test_multiple_pending_verbose(self):
76
 
        tree = self.make_multiple_pending_tree()
77
 
        output = StringIO()
78
 
        tree.lock_read()
79
 
        self.addCleanup(tree.unlock)
80
 
        show_pending_merges(tree, output, verbose=True)
81
61
        # Even though 2b is in the ancestry of 3c, it should only be displayed
82
62
        # under the first merge parent.
83
63
        self.assertEqualDiff('pending merges:\n'
95
75
        self.addCleanup(tree.unlock)
96
76
        output = StringIO()
97
77
        show_pending_merges(tree, output)
98
 
        self.assertEqualDiff(
99
 
            'pending merge tips: (use -v to see all merge revisions)\n'
100
 
            '  (ghost) a-ghost-revision\n',
101
 
            output.getvalue())
 
78
        self.assertEqualDiff('pending merges:\n'
 
79
                             '  (ghost) a-ghost-revision\n',
 
80
                             output.getvalue())
102
81
 
103
82
    def test_pending_with_ghosts(self):
104
83
        """Test when a pending merge's ancestry includes ghosts."""
105
 
        config.GlobalStack().set('email', 'Joe Foo <joe@foo.com>')
 
84
        config.GlobalConfig().set_user_option('email', 'Joe Foo <joe@foo.com>')
106
85
        tree = self.make_branch_and_tree('a')
107
86
        tree.commit('empty commit')
108
87
        tree2 = tree.bzrdir.clone('b').open_workingtree()
114
93
        tree.lock_read()
115
94
        self.addCleanup(tree.unlock)
116
95
        output = StringIO()
117
 
        show_pending_merges(tree, output, verbose=True)
 
96
        show_pending_merges(tree, output)
118
97
        self.assertEqualDiff('pending merges:\n'
119
98
                             '  Joe Foo 2007-12-04 another non-ghost\n'
120
 
                             '    Joe Foo 2007-12-04 [merge] commit with ghost\n'
 
99
                             '    Joe Foo 2007-12-04 commit with ghost\n'
121
100
                             '    (ghost) a-ghost-revision\n'
122
101
                             '    Joe Foo 2007-12-04 a non-ghost\n',
123
102
                             output.getvalue())
134
113
                               RevisionSpec.from_string("revid:%s" % r2_id)])
135
114
        # return does not matter as long as it did not raise.
136
115
 
137
 
 
138
 
class TestHooks(TestCaseWithTransport):
139
 
 
140
 
    def test_constructor(self):
141
 
        """Check that creating a StatusHooks instance has the right defaults.
142
 
        """
143
 
        hooks = _mod_status.StatusHooks()
144
 
        self.assertTrue("post_status" in hooks, "post_status not in %s" % hooks)
145
 
        self.assertTrue("pre_status" in hooks, "pre_status not in %s" % hooks)
146
 
 
147
 
    def test_installed_hooks_are_StatusHooks(self):
148
 
        """The installed hooks object should be a StatusHooks.
149
 
        """
150
 
        # the installed hooks are saved in self._preserved_hooks.
151
 
        self.assertIsInstance(self._preserved_hooks[_mod_status][1],
152
 
            _mod_status.StatusHooks)
153
 
 
154
 
    def test_post_status_hook(self):
155
 
        """Ensure that post_status hook is invoked with the right args.
156
 
        """
157
 
        calls = []
158
 
        _mod_status.hooks.install_named_hook('post_status', calls.append, None)
159
 
        self.assertLength(0, calls)
160
 
        tree = self.make_branch_and_tree('.')
161
 
        r1_id = tree.commit('one', allow_pointless=True)
162
 
        r2_id = tree.commit('two', allow_pointless=True)
163
 
        r2_tree = tree.branch.repository.revision_tree(r2_id)
164
 
        output = StringIO()
165
 
        show_tree_status(tree, to_file=output,
166
 
            revision=[RevisionSpec.from_string("revid:%s" % r1_id),
167
 
                RevisionSpec.from_string("revid:%s" % r2_id)])
168
 
        self.assertLength(1, calls)
169
 
        params = calls[0]
170
 
        self.assertIsInstance(params, _mod_status.StatusHookParams)
171
 
        attrs = ['old_tree', 'new_tree', 'to_file', 'versioned',
172
 
            'show_ids', 'short', 'verbose', 'specific_files']
173
 
        for a in attrs:
174
 
            self.assertTrue(hasattr(params, a),
175
 
                'Attribute "%s" not found in StatusHookParam' % a)
176
 
 
177
 
    def test_pre_status_hook(self):
178
 
        """Ensure that pre_status hook is invoked with the right args.
179
 
        """
180
 
        calls = []
181
 
        _mod_status.hooks.install_named_hook('pre_status', calls.append, None)
182
 
        self.assertLength(0, calls)
183
 
        tree = self.make_branch_and_tree('.')
184
 
        r1_id = tree.commit('one', allow_pointless=True)
185
 
        r2_id = tree.commit('two', allow_pointless=True)
186
 
        r2_tree = tree.branch.repository.revision_tree(r2_id)
187
 
        output = StringIO()
188
 
        show_tree_status(tree, to_file=output,
189
 
            revision=[RevisionSpec.from_string("revid:%s" % r1_id),
190
 
                RevisionSpec.from_string("revid:%s" % r2_id)])
191
 
        self.assertLength(1, calls)
192
 
        params = calls[0]
193
 
        self.assertIsInstance(params, _mod_status.StatusHookParams)
194
 
        attrs = ['old_tree', 'new_tree', 'to_file', 'versioned',
195
 
            'show_ids', 'short', 'verbose', 'specific_files']
196
 
        for a in attrs:
197
 
            self.assertTrue(hasattr(params, a),
198
 
                'Attribute "%s" not found in StatusHookParam' % a)
199
 
 
 
116
    def test_pending_specific_files(self):
 
117
        """With a specific file list, pending merges are not shown."""
 
118
        tree = self.make_branch_and_tree('tree')
 
119
        self.build_tree_contents([('tree/a', 'content of a\n')])
 
120
        tree.add('a')
 
121
        r1_id = tree.commit('one')
 
122
        alt = tree.bzrdir.sprout('alt').open_workingtree()
 
123
        self.build_tree_contents([('alt/a', 'content of a\nfrom alt\n')])
 
124
        alt_id = alt.commit('alt')
 
125
        tree.merge_from_branch(alt.branch)
 
126
        output = StringIO()
 
127
        show_tree_status(tree, to_file=output)
 
128
        self.assertContainsRe(output.getvalue(), 'pending merges:')
 
129
        output = StringIO()
 
130
        show_tree_status(tree, to_file=output, specific_files=['a'])
 
131
        self.assertNotContainsRe(output.getvalue(), 'pending merges:')