~ubuntu-branches/ubuntu/oneiric/bzr-builddeb/oneiric

« back to all changes in this revision

Viewing changes to tests/test_import_dsc.py

  • Committer: Bazaar Package Importer
  • Author(s): James Westby, James Westby, Jelmer Vernooij
  • Date: 2010-08-18 20:12:20 UTC
  • mfrom: (5.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100818201220-yblzkx1w097ohh7h
Tags: 2.6
[ James Westby ]

* Don't fail if asked to use a .bz2 tarball that is already in the desired
  location. LP: #616786
* Don't crash if we are asked to merge-upstream with an unrelated branch.
  LP: #619614.
* Don't strip -n from the version we get in merge-upstream, as some
  upstreams have this in there, and trying to support both means supporting
  both badly. If you are used to doing "bzr merge-upstream --version
  <package version>" then it will no longer work for you, use the
  upstream version instead.
* Don't crash when doing merge-upstream with a branch that does a rename
  and then ships another file with the old path in the tarball that isn't
  in the branch.

[ Jelmer Vernooij ]

* Fix the auto-detection of merge mode.
* Don't crash on merge mode packages where there is no export-upstream
  if we can't find the tarball.
* Determine Bazaar home directory using bzrlib to prevent test
  isolation issues. LP: #614125

Show diffs side-by-side

added added

removed removed

Lines of Context:
1499
1499
            tf.add("a")
1500
1500
        finally:
1501
1501
            tf.close()
1502
 
        conflicts = db.merge_upstream(tarball_filename, Version("0.2"),
1503
 
                Version("0.1"))
 
1502
        conflicts = db.merge_upstream(tarball_filename, "0.2", "0.1")
1504
1503
        self.assertEqual(0,  conflicts)
1505
1504
 
1506
1505
    def test_merge_upstream_initial_with_branch(self):
1537
1536
            tf.add("a")
1538
1537
        finally:
1539
1538
            tf.close()
1540
 
        conflicts = db.merge_upstream(tarball_filename, Version("0.2"),
1541
 
                Version("0.1"), upstream_branch=upstream_tree.branch,
 
1539
        conflicts = db.merge_upstream(tarball_filename, "0.2", "0.1",
 
1540
                upstream_branch=upstream_tree.branch,
1542
1541
                upstream_revision=upstream_rev)
1543
1542
        self.assertEqual(0,  conflicts)
1544
1543
 
1577
1576
            tf.add("a")
1578
1577
        finally:
1579
1578
            tf.close()
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
1584
 
 
1585
    def test_merge_upstream_with_unrelated_branch(self):
 
1586
        """Check that we can merge-upstream with an unrelated branch.
 
1587
 
 
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.
 
1591
        """
 
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")
 
1598
        builder.build()
 
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()
 
1605
        dbs.add_branch(db)
 
1606
        db.import_package(builder.dsc_name())
 
1607
        builder.new_version(version2)
 
1608
        builder.add_upstream_file("a", "New a")
 
1609
        builder.build()
 
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()
 
1617
        dbs.add_branch(db)
 
1618
        tree.lock_write()
 
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"))
 
1633
 
 
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'])
 
1637
        tree.add(['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()
 
1647
        dbs.add_branch(db)
 
1648
        tarball_filename = "package-0.2.tar.gz"
 
1649
        tf = tarfile.open(tarball_filename, 'w:gz')
 
1650
        try:
 
1651
            f = open("a", "wb")
 
1652
            try:
 
1653
                f.write("aaa")
 
1654
            finally:
 
1655
                f.close()
 
1656
            tf.add("a")
 
1657
        finally:
 
1658
            tf.close()
 
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'))
 
1662
 
 
1663
    def test_merge_upstream_rename_and_replace(self):
 
1664
        """Test renaming a file upstream and replacing it.
 
1665
 
 
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.
 
1669
        """
 
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()
 
1682
        dbs.add_branch(db)
 
1683
        tree.lock_write()
 
1684
        self.addCleanup(tree.unlock)
 
1685
        tree.commit("add packaging")
 
1686
        tree.branch.tags.set_tag("upstream-%s" % version1.upstream_version,
 
1687
                upstream_rev1)
 
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")
 
1692
        builder.build()
 
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"))
 
1702
 
 
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()
 
1717
        dbs.add_branch(db)
 
1718
        tree.lock_write()
 
1719
        self.addCleanup(tree.unlock)
 
1720
        tree.commit("add packaging")
 
1721
        tree.branch.tags.set_tag("upstream-%s" % version1.upstream_version,
 
1722
                upstream_rev1)
 
1723
        builder = SourcePackageBuilder("package", version2)
 
1724
        builder.add_default_control()
 
1725
        builder.add_upstream_file("b", "Renamed a")
 
1726
        builder.build()
 
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"))
 
1738
 
1586
1739
    def test_import_symlink(self):
1587
1740
        version = Version("1.0-1")
1588
1741
        self.requireFeature(PristineTarFeature)