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 (
25
from bzrlib.tests import HardlinkFeature
29
26
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
30
27
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
31
28
from bzrlib.workingtree import WorkingTree
96
93
self.build_tree(['source/file1'])
97
94
source.add('file1')
98
95
source.commit('added file')
99
out, err = self.run_bzr(['branch', 'source', 'target', '--hardlink'])
96
self.run_bzr(['branch', 'source', 'target', '--hardlink'])
100
97
source_stat = os.stat('source/file1')
101
98
target_stat = os.stat('target/file1')
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)")
99
self.assertEqual(source_stat, target_stat)
112
101
def test_branch_standalone(self):
113
102
shared_repo = self.make_repository('repo', shared=True)
149
138
class TestBranchStacked(ExternalBase):
150
139
"""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,))
152
164
def assertRevisionInRepository(self, repo_path, revid):
153
165
"""Check that a revision is in a repository, disregarding stacking."""
154
166
repo = bzrdir.BzrDir.open(repo_path).open_repository()
176
188
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
177
189
# with some work on it
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)
190
branch_tree.commit('moar work plz')
181
191
# branching our local branch gives us a new stacked branch pointing at
183
193
out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
184
194
self.assertEqual('', out)
185
self.assertEqual('Branched 2 revision(s).\n',
195
self.assertEqual('Branched 1 revision(s).\n',
187
197
# it should have preserved the branch format, and so it should be
188
198
# capable of supporting stacking, but not actually have a stacked_on
202
212
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
203
213
# with some work on it
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)
214
branch_revid = branch_tree.commit('moar work plz')
207
215
# you can chain branches on from there
208
216
out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
209
217
self.assertEqual('', out)
212
220
self.assertEqual(branch_tree.branch.base,
213
221
branch.Branch.open('branch2').get_stacked_on_url())
214
222
branch2_tree = WorkingTree.open('branch2')
215
branch2_revid = work_tree.commit('work on second stacked branch')
216
work_tree.branch.push(branch2_tree.branch)
223
branch2_revid = branch2_tree.commit('work on second stacked branch')
217
224
self.assertRevisionInRepository('branch2', branch2_revid)
218
225
self.assertRevisionsInBranchRepository(
219
226
[trunk_revid, branch_revid, branch2_revid],
232
239
self.assertEqual('Created new stacked branch referring to %s.\n' %
233
240
trunk_tree.branch.base, err)
234
241
self.assertRevisionNotInRepository('newbranch', original_revid)
235
new_branch = branch.Branch.open('newbranch')
236
self.assertEqual(trunk_tree.branch.base, new_branch.get_stacked_on_url())
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)
238
246
def test_branch_stacked_from_smart_server(self):
239
247
# We can branch stacking on a smart server
310
318
t.commit(message='commit %d' % count)
311
319
tree2 = t.branch.bzrdir.sprout('feature', stacked=True
312
320
).open_workingtree()
313
local_tree = t.branch.bzrdir.sprout('local-working').open_workingtree()
314
local_tree.commit('feature change')
315
local_tree.branch.push(tree2.branch)
321
tree2.commit('feature change')
316
322
self.reset_smart_call_log()
317
323
out, err = self.run_bzr(['branch', self.get_url('feature'),