Merge lp:~jelmer/brz/push-branch-tags into lp:brz

Proposed by Jelmer Vernooij on 2019-02-15
Status: Merged
Approved by: Jelmer Vernooij on 2019-02-15
Approved revision: 7294
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/push-branch-tags
Merge into: lp:brz
Diff against target: 231 lines (+134/-24)
5 files modified
breezy/bzr/remote.py (+7/-2)
breezy/git/remote.py (+35/-21)
breezy/git/tests/test_remote.py (+37/-0)
breezy/tests/per_controldir/test_push.py (+32/-1)
breezy/tests/test_remote.py (+23/-0)
To merge this branch: bzr merge lp:~jelmer/brz/push-branch-tags
Reviewer Review Type Date Requested Status
Martin Packman 2019-02-15 Approve on 2019-02-15
Review via email: mp+363234@code.launchpad.net

Commit message

Fix pushing of tags as part of nascent git branches.

Description of the change

Fix pushing of tags as part of nascent git branches.

To post a comment you must log in.
Martin Packman (gz) wrote :

Thanks! One nit inline.

review: Approve
lp:~jelmer/brz/push-branch-tags updated on 2019-02-15
7294. By Jelmer Vernooij on 2019-02-15

Fix flake8 warning.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/bzr/remote.py'
2--- breezy/bzr/remote.py 2019-01-01 23:40:59 +0000
3+++ breezy/bzr/remote.py 2019-02-15 14:45:32 +0000
4@@ -4226,12 +4226,17 @@
5 return self._set_config_option(value, name, section)
6
7 def _set_config_option(self, value, name, section):
8+ if isinstance(value, (bool, int)):
9+ value = str(value)
10+ elif isinstance(value, (text_type, str)):
11+ pass
12+ else:
13+ raise TypeError(value)
14 try:
15 path = self._branch._remote_path()
16 response = self._branch._client.call(b'Branch.set_config_option',
17 path, self._branch._lock_token, self._branch._repo_lock_token,
18- value.encode(
19- 'utf8'), name.encode('utf-8'),
20+ value.encode('utf-8'), name.encode('utf-8'),
21 (section or '').encode('utf-8'))
22 except errors.UnknownSmartMethod:
23 medium = self._branch._client._medium
24
25=== modified file 'breezy/git/remote.py'
26--- breezy/git/remote.py 2019-02-14 03:00:04 +0000
27+++ breezy/git/remote.py 2019-02-15 14:45:32 +0000
28@@ -48,7 +48,10 @@
29 UninitializableFormat,
30 )
31 from ..revisiontree import RevisionTree
32-from ..sixish import text_type
33+from ..sixish import (
34+ text_type,
35+ viewitems,
36+ )
37 from ..transport import (
38 Transport,
39 register_urlparse_netloc_protocol,
40@@ -566,27 +569,38 @@
41 if isinstance(source, GitBranch) and lossy:
42 raise errors.LossyPushToSameVCS(source.controldir, self)
43 source_store = get_object_store(source.repository)
44+ fetch_tags = source.get_config_stack().get('branch.fetch_tags')
45+ def get_changed_refs(refs):
46+ self._refs = remote_refs_dict_to_container(refs)
47+ ret = {}
48+ # TODO(jelmer): Unpeel if necessary
49+ push_result.new_original_revid = revision_id
50+ if lossy:
51+ new_sha = source_store._lookup_revision_sha1(revision_id)
52+ else:
53+ try:
54+ new_sha = repo.lookup_bzr_revision_id(revision_id)[0]
55+ except errors.NoSuchRevision:
56+ raise errors.NoRoundtrippingSupport(
57+ source, self.open_branch(name=name, nascent_ok=True))
58+ if not overwrite:
59+ if remote_divergence(ret.get(refname), new_sha,
60+ source_store):
61+ raise DivergedBranches(
62+ source, self.open_branch(name, nascent_ok=True))
63+ ret[refname] = new_sha
64+ if fetch_tags:
65+ for tagname, revid in viewitems(source.tags.get_tag_dict()):
66+ if lossy:
67+ new_sha = source_store._lookup_revision_sha1(revid)
68+ else:
69+ try:
70+ new_sha = repo.lookup_bzr_revision_id(revid)[0]
71+ except errors.NoSuchRevision:
72+ continue
73+ ret[tag_name_to_ref(tagname)] = new_sha
74+ return ret
75 with source_store.lock_read():
76- def get_changed_refs(refs):
77- self._refs = remote_refs_dict_to_container(refs)
78- ret = {}
79- # TODO(jelmer): Unpeel if necessary
80- push_result.new_original_revid = revision_id
81- if lossy:
82- new_sha = source_store._lookup_revision_sha1(revision_id)
83- else:
84- try:
85- new_sha = repo.lookup_bzr_revision_id(revision_id)[0]
86- except errors.NoSuchRevision:
87- raise errors.NoRoundtrippingSupport(
88- source, self.open_branch(name=name, nascent_ok=True))
89- if not overwrite:
90- if remote_divergence(ret.get(refname), new_sha,
91- source_store):
92- raise DivergedBranches(
93- source, self.open_branch(name, nascent_ok=True))
94- ret[refname] = new_sha
95- return ret
96 if lossy:
97 generate_pack_data = source_store.generate_lossy_pack_data
98 else:
99
100=== modified file 'breezy/git/tests/test_remote.py'
101--- breezy/git/tests/test_remote.py 2018-11-17 02:16:58 +0000
102+++ breezy/git/tests/test_remote.py 2019-02-15 14:45:32 +0000
103@@ -338,6 +338,43 @@
104 },
105 self.remote_real.get_refs())
106
107+ def test_push_branch_new_with_tags(self):
108+ remote = ControlDir.open(self.remote_url)
109+ builder = self.make_branch_builder('local', format=self._from_format)
110+ builder.start_series()
111+ rev_1 = builder.build_snapshot(None, [
112+ ('add', ('', None, 'directory', '')),
113+ ('add', ('filename', None, 'file', b'content'))])
114+ rev_2 = builder.build_snapshot(
115+ [rev_1], [('modify', ('filename', b'new-content\n'))])
116+ rev_3 = builder.build_snapshot(
117+ [rev_1], [('modify', ('filename', b'new-new-content\n'))])
118+ builder.finish_series()
119+ branch = builder.get_branch()
120+ try:
121+ branch.tags.set_tag('atag', rev_2)
122+ except TagsNotSupported:
123+ raise TestNotApplicable('source format does not support tags')
124+
125+ branch.get_config_stack().set('branch.fetch_tags', True)
126+ if self._from_format == 'git':
127+ result = remote.push_branch(branch, name='newbranch')
128+ else:
129+ result = remote.push_branch(
130+ branch, lossy=True, name='newbranch')
131+
132+ self.assertEqual(0, result.old_revno)
133+ if self._from_format == 'git':
134+ self.assertEqual(2, result.new_revno)
135+ else:
136+ self.assertIs(None, result.new_revno)
137+
138+ result.report(BytesIO())
139+
140+ self.assertEqual(
141+ {b'refs/heads/newbranch', b'refs/tags/atag'},
142+ set(self.remote_real.get_refs().keys()))
143+
144 def test_push(self):
145 c1 = self.remote_real.do_commit(
146 message=b'message',
147
148=== modified file 'breezy/tests/per_controldir/test_push.py'
149--- breezy/tests/per_controldir/test_push.py 2018-11-11 04:08:32 +0000
150+++ breezy/tests/per_controldir/test_push.py 2019-02-15 14:45:32 +0000
151@@ -16,7 +16,12 @@
152
153 """Tests for bzrdir implementations - push."""
154
155-from ...errors import LossyPushToSameVCS
156+from ...errors import (
157+ LossyPushToSameVCS,
158+ TagsNotSupported,
159+ )
160+from ...revision import NULL_REVISION
161+from .. import TestNotApplicable
162
163 from breezy.tests.per_controldir import (
164 TestCaseWithControlDir,
165@@ -41,6 +46,32 @@
166 self.assertEqual(dir.open_branch().base,
167 tree.branch.get_push_location())
168
169+ def test_push_new_branch_fetch_tags(self):
170+ builder = self.make_branch_builder('from')
171+ builder.start_series()
172+ rev_1 = builder.build_snapshot(None, [
173+ ('add', ('', None, 'directory', '')),
174+ ('add', ('filename', None, 'file', b'content'))])
175+ rev_2 = builder.build_snapshot(
176+ [rev_1], [('modify', ('filename', b'new-content\n'))])
177+ rev_3 = builder.build_snapshot(
178+ [rev_1], [('modify', ('filename', b'new-new-content\n'))])
179+ builder.finish_series()
180+ branch = builder.get_branch()
181+ try:
182+ branch.tags.set_tag('atag', rev_2)
183+ except TagsNotSupported:
184+ raise TestNotApplicable('source format does not support tags')
185+
186+ dir = self.make_repository('target').controldir
187+ branch.get_config().set_user_option('branch.fetch_tags', True)
188+ result = dir.push_branch(branch)
189+ self.assertEqual(
190+ set([rev_1, rev_2, rev_3]),
191+ set(result.source_branch.repository.all_revision_ids()))
192+ self.assertEqual(
193+ {'atag': rev_2}, result.source_branch.tags.get_tag_dict())
194+
195 def test_push_new_branch_lossy(self):
196 tree, rev_1 = self.create_simple_tree()
197 dir = self.make_repository('dir').controldir
198
199=== modified file 'breezy/tests/test_remote.py'
200--- breezy/tests/test_remote.py 2018-11-12 01:41:38 +0000
201+++ breezy/tests/test_remote.py 2019-02-15 14:45:32 +0000
202@@ -2042,6 +2042,29 @@
203 branch.unlock()
204 self.assertFinished(client)
205
206+ def test_set_option_with_bool(self):
207+ client = FakeClient()
208+ client.add_expected_call(
209+ b'Branch.get_stacked_on_url', (b'memory:///',),
210+ b'error', (b'NotStacked',),)
211+ client.add_expected_call(
212+ b'Branch.lock_write', (b'memory:///', b'', b''),
213+ b'success', (b'ok', b'branch token', b'repo token'))
214+ client.add_expected_call(
215+ b'Branch.set_config_option', (b'memory:///', b'branch token',
216+ b'repo token', b'True', b'foo', b''),
217+ b'success', ())
218+ client.add_expected_call(
219+ b'Branch.unlock', (b'memory:///', b'branch token', b'repo token'),
220+ b'success', (b'ok',))
221+ transport = MemoryTransport()
222+ branch = self.make_remote_branch(transport, client)
223+ branch.lock_write()
224+ config = branch._get_config()
225+ config.set_option(True, 'foo')
226+ branch.unlock()
227+ self.assertFinished(client)
228+
229 def test_backwards_compat_set_option(self):
230 self.setup_smart_server_with_call_log()
231 branch = self.make_branch('.')

Subscribers

People subscribed via source and target branches