~ubuntu-branches/debian/sid/bzr-builddeb/sid

« back to all changes in this revision

Viewing changes to tests/blackbox/test_import_upstream.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij, Colin Watson, Jelmer Vernooij, Robert Collins, James Westby
  • Date: 2010-08-11 18:23:54 UTC
  • Revision ID: james.westby@ubuntu.com-20100811182354-pgqznly5bbtoiso4
Tags: 2.5
[ Colin Watson ]
* Consider a .dsc without a Format: to be Format: 1.0.

[ Jelmer Vernooij ]
* export now uses the timestamp of the last revision, making them more
  deterministic, and so hopefully producing the same tarballs when it is
  used for that.
* Fix use of getattr to have 3 arguments to avoid exception. (LP: #572093)
* Implement the automatic_tag_name hook so that "bzr tag" with no arguments
  will tag based on the version in debian/changelog.
* Support upstream/VERSION tags, for compatibility with git-
  buildpackage. LP: #551362
* Support upstream tarballs without a pristine tar delta.
* Support -r argument to import-upstream.

[ Robert Collins ]
* Add import-upstream command which imports an upstream - useful for
  migrating existing packaging branches into pristine-tar using mode.
* Stop stripping .bzrignore from tarball imports. LP: #496907
* Make the upstream branch authoritative for file ids when importing a
  tarball, stopping errors when files are renamed. LP: #588060

[ James Westby ]
* Add a --package-merge option to builddeb to build with the -v and -sa
  appropriate when doing a merge from Debian or similar. LP: #576027
* Fixed a logic error that stops -r working in merge-upstream. LP: #594575

[ Jelmer Vernooij ]
* Determine Bazaar home directory using bzrlib to prevent test
  isolation issues. Closes: #614125
* Bump standards version to 3.9.1 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#    Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
 
2
#    Copyright (C) 2010 Canonical Ltd
 
3
#    
 
4
#    This file is part of bzr-builddeb.
 
5
#
 
6
#    bzr-builddeb is free software; you can redistribute it and/or modify
 
7
#    it under the terms of the GNU General Public License as published by
 
8
#    the Free Software Foundation; either version 2 of the License, or
 
9
#    (at your option) any later version.
 
10
#
 
11
#    bzr-builddeb is distributed in the hope that it will be useful,
 
12
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#    GNU General Public License for more details.
 
15
#
 
16
#    You should have received a copy of the GNU General Public License
 
17
#    along with bzr-builddeb; if not, write to the Free Software
 
18
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 
 
20
"""Tests for import-upstream."""
 
21
 
 
22
try:
 
23
    from debian.changelog import Version
 
24
except ImportError:
 
25
    # Prior to 0.1.15 the debian module was called debian_bundle
 
26
    from debian_bundle.changelog import Version
 
27
 
 
28
from bzrlib.plugins.builddeb.tests.blackbox.test_import_dsc import TestBaseImportDsc
 
29
from bzrlib.plugins.builddeb.tests.test_import_dsc import PristineTarFeature
 
30
 
 
31
 
 
32
class TestImportUpstream(TestBaseImportDsc):
 
33
 
 
34
    def setUp(self):
 
35
        TestBaseImportDsc.setUp(self)
 
36
        self.requireFeature(PristineTarFeature)
 
37
 
 
38
    def assertHasImportArtifacts(self, tree, upstream_version=None):
 
39
        upstream_version = self.get_test_upstream_version(upstream_version)
 
40
        upstream_tag = self.upstream_tag(upstream_version)
 
41
        tags = tree.branch.tags
 
42
        # If it imported, we have a tag
 
43
        imported_rev = tags.lookup_tag(upstream_tag)
 
44
        # For a working revision tree
 
45
        revtree = tree.branch.repository.revision_tree(imported_rev)
 
46
        revtree.lock_read()
 
47
        self.addCleanup(revtree.unlock)
 
48
        return revtree
 
49
 
 
50
    def assertUpstreamContentAndFileIdFromTree(self, revtree, fromtree):
 
51
        """Check what content and file ids revtree has."""
 
52
        # that does not have debian/
 
53
        self.assertEqual(None, revtree.path2id('debian'))
 
54
        # and does have the same fileid for README as in tree
 
55
        self.assertNotEqual(None, revtree.path2id('README'))
 
56
        self.assertEqual(fromtree.path2id('README'), revtree.path2id('README'))
 
57
 
 
58
    def make_upstream_tree(self):
 
59
        """Make an upstream tree with its own history."""
 
60
        upstreamtree = self.make_branch_and_tree('upstream')
 
61
        self.make_unpacked_upstream_source(transport=upstreamtree.bzrdir.root_transport)
 
62
        upstreamtree.smart_add(['upstream'])
 
63
        upstreamtree.commit('upstream release')
 
64
        return upstreamtree
 
65
 
 
66
    def make_upstream_change(self, upstreamtree):
 
67
        """Commit a change to upstreamtree."""
 
68
        # Currently an empty commit, but we may need file content changes to be
 
69
        # thorough?
 
70
        return upstreamtree.commit('new commit')
 
71
 
 
72
    def make_workingdir(self):
 
73
        """Make a working directory with both upstream source and debian packaging."""
 
74
        tree = self.make_branch_and_tree('working')
 
75
        self.make_unpacked_upstream_source(transport=tree.bzrdir.root_transport)
 
76
        self.make_debian_dir(tree.bzrdir.root_transport.local_abspath('debian'))
 
77
        tree.smart_add(['working'])
 
78
        tree.commit('save changes')
 
79
        return tree
 
80
 
 
81
    def upstream_tag(self, version):
 
82
        return "upstream-%s" % version
 
83
 
 
84
    def test_import_upstream_no_branch_no_prior_tarball(self):
 
85
        self.make_upstream_tarball()
 
86
        self.make_real_source_package()
 
87
        tree = self.make_branch_and_tree('working')
 
88
        self.make_unpacked_upstream_source(transport=tree.bzrdir.root_transport)
 
89
        self.make_debian_dir(tree.bzrdir.root_transport.local_abspath('debian'))
 
90
        tree.smart_add(['working'])
 
91
        tree.commit('save changes')
 
92
        tar_path = "../%s" % self.upstream_tarball_name
 
93
        out, err = self.run_bzr(['import-upstream', self.upstream_version,
 
94
            tar_path], working_dir='working')
 
95
        self.assertEqual('Imported %s as tag:upstream-%s.\n' % (tar_path,
 
96
            self.upstream_version), out)
 
97
        tree.lock_read()
 
98
        self.addCleanup(tree.unlock)
 
99
        self.assertFalse(tree.has_changes())
 
100
        revtree = self.assertHasImportArtifacts(tree)
 
101
        self.assertUpstreamContentAndFileIdFromTree(revtree, tree)
 
102
 
 
103
    def test_import_upstream_with_branch_no_prior_tarball(self):
 
104
        self.make_upstream_tarball()
 
105
        # The two branches are deliberately disconnected, to reflect likely
 
106
        # situations where this is first called.
 
107
        upstreamtree = self.make_upstream_tree()
 
108
        tree = self.make_workingdir()
 
109
        self.run_bzr(['import-upstream', self.upstream_version, "../%s" %
 
110
            self.upstream_tarball_name, '../upstream'],
 
111
            working_dir='working')
 
112
        tree.lock_read()
 
113
        self.addCleanup(tree.unlock)
 
114
        self.assertFalse(tree.has_changes())
 
115
        revtree = self.assertHasImportArtifacts(tree)
 
116
        self.assertUpstreamContentAndFileIdFromTree(revtree, upstreamtree)
 
117
 
 
118
    def test_import_upstream_with_branch_prior_tarball(self):
 
119
        self.make_upstream_tarball()
 
120
        upstreamtree = self.make_upstream_tree()
 
121
        tree = self.make_workingdir()
 
122
        # XXX: refactor: make this an API call - running blackbox in test prep
 
123
        # is ugly.
 
124
        self.run_bzr(['import-upstream', self.upstream_version, "../%s" %
 
125
            self.upstream_tarball_name, '../upstream'],
 
126
            working_dir='working')
 
127
        new_version = Version('0.2-1')
 
128
        self.make_upstream_tarball(new_version.upstream_version)
 
129
        upstream_parent = self.make_upstream_change(upstreamtree)
 
130
        self.run_bzr(['import-upstream', new_version.upstream_version, "../%s" %
 
131
            self._upstream_tarball_name(self.package_name, new_version.upstream_version), '../upstream'],
 
132
            working_dir='working')
 
133
        tree.lock_read()
 
134
        self.addCleanup(tree.unlock)
 
135
        self.assertFalse(tree.has_changes())
 
136
        revtree = self.assertHasImportArtifacts(tree, new_version.upstream_version)
 
137
        self.assertUpstreamContentAndFileIdFromTree(revtree, upstreamtree)
 
138
        # Check parents: we want
 
139
        # [previous_import, upstream_parent] to reflect that the 'branch' is
 
140
        # the tarball branch aka upstream branch [ugh], and then a merge in
 
141
        # from upstream so that cherrypicks do the right thing.
 
142
        tags = tree.branch.tags
 
143
        self.assertEqual([tags.lookup_tag(self.upstream_tag(self.upstream_version)),
 
144
            upstreamtree.branch.last_revision()],
 
145
            revtree.get_parent_ids())
 
146
 
 
147
 
 
148
# vim: ts=4 sts=4 sw=4
 
149