1580
conflicts = db.merge_upstream(tarball_filename, Version("0.2"),
1581
Version("0.1"), upstream_branch=upstream_tree.branch,
1579
conflicts = db.merge_upstream(tarball_filename, "0.2", "0.1",
1580
upstream_branch=upstream_tree.branch,
1582
1581
upstream_revision=upstream_rev)
1583
1582
# ./debian conflicts.
1584
1583
self.assertEqual(3, conflicts)
1585
def test_merge_upstream_with_unrelated_branch(self):
1586
"""Check that we can merge-upstream with an unrelated branch.
1588
We should do this by changing all the file ids to be the same
1589
as in the upstream branch, which gives a discontinuity, but
1590
makes for a better experience in the future.
1592
self.requireFeature(PristineTarFeature)
1593
version1 = Version("1.0-1")
1594
version2 = Version("1.1-1")
1595
builder = SourcePackageBuilder("package", version1)
1596
builder.add_default_control()
1597
builder.add_upstream_file("a", "Original a")
1599
tree = self.make_branch_and_tree(".")
1600
packaging_upstream_tree = self.make_branch_and_tree(
1601
"packaging-upstream")
1602
db = DistributionBranch(tree.branch, packaging_upstream_tree.branch,
1603
tree=tree, upstream_tree=packaging_upstream_tree)
1604
dbs = DistributionBranchSet()
1606
db.import_package(builder.dsc_name())
1607
builder.new_version(version2)
1608
builder.add_upstream_file("a", "New a")
1610
upstream_tree = self.make_branch_and_tree("upstream")
1611
self.build_tree(['upstream/a'])
1612
upstream_tree.add(['a'], ['a-id'])
1613
upstream_tree.commit("one")
1614
upstream_rev = upstream_tree.branch.last_revision()
1615
db = DistributionBranch(tree.branch, None, tree=tree)
1616
dbs = DistributionBranchSet()
1619
self.addCleanup(tree.unlock)
1620
db.merge_upstream(builder.tar_name(), str(version2),
1621
version1.upstream_version,
1622
upstream_branch=upstream_tree.branch,
1623
upstream_revision=upstream_rev)
1624
rh1 = tree.branch.revision_history()
1625
self.assertEqual(2, len(rh1))
1626
packaging_upstream_tip = tree.get_parent_ids()[1]
1627
# We added the extra parent for the upstream branch
1628
revtree = tree.branch.repository.revision_tree(packaging_upstream_tip)
1629
self.assertEqual(2, len(revtree.get_parent_ids()))
1630
self.assertEqual(upstream_rev, revtree.get_parent_ids()[1])
1631
# And the file has the new id in our tree
1632
self.assertEqual("a-id", tree.path2id("a"))
1634
def test_merge_upstream_with_dash_in_version_number(self):
1635
tree = self.make_branch_and_tree('work')
1636
self.build_tree(['work/a'])
1638
orig_upstream_rev = tree.commit("one")
1639
tree.branch.tags.set_tag("upstream-0.1", orig_upstream_rev)
1640
self.build_tree(['work/debian/'])
1641
cl = self.make_changelog(version="0.1-1")
1642
self.write_changelog(cl, 'work/debian/changelog')
1643
tree.add(['debian/', 'debian/changelog'])
1644
orig_debian_rev = tree.commit("two")
1645
db = DistributionBranch(tree.branch, None, tree=tree)
1646
dbs = DistributionBranchSet()
1648
tarball_filename = "package-0.2.tar.gz"
1649
tf = tarfile.open(tarball_filename, 'w:gz')
1659
conflicts = db.merge_upstream(tarball_filename, "0.2-1", "0.1")
1660
# Check that we tagged wiht the dash version
1661
self.assertTrue(tree.branch.tags.has_tag('upstream-0.2-1'))
1663
def test_merge_upstream_rename_and_replace(self):
1664
"""Test renaming a file upstream and replacing it.
1666
We want to take the rename in to our tree, but have to be
1667
careful not to assign the file id to the new file at the same
1668
path as well, as that will lead to problems.
1670
self.requireFeature(PristineTarFeature)
1671
version1 = Version("1.0-1")
1672
version2 = Version("1.1-1")
1673
upstream_tree = self.make_branch_and_tree("upstream")
1674
upstream_tree.lock_write()
1675
self.addCleanup(upstream_tree.unlock)
1676
self.build_tree(['upstream/a'])
1677
upstream_tree.add(['a'], ['a-id'])
1678
upstream_rev1 = upstream_tree.commit("one")
1679
tree = upstream_tree.bzrdir.sprout('packaging').open_workingtree()
1680
db = DistributionBranch(tree.branch, None, tree=tree)
1681
dbs = DistributionBranchSet()
1684
self.addCleanup(tree.unlock)
1685
tree.commit("add packaging")
1686
tree.branch.tags.set_tag("upstream-%s" % version1.upstream_version,
1688
builder = SourcePackageBuilder("package", version2)
1689
builder.add_default_control()
1690
builder.add_upstream_file("a", "New a")
1691
builder.add_upstream_file("b", "Renamed a")
1693
upstream_tree.rename_one('a', 'b')
1694
# We don't add the new file upstream, as the new file id would
1695
# be picked up from there.
1696
upstream_rev2 = upstream_tree.commit("two")
1697
db.merge_upstream(builder.tar_name(), version2.upstream_version,
1698
version1.upstream_version,
1699
upstream_branch=upstream_tree.branch,
1700
upstream_revision=upstream_rev2)
1701
self.assertEqual("a-id", tree.path2id("b"))
1703
def test_merge_upstream_rename_on_top(self):
1704
"""Test renaming a file upstream, replacing an existing file."""
1705
self.requireFeature(PristineTarFeature)
1706
version1 = Version("1.0-1")
1707
version2 = Version("1.1-1")
1708
upstream_tree = self.make_branch_and_tree("upstream")
1709
upstream_tree.lock_write()
1710
self.addCleanup(upstream_tree.unlock)
1711
self.build_tree(['upstream/a', 'upstream/b'])
1712
upstream_tree.add(['a', 'b'], ['a-id', 'b-id'])
1713
upstream_rev1 = upstream_tree.commit("one")
1714
tree = upstream_tree.bzrdir.sprout('packaging').open_workingtree()
1715
db = DistributionBranch(tree.branch, None, tree=tree)
1716
dbs = DistributionBranchSet()
1719
self.addCleanup(tree.unlock)
1720
tree.commit("add packaging")
1721
tree.branch.tags.set_tag("upstream-%s" % version1.upstream_version,
1723
builder = SourcePackageBuilder("package", version2)
1724
builder.add_default_control()
1725
builder.add_upstream_file("b", "Renamed a")
1727
upstream_tree.unversion(['b-id'])
1728
os.unlink('upstream/b')
1729
upstream_tree.rename_one('a', 'b')
1730
# We don't add the new file upstream, as the new file id would
1731
# be picked up from there.
1732
upstream_rev2 = upstream_tree.commit("two")
1733
db.merge_upstream(builder.tar_name(), version2.upstream_version,
1734
version1.upstream_version,
1735
upstream_branch=upstream_tree.branch,
1736
upstream_revision=upstream_rev2)
1737
self.assertEqual("a-id", tree.path2id("b"))
1586
1739
def test_import_symlink(self):
1587
1740
version = Version("1.0-1")
1588
1741
self.requireFeature(PristineTarFeature)