def test_create_branches(self): """Test if creating missing branches works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-3.0', 'hello-debhelper_%s.dsc' % version) dsc = _dsc('2.6-2') assert import_dsc(['arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', dsc]) == 0 repo = ComponentTestGitRepository('hello-debhelper') os.chdir('hello-debhelper') assert len(repo.get_commits()) == 2 reflog, ret = repo._git_getoutput('reflog') ok_("gbp: Import Debian changes" in reflog[1]) ok_("gbp: Import Upstream version 2.6" in reflog[2]) self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream']) dsc = _dsc('2.8-1') assert import_dsc(['arg0', '--verbose', '--pristine-tar', '--debian-branch=foo', '--upstream-branch=bar', '--create-missing-branches', dsc]) == 0 self._check_repo_state(repo, 'master', ['bar', 'foo', 'master', 'pristine-tar', 'upstream']) commits, expected = len(repo.get_commits()), 2 ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected))
def test_create_branches(self): """Test that creating missing branches works""" dsc = self._dsc30('2.6-2') assert import_dsc(['arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', dsc]) == 0 repo = ComponentTestGitRepository('hello-debhelper') os.chdir('hello-debhelper') assert len(repo.get_commits()) == 2 self._check_reflog(repo) self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream']) dsc = self._dsc30('2.8-1') assert import_dsc(['arg0', '--verbose', '--pristine-tar', '--debian-branch=foo', '--upstream-branch=bar', '--create-missing-branches', dsc]) == 0 self._check_repo_state(repo, 'master', ['bar', 'foo', 'master', 'pristine-tar', 'upstream']) commits, expected = len(repo.get_commits()), 2 ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected))
def test_import_debian_native(self): """Test that importing of debian native packages works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-native', 'git-buildpackage_%s.dsc' % version) dsc = _dsc('0.4.14') assert import_dsc(['arg0', dsc]) == 0 repo = ComponentTestGitRepository('git-buildpackage') self._check_repo_state(repo, 'master', ['master']) assert len(repo.get_commits()) == 1 commitmsg = repo.get_commit_info('HEAD')['body'] ok_("git-buildpackage (0.01) unstable; urgency=low" in commitmsg) ok_("git-buildpackage (0.4.14) unstable; urgency=low" in commitmsg) os.chdir('git-buildpackage') dsc = _dsc('0.4.15') assert import_dsc(['arg0', dsc]) == 0 self._check_repo_state(repo, 'master', ['master']) assert len(repo.get_commits()) == 2 commitmsg = repo.get_commit_info('HEAD')['body'] ok_("git-buildpackage (0.4.14) unstable; urgency=low" not in commitmsg) ok_("git-buildpackage (0.4.15) unstable; urgency=low" in commitmsg) dsc = _dsc('0.4.16') assert import_dsc(['arg0', dsc]) == 0 self._check_repo_state(repo, 'master', ['master']) assert len(repo.get_commits()) == 3 commitmsg = repo.get_commit_info('HEAD')['body'] ok_("git-buildpackage (0.4.14) unstable; urgency=low" not in commitmsg) ok_("git-buildpackage (0.4.15) unstable; urgency=low" not in commitmsg) ok_("git-buildpackage (0.4.16) unstable; urgency=low" in commitmsg)
def test_import_30_pristine_tar(self): dscfile = self._dsc30('2.6-1') assert import_dsc(['arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', dscfile]) == 0 repo = ComponentTestGitRepository('hello-debhelper') self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream']) commits, expected = len(repo.get_commits()), 2 commitmsg = repo.get_commit_info('HEAD')['body'] eq_("hello-debhelper (2.6-1) unstable; urgency=low", commitmsg.split('\n')[0]) ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected)) os.chdir(repo.path) dscfile = self._dsc30('2.6-2') assert import_dsc(['arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', dscfile]) == 0 commits, expected = len(repo.get_commits()), 3 commitmsg = repo.get_commit_info('HEAD')['body'] eq_("hello-debhelper (2.6-2) unstable; urgency=medium", commitmsg.split('\n')[0]) ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected)) commits, expected = len(repo.get_commits(until='pristine-tar')), 1 ok_(commits == expected, "Found %d pristine-tar commits instead of %d" % (commits, expected))
def test_bare(self): """Test that importing into bare repository works""" dsc = self._dsc30('2.6-2') assert import_dsc(['arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', dsc]) == 0 repo = ComponentTestGitRepository('hello-debhelper') os.chdir('hello-debhelper') assert len(repo.get_commits()) == 2 self._check_reflog(repo) self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream']) commitmsg = repo.get_commit_info('HEAD')['body'] ok_("hello-debhelper (2.6-2) unstable; urgency=medium" in commitmsg) ok_("hello (1.3-7) experimental; urgency=LOW" in commitmsg) dsc = self._dsc30('2.8-1') assert import_dsc(['arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', dsc]) == 0 commits, expected = len(repo.get_commits()), 4 ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected)) commitmsg = repo.get_commit_info('HEAD')['body'] ok_("hello-debhelper (2.8-1) unstable; urgency=low" in commitmsg) ok_("ello-debhelper (2.7-1) unstable; urgency=low" in commitmsg) ok_("hello-debhelper (2.6-2) unstable; urgency=medium" not in commitmsg)
def test_create_branches(self): """Test if creating missing branches works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, "dsc-3.0", "hello-debhelper_%s.dsc" % version) dsc = _dsc("2.6-2") assert ( import_dsc( ["arg0", "--verbose", "--pristine-tar", "--debian-branch=master", "--upstream-branch=upstream", dsc] ) == 0 ) repo = ComponentTestGitRepository("hello-debhelper") os.chdir("hello-debhelper") assert len(repo.get_commits()) == 2 self._check_repo_state(repo, "master", ["master", "pristine-tar", "upstream"]) dsc = _dsc("2.8-1") assert ( import_dsc( [ "arg0", "--verbose", "--pristine-tar", "--debian-branch=foo", "--upstream-branch=bar", "--create-missing-branches", dsc, ] ) == 0 ) self._check_repo_state(repo, "master", ["bar", "foo", "master", "pristine-tar", "upstream"]) commits, expected = len(repo.get_commits()), 2 ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected))
def _test_buildpackage(self, pkg, dir, version, opts=[]): dsc = self._dsc_name(pkg, version, dir) assert import_dsc(['arg0', dsc]) == 0 ComponentTestGitRepository(pkg) prebuild_out = os.path.join(os.path.abspath(pkg), 'prebuild.out') postbuild_out = os.path.join(os.path.abspath(pkg), 'postbuild.out') os.chdir(pkg) args = ['arg0', '--git-prebuild=printenv > %s' % prebuild_out, '--git-postbuild=printenv > %s' % postbuild_out, '--git-builder=/bin/true', '--git-cleaner=/bin/true'] + opts ret = buildpackage(args) ok_(ret == 0, "Building the package failed") eq_(os.path.exists(prebuild_out), True) eq_(os.path.exists(postbuild_out), True) self.check_hook_vars('prebuild', ["GBP_BUILD_DIR", "GBP_GIT_DIR", "GBP_BUILD_DIR"]) self.check_hook_vars('postbuild', ["GBP_CHANGES_FILE", "GBP_BUILD_DIR", "GBP_CHANGES_FILE", "GBP_BUILD_DIR"])
def test_import(self, repo): pkg = 'hello-debhelper' dsc = self._dsc_name(pkg, '2.6-2', 'dsc-3.0') eq_(import_dsc(['arg0', dsc]), 0) self._test_pq(repo, 'import') author, subject = repo.get_head_author_subject() eq_(author, 'Santiago Vila <*****@*****.**>') eq_(subject, 'Modified doc/Makefile.in to avoid ' '/usr/share/info/dir.gz') self._test_pq(repo, 'switch') self._append_patch(repo, 'foo', '''\ Author: Mr. T. St <*****@*****.**> Description: Short DEP3 description Long DEP3 description . Continued --- /dev/null +++ b/foo @@ -0,0 +1 @@ +foo ''') self._test_pq(repo, 'import', ['--force']) author, subject = repo.get_head_author_subject() eq_(subject, 'Short DEP3 description') eq_(author, '"Mr. T. St" <*****@*****.**>')
def test_debian_buildpackage(self): """Test that building a native debian package works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-native', 'git-buildpackage_%s.dsc' % version) dsc = _dsc('0.4.14') assert import_dsc(['arg0', dsc]) == 0 repo = ComponentTestGitRepository('git-buildpackage') os.chdir('git-buildpackage') ret = buildpackage(['arg0', '--git-prebuild=printenv > prebuild.out', '--git-postbuild=printenv > postbuild.out', '--git-builder=/bin/true', '--git-cleaner=/bin/true']) ok_(ret == 0, "Building the package failed") eq_(os.path.exists('prebuild.out'), True) self.check_hook_vars('prebuild', ["GBP_BUILD_DIR", "GBP_GIT_DIR", "GBP_GIT_DIR", "GBP_BUILD_DIR"]) self.check_hook_vars('postbuild', ["GBP_CHANGES_FILE", "GBP_BUILD_DIR", "GBP_CHANGES_FILE", "GBP_BUILD_DIR"])
def test_update_component_tarballs(self): """ Test importing new version with additional tarballs works """ dsc = self._dsc('2.6-2') ok_(import_dsc(['arg0', '--pristine-tar', dsc]) == 0) repo = ComponentTestGitRepository(self.pkg) os.chdir(self.pkg) self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar']) # Import 2.8 orig = self._orig('2.8', dir='dsc-3.0-additional-tarballs') ok_(import_orig(['arg0', '--component=foo', '--no-interactive', '--pristine-tar', orig]) == 0) self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar'], tags=['debian/2.6-2', 'upstream/2.6', 'upstream/2.8']) self._check_component_tarballs(repo, ['foo/test1', 'foo/test2']) dsc = DscFile.parse(self._dsc('2.8-1', dir='dsc-3.0-additional-tarballs')) # Check if we can rebuild the upstream tarball and additional tarball ptars = [('hello-debhelper_2.8.orig.tar.gz', 'pristine-tar', '', dsc.tgz), ('hello-debhelper_2.8.orig-foo.tar.gz', 'pristine-tar^', 'foo', dsc.additional_tarballs['foo'])] p = DebianPristineTar(repo) outdir = os.path.abspath('.') for f, w, s, o in ptars: eq_(repo.get_subject(w), 'pristine-tar data for %s' % f) old = self.hash_file(o) p.checkout('hello-debhelper', '2.8', 'gzip', outdir, component=s) out = os.path.join(outdir, f) new = self.hash_file(out) eq_(old, new, "Checksum %s of regenerated tarball %s does not match original %s" % (f, old, new)) os.unlink(out) # Import 2.9 orig = self._orig('2.9', dir='dsc-3.0-additional-tarballs') ok_(import_orig(['arg0', '--component=foo', '--no-interactive', '--pristine-tar', orig]) == 0) self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar'], tags=['debian/2.6-2', 'upstream/2.6', 'upstream/2.8', 'upstream/2.9']) self._check_component_tarballs(repo, ['foo/test1', 'foo/test2', 'foo/test3']) dsc = DscFile.parse(self._dsc('2.9-1', dir='dsc-3.0-additional-tarballs')) # Check if we can rebuild the upstream tarball and additional tarball ptars = [('hello-debhelper_2.9.orig.tar.gz', 'pristine-tar', '', dsc.tgz), ('hello-debhelper_2.9.orig-foo.tar.gz', 'pristine-tar^', 'foo', dsc.additional_tarballs['foo'])] p = DebianPristineTar(repo) outdir = os.path.abspath('.') for f, w, s, o in ptars: eq_(repo.get_subject(w), 'pristine-tar data for %s' % f) old = self.hash_file(o) p.checkout('hello-debhelper', '2.9', 'gzip', outdir, component=s) new = self.hash_file(os.path.join(outdir, f)) eq_(old, new, "Checksum %s of regenerated tarball %s does not match original %s" % (f, old, new))
def test_target_dir(self): """Test that setting the target dir works""" dsc = self._dsc30('2.6-2') assert import_dsc(['arg0', '--verbose', '--no-pristine-tar', dsc, 'targetdir']) == 0 assert os.path.exists('targetdir') repo = ComponentTestGitRepository('targetdir') self._check_repo_state(repo, 'master', ['master', 'upstream'])
def test_broken_download(self): def _not_a_dsc(version): return os.path.join(DEB_TEST_DOWNLOAD_URL, 'dsc-3.0', 'hello-debhelper_%s.orig.tar.gz' % version) f = _not_a_dsc('2.6') assert import_dsc(['arg0', '--allow-unauthenticated', f]) == 1 self._check_log(-1, "gbp:error: Did not find a dsc file at")
def test_update(self): repo = GitRepository.create(self.pkg) os.chdir(self.pkg) dsc = self._dsc('2.6-2') ok_(import_dsc(['arg0', '--pristine-tar', dsc]) == 0) self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar']) self._orig('2.8') self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar'], tags=['debian/2.6-2', 'upstream/2.6'])
def test_download(self): def _dsc(version): return os.path.join(DEB_TEST_DOWNLOAD_URL, 'dsc-native', 'git-buildpackage_%s.dsc' % version) dsc = _dsc('0.4.14') assert import_dsc(['arg0', '--allow-unauthenticated', dsc]) == 0 repo = ComponentTestGitRepository('git-buildpackage') self._check_repo_state(repo, 'master', ['master']) assert len(repo.get_commits()) == 1
def test_upstream_branch_is_master(self): """Make sure we can import when upstream-branch == master (#750962)""" dsc = self._dsc30('2.6-2') assert import_dsc([ 'arg0', '--verbose', '--no-pristine-tar', '--debian-branch=debian', '--upstream-branch=master', dsc ]) == 0 repo = ComponentTestGitRepository('hello-debhelper') self._check_repo_state(repo, 'debian', ['debian', 'master']) commits, expected = len(repo.get_commits()), 2 ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected))
def test_target_dir(self): """Test if setting the target dir works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-3.0', 'hello-debhelper_%s.dsc' % version) dsc = _dsc('2.6-2') assert import_dsc( ['arg0', '--verbose', '--no-pristine-tar', dsc, 'targetdir']) == 0 assert os.path.exists('targetdir') repo = ComponentTestGitRepository('targetdir') self._check_repo_state(repo, 'master', ['master', 'upstream'])
def test_debian_branch_not_master(self): """Make sure we only have debian-branch and upstream-branch after an initial import""" dsc = self._dsc30('2.6-2') assert import_dsc([ 'arg0', '--verbose', '--no-pristine-tar', '--debian-branch=pk4', '--upstream-branch=upstream', dsc ]) == 0 repo = ComponentTestGitRepository('hello-debhelper') self._check_repo_state(repo, 'pk4', ['pk4', 'upstream']) commits, expected = len(repo.get_commits()), 2 ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected))
def test_upstream_branch_is_master(self): """Make sure we can import when upstream-branch == master (#750962)""" dsc = self._dsc30('2.6-2') assert import_dsc(['arg0', '--verbose', '--no-pristine-tar', '--debian-branch=debian', '--upstream-branch=master', dsc]) == 0 repo = ComponentTestGitRepository('hello-debhelper') self._check_repo_state(repo, 'debian', ['debian', 'master']) commits, expected = len(repo.get_commits()), 2 ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected))
def test_debian_buildpackage(self): """Test that building a native debian package works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-native', 'git-buildpackage_%s.dsc' % version) dsc = _dsc('0.4.14') assert import_dsc(['arg0', dsc]) == 0 repo = ComponentTestGitRepository('git-buildpackage') os.chdir('git-buildpackage') ret = buildpackage( ['arg0', '--git-builder=/bin/true', '--git-cleaner=/bin/true']) ok_(ret == 0, "Building the package failed")
def test_import_10(self): """Test if importing a 1.0 source format package works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-1.0', 'hello-debhelper_%s.dsc' % version) dsc = _dsc('2.6-2') assert import_dsc(['arg0', dsc]) == 0 repo = ComponentTestGitRepository('hello-debhelper') self._check_repo_state(repo, 'master', ['master', 'upstream'], tags=['upstream/2.6', 'debian/2.6-2']) assert len(repo.get_commits()) == 2
def test_debian_import(self): """Test that importing of debian native packages works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, "dsc-native", "git-buildpackage_%s.dsc" % version) dsc = _dsc("0.4.14") assert import_dsc(["arg0", dsc]) == 0 repo = ComponentTestGitRepository("git-buildpackage") self._check_repo_state(repo, "master", ["master"]) assert len(repo.get_commits()) == 1 os.chdir("git-buildpackage") dsc = _dsc("0.4.15") assert import_dsc(["arg0", dsc]) == 0 self._check_repo_state(repo, "master", ["master"]) assert len(repo.get_commits()) == 2 dsc = _dsc("0.4.16") assert import_dsc(["arg0", dsc]) == 0 self._check_repo_state(repo, "master", ["master"]) assert len(repo.get_commits()) == 3
def test_debian_branch_not_master(self): """Make sure we only have debian-branch and upstream-branch after an initial import""" dsc = self._dsc30('2.6-2') assert import_dsc(['arg0', '--verbose', '--no-pristine-tar', '--debian-branch=pk4', '--upstream-branch=upstream', dsc]) == 0 repo = ComponentTestGitRepository('hello-debhelper') self._check_repo_state(repo, 'pk4', ['pk4', 'upstream']) commits, expected = len(repo.get_commits()), 2 ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected))
def test_import_10(self): """Test that importing a 1.0 source format package works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-1.0', 'hello-debhelper_%s.dsc' % version) dsc = _dsc('2.6-2') assert import_dsc(['arg0', dsc]) == 0 repo = ComponentTestGitRepository('hello-debhelper') self._check_repo_state(repo, 'master', ['master', 'upstream'], tags=['upstream/2.6', 'debian/2.6-2']) assert len(repo.get_commits()) == 2
def test_debian_import(self): """Test that importing of debian native packages works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-native', 'git-buildpackage_%s.dsc' % version) dsc = _dsc('0.4.14') assert import_dsc(['arg0', dsc]) == 0 repo = ComponentTestGitRepository('git-buildpackage') self._check_repo_state(repo, 'master', ['master']) assert len(repo.get_commits()) == 1 os.chdir('git-buildpackage') dsc = _dsc('0.4.15') assert import_dsc(['arg0', dsc]) == 0 self._check_repo_state(repo, 'master', ['master']) assert len(repo.get_commits()) == 2 dsc = _dsc('0.4.16') assert import_dsc(['arg0', dsc]) == 0 self._check_repo_state(repo, 'master', ['master']) assert len(repo.get_commits()) == 3
def test_import_poor_dep3_behaviour(self, repo): """Demonstrate the issues with the current DEP3 support""" pkg = 'hello-debhelper' dsc = self._dsc_name(pkg, '2.6-2', 'dsc-3.0') eq_(import_dsc(['arg0', dsc]), 0) self._append_patch(repo, 'foo', '''\ Author: Mr. T. St <*****@*****.**> Description: A very long description with wrapp- ing to increase readability in the file, which is currently split into a short and long description. Origin: https://twitter.com/MrT/status/941789967361097728 Forwarded: not-needed --- /dev/null +++ b/foo @@ -0,0 +1 @@ +foo ''') self._test_pq(repo, 'import', ['--force']) _, subject = repo.get_head_author_subject() eq_(subject, 'A very long description with wrapp-') self._test_pq(repo, 'export') relevant_parts_of_patch = '' with open('debian/patches/foo.patch') as patch_file: for line in patch_file: # skip the date as it's currently set to now(), # not a deterministic value if line.startswith('Date: '): continue # stop reading after the main part of the description; # i.e. ignore the bit that git(1) fully controls. if line.startswith('---'): break relevant_parts_of_patch += line eq_(relevant_parts_of_patch, '''\ From: "Mr. T. St" <*****@*****.**> Subject: A very long description with wrapp- Origin: https://twitter.com/MrT/status/941789967361097728 Forwarded: not-needed ing to increase readability in the file, which is currently split into a short and long description. ''')
def test_bare(self): """Test if importing into bare repository""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-3.0', 'hello-debhelper_%s.dsc' % version) dsc = _dsc('2.6-2') assert import_dsc(['arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', dsc]) == 0 repo = ComponentTestGitRepository('hello-debhelper') os.chdir('hello-debhelper') assert len(repo.get_commits()) == 2 reflog, ret = repo._git_getoutput('reflog') ok_("gbp: Import Debian changes" in reflog[1]) ok_("gbp: Import Upstream version 2.6" in reflog[2]) self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream']) commitmsg = repo.get_commit_info('HEAD')['body'] ok_("hello-debhelper (2.6-2) unstable; urgency=medium" in commitmsg) ok_("hello (1.3-7) experimental; urgency=LOW" in commitmsg) dsc = _dsc('2.8-1') assert import_dsc(['arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', dsc]) == 0 commits, expected = len(repo.get_commits()), 4 ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected)) commitmsg = repo.get_commit_info('HEAD')['body'] ok_("hello-debhelper (2.8-1) unstable; urgency=low" in commitmsg) ok_("ello-debhelper (2.7-1) unstable; urgency=low" in commitmsg) ok_("hello-debhelper (2.6-2) unstable; urgency=medium" not in commitmsg)
def test_import_30_filters(self): dscfile = self._dsc30('2.6-1') assert import_dsc([ 'arg0', '--verbose', '--no-pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', '--filter=debian/patches/*', '--filter=AUTHORS', dscfile ]) == 0 repo = ComponentTestGitRepository('hello-debhelper') self._check_repo_state(repo, 'master', ['master', 'upstream']) os.chdir('hello-debhelper') ok_(os.path.exists("./debian/changelog")) ok_(os.path.exists("./configure.ac")) ok_(not os.path.exists("./debian/patches/series")) ok_(not os.path.exists("./debian/patches/AUTHORS"))
def test_empty_repo(self): """Make sure we can import into an empty repository""" dsc = self._dsc30('2.6-2') repo = GitRepository.create("hello-debhelper") self._check_repo_state(repo, None, []) os.chdir('hello-debhelper') assert import_dsc([ 'arg0', '--verbose', '--no-pristine-tar', '--debian-branch=pk4', '--upstream-branch=upstream', dsc ]) == 0 self._check_repo_state(repo, 'pk4', ['pk4', 'upstream']) commits, expected = len(repo.get_commits()), 2 ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected))
def test_bare(self): """Test if importing into bare repository""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-3.0', 'hello-debhelper_%s.dsc' % version) dsc = _dsc('2.6-2') assert import_dsc([ 'arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', dsc ]) == 0 repo = ComponentTestGitRepository('hello-debhelper') os.chdir('hello-debhelper') assert len(repo.get_commits()) == 2 reflog, ret = repo._git_getoutput('reflog') ok_("gbp: Import Debian changes" in reflog[1]) ok_("gbp: Import Upstream version 2.6" in reflog[2]) self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream']) commitmsg = repo.get_commit_info('HEAD')['body'] ok_("hello-debhelper (2.6-2) unstable; urgency=medium" in commitmsg) ok_("hello (1.3-7) experimental; urgency=LOW" in commitmsg) dsc = _dsc('2.8-1') assert import_dsc([ 'arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', dsc ]) == 0 commits, expected = len(repo.get_commits()), 4 ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected)) commitmsg = repo.get_commit_info('HEAD')['body'] ok_("hello-debhelper (2.8-1) unstable; urgency=low" in commitmsg) ok_("ello-debhelper (2.7-1) unstable; urgency=low" in commitmsg) ok_("hello-debhelper (2.6-2) unstable; urgency=medium" not in commitmsg)
def test_debian_buildpackage(self): """Test that building a native debian package works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-native', 'git-buildpackage_%s.dsc' % version) dsc = _dsc('0.4.14') assert import_dsc(['arg0', dsc]) == 0 repo = ComponentTestGitRepository('git-buildpackage') os.chdir('git-buildpackage') ret = buildpackage(['arg0', '--git-builder=/bin/true', '--git-cleaner=/bin/true']) ok_(ret == 0, "Building the package failed")
def test_empty_repo(self): """Make sure we can import into an empty repository""" dsc = self._dsc30('2.6-2') repo = GitRepository.create("hello-debhelper") self._check_repo_state(repo, None, []) os.chdir('hello-debhelper') assert import_dsc(['arg0', '--verbose', '--no-pristine-tar', '--debian-branch=pk4', '--upstream-branch=upstream', dsc]) == 0 self._check_repo_state(repo, 'pk4', ['pk4', 'upstream']) commits, expected = len(repo.get_commits()), 2 ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected))
def test_target_dir(self): """Test if setting the target dir works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-3.0', 'hello-debhelper_%s.dsc' % version) dsc = _dsc('2.6-2') assert import_dsc(['arg0', '--verbose', '--no-pristine-tar', dsc, 'targetdir']) == 0 assert os.path.exists('targetdir') repo = ComponentTestGitRepository('targetdir') self._check_repo_state(repo, 'master', ['master', 'upstream'])
def test_git_archive_tree_non_existent(self): """Test that we're failing tarball generation when commits are missing""" pkg = 'hello-debhelper' dsc = self._dsc_name(pkg, '2.8-1', 'dsc-3.0-additional-tarballs') assert import_dsc(['arg0', '--no-pristine-tar', dsc]) == 0 repo = ComponentTestGitRepository(pkg) os.chdir(pkg) assert_false(repo.has_branch('pristine-tar'), "Pristine-tar branch not must exist") ret = export_orig(['arg0', '--component=bar', # non-existing component '--no-pristine-tar']) ok_(ret == 1, "Exporting tarballs must fail") self._check_log(-1, "gbp:error: No tree for 'bar' found in " "'upstream/2.8' to create additional tarball from")
def test_create_branches(self): """Test that creating missing branches works""" dsc = self._dsc30('2.6-2') assert import_dsc([ 'arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', dsc ]) == 0 repo = ComponentTestGitRepository('hello-debhelper') os.chdir('hello-debhelper') assert len(repo.get_commits()) == 2 self._check_reflog(repo) self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream']) dsc = self._dsc30('2.8-1') assert import_dsc([ 'arg0', '--verbose', '--pristine-tar', '--debian-branch=foo', '--upstream-branch=bar', '--create-missing-branches', dsc ]) == 0 self._check_repo_state( repo, 'master', ['bar', 'foo', 'master', 'pristine-tar', 'upstream']) commits, expected = len(repo.get_commits()), 2 ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected))
def test_import_multiple(self): """Test if importing a multiple tarball package works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-3.0-additional-tarballs', 'hello-debhelper_%s.dsc' % version) dsc = _dsc('2.8-1') assert import_dsc(['arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', dsc]) == 1 self._check_log(0, "gbp:error: Cannot import package with additional tarballs but found 'hello-debhelper_2.8.orig-foo.tar.gz")
def test_pristine_tar_commit_non_existent(self): """Test that we're failing if pristine-tar commit is missing""" pkg = 'hello-debhelper' dsc = self._dsc_name(pkg, '2.8-1', 'dsc-3.0-additional-tarballs') assert import_dsc(['arg0', '--pristine-tar', dsc]) == 0 repo = ComponentTestGitRepository(pkg) os.chdir(pkg) assert_true(repo.has_branch('pristine-tar'), "Pristine-tar branch must exist") repo.delete_branch("pristine-tar") repo.create_branch("pristine-tar") # create a nonsense pristine-tar branch ret = export_orig(['arg0', '--component=foo', '--pristine-tar']) ok_(ret == 1, "Exporting tarballs must fail") self._check_log(-1, ".*git show refs/heads/pristine-tar:.*failed")
def test_pristine_tar_commit_non_existent(self): """Test that we're failing if pristine-tar commit is missing""" pkg = 'hello-debhelper' dsc = self._dsc_name(pkg, '2.8-1', 'dsc-3.0-additional-tarballs') assert import_dsc(['arg0', '--pristine-tar', dsc]) == 0 repo = ComponentTestGitRepository(pkg) os.chdir(pkg) assert_true(repo.has_branch('pristine-tar'), "Pristine-tar branch must exist") repo.delete_branch("pristine-tar") repo.create_branch( "pristine-tar") # create a nonsense pristine-tar branch ret = export_orig(['arg0', '--component=foo', '--pristine-tar']) ok_(ret == 1, "Exporting tarballs must fail") self._check_log(-1, ".*git show refs/heads/pristine-tar:.*failed")
def test_import_multiple(self): """Test if importing a multiple tarball package works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-3.0-additional-tarballs', 'hello-debhelper_%s.dsc' % version) dsc = _dsc('2.8-1') assert import_dsc([ 'arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', dsc ]) == 1 self._check_log( 0, "gbp:error: Cannot import package with additional tarballs but found 'hello-debhelper_2.8.orig-foo.tar.gz" )
def test_import_30_additional_tarball_pristine_tar(self): """Test that importing a package with additional tarballs works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-3.0-additional-tarballs', 'hello-debhelper_%s.dsc' % version) dscfile = _dsc('2.8-1') assert import_dsc([ 'arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', dscfile ]) == 0 repo = ComponentTestGitRepository('hello-debhelper') self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream']) commits, expected = len(repo.get_commits()), 2 commitmsg = repo.get_commit_info('HEAD')['body'] ok_("hello-debhelper (2.8-1) unstable; urgency=low" in commitmsg) ok_("hello (1.3-7) experimental; urgency=LOW" in commitmsg) for file in [b'foo/test1', b'foo/test2']: ok_( file in repo.ls_tree('HEAD'), "Could not find component tarball file %s in %s" % (file, repo.ls_tree('HEAD'))) ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected)) dsc = DscFile.parse(dscfile) # Check if we can rebuild the tarball and component ptars = [('hello-debhelper_2.8.orig.tar.gz', 'pristine-tar', '', dsc.tgz), ('hello-debhelper_2.8.orig-foo.tar.gz', 'pristine-tar^', 'foo', dsc.additional_tarballs['foo'])] p = DebianPristineTar(repo) outdir = os.path.abspath('.') for f, w, s, o in ptars: eq_(repo.get_subject(w), 'pristine-tar data for %s' % f) old = self.hash_file(o) p.checkout('hello-debhelper', '2.8', 'gzip', outdir, component=s) new = self.hash_file(os.path.join(outdir, f)) eq_( old, new, "Checksum %s of regenerated tarball %s does not match original %s" % (f, old, new))
def test_existing_dir(self): """ Importing outside of git repository with existing target dir must fail """ # Create directory we should stumble upon os.makedirs('hello-debhelper') dsc = self._dsc30('2.8-1') assert import_dsc([ 'arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', dsc ]) == 1 self._check_log( 0, "gbp:error: Directory 'hello-debhelper' already exists. If you want to import into it, " "please change into this directory otherwise move it away first")
def test_clone_nonempty(self): """Test that cloning into an existing dir fails""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-native', 'git-buildpackage_%s.dsc' % version) # Build up somethng we can clone from dsc = _dsc('0.4.14') assert import_dsc(['arg0', dsc]) == 0 repo = ComponentTestGitRepository('git-buildpackage') self._check_repo_state(repo, 'master', ['master']) assert len(repo.get_commits()) == 1 ok_(clone(['arg0', repo.path]) == 1, "Cloning did no fail as expected") self._check_log(-2, "gbp:error: Git command failed: Error running git clone: fatal: destination path 'git-buildpackage' already exists and is not an empty directory.")
def test_pristine_tar_upstream_signatures_without(self): """Test that exporting upstream signatures in pristine tar works without imported signature""" pkg = 'hello-debhelper' dsc = self._dsc_name(pkg, '2.6-1', 'dsc-3.0') files = ["%s_2.6.orig.tar.gz" % pkg, "%s_2.6.orig.tar.gz.asc" % pkg] assert import_dsc(['arg0', '--pristine-tar', dsc]) == 0 ComponentTestGitRepository(pkg) os.chdir(pkg) for f in files: self.assertFalse(os.path.exists(os.path.join('..', f)), "File %s must not exist" % f) ret = export_orig( ['arg0', '--pristine-tar', '--upstream-signatures=no']) ok_(ret == 0, "Exporting tarballs failed") self.assertTrue(os.path.exists(os.path.join('..', files[0])), "Tarball %s not found" % files[0]) self.assertFalse(os.path.exists(os.path.join('..', files[1])), "Signature %s found" % files[1]) os.remove(os.path.join('..', files[0])) for f in files: self.assertFalse(os.path.exists(os.path.join('..', f)), "File %s must not exist" % f) ret = export_orig( ['arg0', '--pristine-tar', '--upstream-signatures=auto']) ok_(ret == 0, "Exporting tarballs failed") self.assertTrue(os.path.exists(os.path.join('..', files[0])), "Tarball %s not found" % files[0]) self.assertFalse(os.path.exists(os.path.join('..', files[1])), "Signature %s found" % files[1]) os.remove(os.path.join('..', files[0])) for f in files: self.assertFalse(os.path.exists(os.path.join('..', f)), "File %s must not exist" % f) ret = export_orig( ['arg0', '--pristine-tar', '--upstream-signatures=on']) ok_(ret == 1, "Exporting tarballs must fail") self._check_log( -1, "gbp:error: Can not find requested upstream signature for archive " "'hello-debhelper_2.6.orig.tar.gz' in pristine tar commit.")
def test_import_30_filters(self): dscfile = self._dsc30('2.6-1') assert import_dsc(['arg0', '--verbose', '--no-pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', '--filter=debian/patches/*', '--filter=AUTHORS', dscfile]) == 0 repo = ComponentTestGitRepository('hello-debhelper') self._check_repo_state(repo, 'master', ['master', 'upstream']) os.chdir('hello-debhelper') ok_(os.path.exists("./debian/changelog")) ok_(os.path.exists("./configure.ac")) ok_(not os.path.exists("./debian/patches/series")) ok_(not os.path.exists("./debian/patches/AUTHORS"))
def test_update_fail_create_upstream_tag(self): repo = GitRepository.create(self.pkg) os.chdir(self.pkg) dsc = self._dsc('2.6-2') ok_(import_dsc(['arg0', '--pristine-tar', dsc]) == 0) self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar']) heads = self.rem_refs(repo, self.def_branches) orig = self._orig('2.8') with patch('gbp.git.repository.GitRepository.create_tag', side_effect=GitRepositoryError('this is a create tag error mock')): ok_(import_orig(['arg0', '--no-interactive', '--pristine-tar', orig]) == 1) self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar'], tags=['debian/2.6-2', 'upstream/2.6']) self.check_refs(repo, heads)
def test_git_archive_tree_non_existent(self): """Test that we're failing tarball generation when commits are missing""" pkg = 'hello-debhelper' dsc = self._dsc_name(pkg, '2.8-1', 'dsc-3.0-additional-tarballs') assert import_dsc(['arg0', '--no-pristine-tar', dsc]) == 0 repo = ComponentTestGitRepository(pkg) os.chdir(pkg) assert_false(repo.has_branch('pristine-tar'), "Pristine-tar branch not must exist") ret = export_orig([ 'arg0', '--component=bar', # non-existing component '--no-pristine-tar' ]) ok_(ret == 1, "Exporting tarballs must fail") self._check_log( -1, "gbp:error: No tree for 'bar' found in " "'upstream/2.8' to create additional tarball from")
def test_tag_only(self): """Test that only tagging a native debian package works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-native', 'git-buildpackage_%s.dsc' % version) dsc = _dsc('0.4.14') assert import_dsc(['arg0', dsc]) == 0 repo = ComponentTestGitRepository('git-buildpackage') os.chdir('git-buildpackage') repo.delete_tag('debian/0.4.14') # make sure we can tag again ret = buildpackage([ 'arg0', '--git-tag-only', '--git-posttag=printenv > posttag.out', '--git-builder=touch builder-run.stamp', '--git-cleaner=/bin/true' ]) ok_(ret == 0, "Building the package failed") eq_(os.path.exists('posttag.out'), True) eq_(os.path.exists('builder-run.stamp'), False) self.check_hook_vars('posttag', ["GBP_TAG", "GBP_BRANCH", "GBP_SHA1"])
def test_component_generation(self): """Test that generating tarball and additional tarball works without pristine-tar""" pkg = 'hello-debhelper' dsc = self._dsc_name(pkg, '2.8-1', 'dsc-3.0-additional-tarballs') tarballs = [ "../%s_2.8.orig-foo.tar.gz" % pkg, "../%s_2.8.orig.tar.gz" % pkg ] assert import_dsc(['arg0', '--no-pristine-tar', dsc]) == 0 repo = ComponentTestGitRepository(pkg) os.chdir(pkg) assert_false(repo.has_branch('pristine-tar'), "Pristine-tar branch must not exist") for t in tarballs: self.assertFalse(os.path.exists(t), "Tarball %s must not exist" % t) ret = export_orig(['arg0', '--component=foo', '--no-pristine-tar']) ok_(ret == 0, "Exporting tarballs failed") for t in tarballs: self.assertTrue(os.path.exists(t), "Tarball %s not found" % t)
def test_import_signature(self): dscfile = self._dsc30('2.8-1') assert import_dsc([ 'arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', dscfile ]) == 0 repo = ComponentTestGitRepository('hello-debhelper') self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream']) commits, expected = len(repo.get_commits()), 2 commits, expected = len(repo.get_commits(until='pristine-tar')), 1 ok_( commits == expected, "Found %d pristine-tar commits instead of %d" % (commits, expected)) eq_( repo.ls_tree('pristine-tar'), { b'hello-debhelper_2.8.orig.tar.gz.delta', b'hello-debhelper_2.8.orig.tar.gz.id', b'hello-debhelper_2.8.orig.tar.gz.asc' })
def test_pristinetar_subtarball_generation(self): """Test that generating tarball and additional tarball works with pristine-tar""" pkg = 'hello-debhelper' dsc = self._dsc_name(pkg, '2.8-1', 'dsc-3.0-additional-tarballs') tarballs = ["../%s_2.8.orig-foo.tar.gz" % pkg, "../%s_2.8.orig.tar.gz" % pkg] assert import_dsc(['arg0', '--pristine-tar', dsc]) == 0 repo = ComponentTestGitRepository(pkg) os.chdir(pkg) assert_true(repo.has_branch('pristine-tar'), "Pristine-tar branch must exist") for t in tarballs: self.assertFalse(os.path.exists(t), "Tarball %s must not exist" % t) ret = buildpackage(['arg0', '--git-subtarball=foo', '--git-pristine-tar', '--git-posttag=printenv > posttag.out', '--git-builder=touch builder-run.stamp', '--git-cleaner=/bin/true']) ok_(ret == 0, "Building the package failed") for t in tarballs: self.assertTrue(os.path.exists(t), "Tarball %s not found" % t)
def _test_buildpackage(self, pkg, dir, version): dsc = self._dsc_name(pkg, version, dir) assert import_dsc(['arg0', dsc]) == 0 ComponentTestGitRepository(pkg) os.chdir(pkg) ret = buildpackage(['arg0', '--git-prebuild=printenv > prebuild.out', '--git-postbuild=printenv > postbuild.out', '--git-builder=/bin/true', '--git-cleaner=/bin/true']) ok_(ret == 0, "Building the package failed") eq_(os.path.exists('prebuild.out'), True) self.check_hook_vars('prebuild', ["GBP_BUILD_DIR", "GBP_GIT_DIR", "GBP_GIT_DIR", "GBP_BUILD_DIR"]) self.check_hook_vars('postbuild', ["GBP_CHANGES_FILE", "GBP_BUILD_DIR", "GBP_CHANGES_FILE", "GBP_BUILD_DIR"])
def test_pristinetar_component_generation(self): """Test that generating tarball and additional tarball works with pristine-tar""" pkg = 'hello-debhelper' dsc = self._dsc_name(pkg, '2.8-1', 'dsc-3.0-additional-tarballs') tarballs = [ "../%s_2.8.orig-foo.tar.gz" % pkg, "../%s_2.8.orig.tar.gz" % pkg ] assert import_dsc(['arg0', '--pristine-tar', dsc]) == 0 repo = ComponentTestGitRepository(pkg) os.chdir(pkg) assert_true(repo.has_branch('pristine-tar'), "Pristine-tar branch must exist") for t in tarballs: self.assertFalse(os.path.exists(t), "Tarball %s must not exist" % t) # Make sure the tree object for importing the main tarball is recreated repo.collect_garbage(prune='all', aggressive=True) ret = export_orig(['arg0', '--component=foo', '--pristine-tar']) ok_(ret == 0, "Exporting tarballs failed") for t in tarballs: self.assertTrue(os.path.exists(t), "Tarball %s not found" % t)
def _import_one(cls, dsc, opts): opts = opts or [] assert import_dsc(['arg0'] + opts + [dsc]) == 0 parsed = DscFile(dsc) return ComponentTestGitRepository(parsed.pkg)