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