22
22
from bzrlib import (branch, bzrdir, errors, repository)
23
23
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
24
24
from bzrlib.tests.blackbox import ExternalBase
25
from bzrlib.tests import HardlinkFeature
25
from bzrlib.tests import (
26
29
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
27
30
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
28
31
from bzrlib.workingtree import WorkingTree
93
96
self.build_tree(['source/file1'])
94
97
source.add('file1')
95
98
source.commit('added file')
96
self.run_bzr(['branch', 'source', 'target', '--hardlink'])
99
out, err = self.run_bzr(['branch', 'source', 'target', '--hardlink'])
97
100
source_stat = os.stat('source/file1')
98
101
target_stat = os.stat('target/file1')
99
self.assertEqual(source_stat, target_stat)
102
same_file = (source_stat == target_stat)
106
# https://bugs.edge.launchpad.net/bzr/+bug/408193
107
self.assertContainsRe(err, "hardlinking working copy files is "
108
"not currently supported")
109
raise KnownFailure("--hardlink doesn't work in formats "
110
"that support content filtering (#408193)")
101
112
def test_branch_standalone(self):
102
113
shared_repo = self.make_repository('repo', shared=True)
138
149
class TestBranchStacked(ExternalBase):
139
150
"""Tests for branch --stacked"""
141
def check_shallow_branch(self, branch_revid, stacked_on):
142
"""Assert that the branch 'newbranch' has been published correctly.
144
:param stacked_on: url of a branch this one is stacked upon.
145
:param branch_revid: a revision id that should be the only
146
revision present in the stacked branch, and it should not be in
147
the reference branch.
149
new_branch = branch.Branch.open('newbranch')
150
# The branch refers to the mainline
151
self.assertEqual(stacked_on, new_branch.get_stacked_on_url())
152
# and the branch's work was pushed
153
self.assertTrue(new_branch.repository.has_revision(branch_revid))
154
# The newly committed revision shoud be present in the stacked branch,
155
# but not in the stacked-on branch. Because stacking is set up by the
156
# branch object, if we open the stacked branch's repository directly,
157
# bypassing the branch, we see only what's in the stacked repository.
158
stacked_repo = bzrdir.BzrDir.open('newbranch').open_repository()
159
stacked_repo_revisions = set(stacked_repo.all_revision_ids())
160
if len(stacked_repo_revisions) != 1:
161
self.fail("wrong revisions in stacked repository: %r"
162
% (stacked_repo_revisions,))
164
152
def assertRevisionInRepository(self, repo_path, revid):
165
153
"""Check that a revision is in a repository, disregarding stacking."""
166
154
repo = bzrdir.BzrDir.open(repo_path).open_repository()
188
176
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
189
177
# with some work on it
190
branch_tree.commit('moar work plz')
178
work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
179
work_tree.commit('moar work plz')
180
work_tree.branch.push(branch_tree.branch)
191
181
# branching our local branch gives us a new stacked branch pointing at
193
183
out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
194
184
self.assertEqual('', out)
195
self.assertEqual('Branched 1 revision(s).\n',
185
self.assertEqual('Branched 2 revision(s).\n',
197
187
# it should have preserved the branch format, and so it should be
198
188
# capable of supporting stacking, but not actually have a stacked_on
212
202
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
213
203
# with some work on it
214
branch_revid = branch_tree.commit('moar work plz')
204
work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
205
branch_revid = work_tree.commit('moar work plz')
206
work_tree.branch.push(branch_tree.branch)
215
207
# you can chain branches on from there
216
208
out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
217
209
self.assertEqual('', out)
220
212
self.assertEqual(branch_tree.branch.base,
221
213
branch.Branch.open('branch2').get_stacked_on_url())
222
214
branch2_tree = WorkingTree.open('branch2')
223
branch2_revid = branch2_tree.commit('work on second stacked branch')
215
branch2_revid = work_tree.commit('work on second stacked branch')
216
work_tree.branch.push(branch2_tree.branch)
224
217
self.assertRevisionInRepository('branch2', branch2_revid)
225
218
self.assertRevisionsInBranchRepository(
226
219
[trunk_revid, branch_revid, branch2_revid],
239
232
self.assertEqual('Created new stacked branch referring to %s.\n' %
240
233
trunk_tree.branch.base, err)
241
234
self.assertRevisionNotInRepository('newbranch', original_revid)
242
new_tree = WorkingTree.open('newbranch')
243
new_revid = new_tree.commit('new work')
244
self.check_shallow_branch(new_revid, trunk_tree.branch.base)
235
new_branch = branch.Branch.open('newbranch')
236
self.assertEqual(trunk_tree.branch.base, new_branch.get_stacked_on_url())
246
238
def test_branch_stacked_from_smart_server(self):
247
239
# We can branch stacking on a smart server
318
310
t.commit(message='commit %d' % count)
319
311
tree2 = t.branch.bzrdir.sprout('feature', stacked=True
320
312
).open_workingtree()
321
tree2.commit('feature change')
313
local_tree = t.branch.bzrdir.sprout('local-working').open_workingtree()
314
local_tree.commit('feature change')
315
local_tree.branch.push(tree2.branch)
322
316
self.reset_smart_call_log()
323
317
out, err = self.run_bzr(['branch', self.get_url('feature'),