15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
21
status as _mod_status,
22
23
from ..revisionspec import RevisionSpec
23
24
from ..sixish import (
26
27
from ..status import show_pending_merges, show_tree_status
27
28
from . import TestCaseWithTransport
35
36
tree.commit('empty commit')
36
37
tree2 = self.make_branch_and_tree('b')
37
38
# set a left most parent that is not a present commit
38
tree2.add_parent_tree_id(b'some-ghost', allow_leftmost_as_ghost=True)
39
tree2.add_parent_tree_id('some-ghost', allow_leftmost_as_ghost=True)
40
41
tree2.merge_from_branch(tree.branch)
42
with tree2.lock_read():
43
45
show_pending_merges(tree2, output)
44
48
self.assertContainsRe(output.getvalue(), 'empty commit')
46
50
def make_multiple_pending_tree(self):
73
77
def test_multiple_pending_verbose(self):
74
78
tree = self.make_multiple_pending_tree()
77
81
self.addCleanup(tree.unlock)
78
82
show_pending_merges(tree, output, verbose=True)
88
92
"""Test when a pending merge is itself a ghost"""
89
93
tree = self.make_branch_and_tree('a')
90
94
tree.commit('first')
91
tree.add_parent_tree_id(b'a-ghost-revision')
95
tree.add_parent_tree_id('a-ghost-revision')
93
97
self.addCleanup(tree.unlock)
95
99
show_pending_merges(tree, output)
96
100
self.assertEqualDiff(
97
101
'pending merge tips: (use -v to see all merge revisions)\n'
105
109
tree.commit('empty commit')
106
110
tree2 = tree.controldir.clone('b').open_workingtree()
107
111
tree2.commit('a non-ghost', timestamp=1196796819, timezone=0)
108
tree2.add_parent_tree_id(b'a-ghost-revision')
112
tree2.add_parent_tree_id('a-ghost-revision')
109
113
tree2.commit('commit with ghost', timestamp=1196796819, timezone=0)
110
114
tree2.commit('another non-ghost', timestamp=1196796819, timezone=0)
111
115
tree.merge_from_branch(tree2.branch)
113
117
self.addCleanup(tree.unlock)
115
119
show_pending_merges(tree, output, verbose=True)
116
self.assertEqualDiff(
118
' Joe Foo 2007-12-04 another non-ghost\n'
119
' Joe Foo 2007-12-04 [merge] commit with ghost\n'
120
' (ghost) a-ghost-revision\n'
121
' Joe Foo 2007-12-04 a non-ghost\n',
120
self.assertEqualDiff('pending merges:\n'
121
' Joe Foo 2007-12-04 another non-ghost\n'
122
' Joe Foo 2007-12-04 [merge] commit with ghost\n'
123
' (ghost) a-ghost-revision\n'
124
' Joe Foo 2007-12-04 a non-ghost\n',
124
127
def tests_revision_to_revision(self):
125
128
"""doing a status between two revision trees should work."""
126
129
tree = self.make_branch_and_tree('.')
127
130
r1_id = tree.commit('one', allow_pointless=True)
128
131
r2_id = tree.commit('two', allow_pointless=True)
130
show_tree_status(tree, to_file=output, revision=[
131
RevisionSpec.from_string("revid:%s" % r1_id.decode('utf-8')),
132
RevisionSpec.from_string("revid:%s" % r2_id.decode('utf-8'))])
132
r2_tree = tree.branch.repository.revision_tree(r2_id)
134
show_tree_status(tree, to_file=output,
135
revision=[RevisionSpec.from_string("revid:%s" % r1_id),
136
RevisionSpec.from_string("revid:%s" % r2_id)])
133
137
# return does not matter as long as it did not raise.
139
143
"""Check that creating a StatusHooks instance has the right defaults.
141
145
hooks = _mod_status.StatusHooks()
142
self.assertTrue("post_status" in hooks,
143
"post_status not in %s" % hooks)
146
self.assertTrue("post_status" in hooks, "post_status not in %s" % hooks)
144
147
self.assertTrue("pre_status" in hooks, "pre_status not in %s" % hooks)
146
149
def test_installed_hooks_are_StatusHooks(self):
159
162
tree = self.make_branch_and_tree('.')
160
163
r1_id = tree.commit('one', allow_pointless=True)
161
164
r2_id = tree.commit('two', allow_pointless=True)
163
show_tree_status(tree, to_file=output, revision=[
164
RevisionSpec.from_string("revid:%s" % r1_id.decode('utf-8')),
165
RevisionSpec.from_string("revid:%s" % r2_id.decode('utf-8'))])
165
r2_tree = tree.branch.repository.revision_tree(r2_id)
167
show_tree_status(tree, to_file=output,
168
revision=[RevisionSpec.from_string("revid:%s" % r1_id),
169
RevisionSpec.from_string("revid:%s" % r2_id)])
166
170
self.assertLength(1, calls)
167
171
params = calls[0]
168
172
self.assertIsInstance(params, _mod_status.StatusHookParams)
169
173
attrs = ['old_tree', 'new_tree', 'to_file', 'versioned',
170
'show_ids', 'short', 'verbose', 'specific_files']
174
'show_ids', 'short', 'verbose', 'specific_files']
172
176
self.assertTrue(hasattr(params, a),
173
'Attribute "%s" not found in StatusHookParam' % a)
177
'Attribute "%s" not found in StatusHookParam' % a)
175
179
def test_pre_status_hook(self):
176
180
"""Ensure that pre_status hook is invoked with the right args.
181
185
tree = self.make_branch_and_tree('.')
182
186
r1_id = tree.commit('one', allow_pointless=True)
183
187
r2_id = tree.commit('two', allow_pointless=True)
186
tree, to_file=output,
188
RevisionSpec.from_string("revid:%s" % r1_id.decode('utf-8')),
189
RevisionSpec.from_string("revid:%s" % r2_id.decode('utf-8'))])
188
r2_tree = tree.branch.repository.revision_tree(r2_id)
190
show_tree_status(tree, to_file=output,
191
revision=[RevisionSpec.from_string("revid:%s" % r1_id),
192
RevisionSpec.from_string("revid:%s" % r2_id)])
190
193
self.assertLength(1, calls)
191
194
params = calls[0]
192
195
self.assertIsInstance(params, _mod_status.StatusHookParams)
193
196
attrs = ['old_tree', 'new_tree', 'to_file', 'versioned',
194
'show_ids', 'short', 'verbose', 'specific_files']
197
'show_ids', 'short', 'verbose', 'specific_files']
196
199
self.assertTrue(hasattr(params, a),
197
'Attribute "%s" not found in StatusHookParam' % a)
200
'Attribute "%s" not found in StatusHookParam' % a)