Rev 3243: Branching a shallow branch gets a shallow branch. in http://people.ubuntu.com/~robertc/baz2.0/shallow-branch
Robert Collins
robertc at robertcollins.net
Wed Feb 27 12:18:26 GMT 2008
At http://people.ubuntu.com/~robertc/baz2.0/shallow-branch
------------------------------------------------------------
revno: 3243
revision-id:robertc at robertcollins.net-20080227121821-2s5wrjlwsd7vy4ii
parent: robertc at robertcollins.net-20080227114404-wuh70yzho5bh8ckt
committer: Robert Collins <robertc at robertcollins.net>
branch nick: branch.shallow
timestamp: Wed 2008-02-27 23:18:21 +1100
message:
Branching a shallow branch gets a shallow branch.
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2008-02-27 11:42:40 +0000
+++ b/bzrlib/branch.py 2008-02-27 12:18:21 +0000
@@ -731,6 +731,13 @@
else:
if parent:
destination.set_parent(parent)
+ try:
+ shallow_url = self.get_stacked_on()
+ except (errors.NotStacked, errors.UnstackableBranchFormat,
+ errors.UnstackableRepositoryFormat):
+ pass
+ else:
+ destination.set_stacked_on(shallow_url)
self.tags.merge_to(destination.tags)
@needs_read_lock
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2008-02-27 11:44:04 +0000
+++ b/bzrlib/builtins.py 2008-02-27 12:18:21 +0000
@@ -964,7 +964,12 @@
if name:
branch.control_files.put_utf8('branch-name', name)
_merge_tags_if_possible(br_from, branch)
- note('Branched %d revision(s).' % branch.revno())
+ try:
+ note('Created new shallow branch referring to %s.' %
+ branch.get_stacked_on())
+ except (errors.NotStacked, errors.UnstackableBranchFormat,
+ errors.UnstackableRepositoryFormat):
+ note('Branched %d revision(s).' % branch.revno())
finally:
br_from.unlock()
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2008-02-27 11:42:40 +0000
+++ b/bzrlib/bzrdir.py 2008-02-27 12:18:21 +0000
@@ -914,9 +914,15 @@
target_transport.ensure_base()
cloning_format = self.cloning_metadir()
result = cloning_format.initialize_on_transport(target_transport)
+ shallow_branch_url = False
try:
source_branch = self.open_branch()
source_repository = source_branch.repository
+ try:
+ shallow_branch_url = source_branch.get_stacked_on()
+ except (errors.NotStacked, errors.UnstackableBranchFormat,
+ errors.UnstackableRepositoryFormat):
+ shallow_branch_url = None
except errors.NotBranchError:
source_branch = None
try:
@@ -935,6 +941,15 @@
elif source_repository is None and result_repo is None:
# no repo available, make a new one
result.create_repository()
+ elif result_repo is None and shallow_branch_url:
+ result_repo = source_repository._format.initialize(result)
+ stacked_dir = BzrDirPreSplitOut.open(shallow_branch_url)
+ try:
+ stacked_repo = stacked_dir.open_branch().repository
+ except errors.NotBranchError:
+ stacked_repo = stacked_dir.open_repository()
+ result_repo.add_fallback_repository(stacked_repo)
+ result_repo.fetch(source_repository, revision_id=revision_id)
elif source_repository is not None and result_repo is None:
# have source, and want to make a new target repo
result_repo = source_repository.sprout(result,
=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py 2007-12-20 20:44:45 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py 2008-02-27 12:18:21 +0000
@@ -96,6 +96,37 @@
target_stat = os.stat('target/file1')
self.assertEqual(source_stat, target_stat)
+ def assertShallow(self, branch_revid, stacked_on):
+ """Assert that the branch 'published' has been published correctly."""
+ new_branch = branch.Branch.open('newbranch')
+ # The branch refers to the mainline
+ self.assertEqual(stacked_on, new_branch.get_stacked_on())
+ # and the branch's work was pushed
+ self.assertTrue(new_branch.repository.has_revision(branch_revid))
+ # but the mainlines was not included
+ repo = new_branch.bzrdir.open_repository()
+ self.assertEqual(1, len(repo.all_revision_ids()))
+
+ def test_branch_shallow_branch_also_shallow_same_reference(self):
+ # We have a mainline
+ trunk_tree = self.make_branch_and_tree('target',
+ format='development')
+ trunk_tree.commit('mainline')
+ # and a branch from it which is shallow
+ branch_tree = self.make_branch_and_tree('branch',
+ format='development')
+ branch_tree.branch.set_stacked_on(trunk_tree.branch.base)
+ # with some work on it
+ branch_tree.commit('moar work plz')
+ # branching our local branch gives us a new stacked branch pointing at
+ # mainline.
+ out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
+ self.assertEqual('', out)
+ self.assertEqual('Created new shallow branch referring to %s.\n' %
+ trunk_tree.branch.base, err)
+ self.assertShallow(branch_tree.last_revision(),
+ trunk_tree.branch.base)
+
class TestRemoteBranch(TestCaseWithSFTPServer):
More information about the bazaar-commits
mailing list