def test_tar_pristine_prefix(self):
     """Test tarball import with prefix mangling"""
     tmpdir = tempfile.mkdtemp(dir=self._tmpdir, prefix='tar_prefix_')
     source = UpstreamSource(self._origs['tar'])
     _orig, prist = prepare_sources(source, 'test', '1.0', 'test.tgz', None,
                                    False, 'np', tmpdir)
     src_ls = ls_tar(self._origs['tar'])
     prist_ref = set([fname.replace('test-1.0', 'np') for fname in src_ls])
     self.assertEqual(prist_ref, ls_tar(prist))
示例#2
0
    def test_option_submodules(self):
        """Test the --git-submodules option"""
        repo = self.init_test_repo('gbp-test')

        # Create submodule to upstream branch
        sub_repo = self.orig_repos['gbp-test-native']
        pkg_branch = repo.get_branch()
        upstr_branch = 'upstream'
        repo.set_branch(upstr_branch)
        repo.add_submodule(sub_repo.path)
        repo.commit_all('Add submodule')
        repo.set_branch(pkg_branch)

        sub_files = sub_repo.ls_tree('HEAD')
        upstr_files = [
            'gbp-test/' + path.decode() for path in repo.ls_tree(upstr_branch)
        ]

        # Test the "no" option
        eq_(
            mock_gbp([
                '--git-no-submodules',
                '--git-upstream-tree=%s' % upstr_branch, '--git-ignore-new'
            ]), 0)
        tar_files = ls_tar('../rpmbuild/SOURCES/gbp-test-1.1.tar.bz2', False)
        self.check_files(upstr_files, tar_files)
        shutil.rmtree('../rpmbuild')

        # Test the "yes" option
        eq_(
            mock_gbp([
                '--git-submodules',
                '--git-upstream-tree=%s' % upstr_branch, '--git-ignore-new'
            ]), 0)
        tar_files = ls_tar('../rpmbuild/SOURCES/gbp-test-1.1.tar.bz2', False)
        ref_files = upstr_files + [
            'gbp-test/gbp-test-native.repo/' + path.decode()
            for path in sub_files
        ]
        self.check_files(ref_files, tar_files)
        shutil.rmtree('../rpmbuild')

        # Test submodule failure
        shutil.rmtree('gbp-test-native.repo')
        repo.create('gbp-test-native.repo')
        eq_(
            mock_gbp([
                '--git-submodules',
                '--git-upstream-tree=%s' % upstr_branch, '--git-ignore-new'
            ]), 2)
        self._check_log(
            -2, ".*Error generating submodules' archives: "
            "Failed to list submodules of [0-9a-f]{40}: fatal: "
            "not a tree object")
示例#3
0
    def test_option_upstream_tree(self):
        """Test the --git-upstream-tree option"""
        repo = self.init_test_repo('gbp-test')

        # Dummy update to upstream branch
        pkg_branch = repo.get_branch()
        upstr_branch = 'upstream'
        orig_files = ['gbp-test/' + path for \
                path in repo.ls_tree(upstr_branch)] + ['gbp-test']
        repo.set_branch(upstr_branch)
        with open('new-file', 'w') as fobj:
            fobj.write('New file\n')
        with open('new-file2', 'w') as fobj:
            fobj.write('New file 2\n')
        repo.add_files(['new-file', 'new-file2'])
        repo.commit_files('new-file', 'New content')
        repo.commit_files('new-file2', 'New content 2')
        repo.set_branch(pkg_branch)

        # TAG (default) does not contain the new files
        eq_(mock_gbp([]), 0)
        tar_files = ls_tar('../rpmbuild/SOURCES/gbp-test-1.1.tar.bz2')
        self.check_files(orig_files, tar_files)
        shutil.rmtree('../rpmbuild')

        # Branch contains them both
        eq_(mock_gbp(['--git-upstream-tree=BRANCH']), 0)
        tar_files = ls_tar('../rpmbuild/SOURCES/gbp-test-1.1.tar.bz2')
        self.check_files(
            orig_files + ['gbp-test/new-file', 'gbp-test/new-file2'],
            tar_files)
        shutil.rmtree('../rpmbuild')

        # The first "extra-commit" in upstream contains only one new file
        eq_(mock_gbp(['--git-upstream-tree=%s^' % upstr_branch]), 0)
        tar_files = ls_tar('../rpmbuild/SOURCES/gbp-test-1.1.tar.bz2')
        self.check_files(orig_files + ['gbp-test/new-file'], tar_files)
        shutil.rmtree('../rpmbuild')

        # Test invalid upstream treeish
        eq_(
            mock_gbp(
                ['--git-upstream-tree=TAG', '--git-upstream-tag=invalid-tag']),
            2)
        self._check_log(-1, ".*Invalid upstream treeish invalid-tag")
        eq_(
            mock_gbp([
                '--git-upstream-tree=BRANCH', '--git-native=no',
                '--git-upstream-branch=invalid-branch'
            ]), 2)
        self._check_log(-1, ".*invalid-branch is not a valid branch")
        eq_(mock_gbp(['--git-upstream-tree=invalid-tree']), 2)
        self._check_log(-1, ".*Invalid treeish object")
示例#4
0
    def test_option_submodules(self):
        """Test the --git-submodules option"""
        repo = self.init_test_repo('gbp-test')

        # Create submodule to upstream branch
        sub_repo = self.orig_repos['gbp-test-native']
        pkg_branch = repo.get_branch()
        upstr_branch = 'srcdata/gbp-test/upstream'
        repo.set_branch(upstr_branch)
        repo.add_submodule(sub_repo.path)
        repo.commit_all('Add submodule')
        repo.set_branch(pkg_branch)

        sub_files = self.ls_tree(sub_repo, 'HEAD')
        upstr_files = [
            'gbp-test/' + path for path in self.ls_tree(repo, upstr_branch)
        ]

        # Test the "no" option
        eq_(
            mock_gbp([
                '--git-no-submodules',
                '--git-upstream-tree=%s' % upstr_branch,
                '--git-ignore-untracked'
            ]), 0)
        tar_files = ls_tar('../rpmbuild/SOURCES/gbp-test-1.1.tar.bz2', False)
        self.check_files(upstr_files, tar_files)
        shutil.rmtree('../rpmbuild')

        # Test the "yes" option
        eq_(
            mock_gbp([
                '--git-submodules',
                '--git-upstream-tree=%s' % upstr_branch,
                '--git-ignore-untracked'
            ]), 0)
        tar_files = ls_tar('../rpmbuild/SOURCES/gbp-test-1.1.tar.bz2', False)
        ref_files = upstr_files + [
            'gbp-test/gbp-test-native.repo/' + path for path in sub_files
        ]
        self.check_files(ref_files, tar_files)
        shutil.rmtree('../rpmbuild')

        # Test submodule failure
        shutil.rmtree('gbp-test-native.repo')
        repo.create('gbp-test-native.repo')
        eq_(
            mock_gbp([
                '--git-submodules',
                '--git-upstream-tree=%s' % upstr_branch,
                '--git-ignore-untracked'
            ]), 2)
 def test_tar(self):
     """Basic test for tarball sources, with pristine-tar"""
     tmpdir = tempfile.mkdtemp(dir=self._tmpdir, prefix='tar_basic_')
     source = UpstreamSource(self._origs['tar'])
     orig, prist = prepare_sources(source, 'test', '1.0', 'test.tgz', None,
                                   False, 'test-1.0', tmpdir)
     src_ls = ls_tar(self._origs['tar'])
     orig_ref = set([
         fname.replace('test-1.0/', '') for fname in src_ls
         if fname != 'test-1.0'
     ])
     self.assertEqual(orig_ref, ls_dir(orig))
     self.assertEqual(src_ls, ls_tar(prist))
 def test_tar_filter_pristine_prefix(self):
     """Filter tarball, pristine-tar prefix mangling but not filter"""
     tmpdir = tempfile.mkdtemp(dir=self._tmpdir, prefix='tar_filter_')
     source = UpstreamSource(self._origs['tar'])
     orig, prist = prepare_sources(source, 'test', '1.0', 'test.tgz',
                                   ['pkg'], False, 'newp', tmpdir)
     src_ls = ls_tar(self._origs['tar'])
     orig_ref = set([
         fname.replace('test-1.0/', '') for fname in src_ls
         if fname != 'test-1.0' and not fname.startswith('test-1.0/pkg')
     ])
     prist_ref = set(
         [fname.replace('test-1.0', 'newp') for fname in src_ls])
     self.assertEqual(orig_ref, ls_dir(orig))
     self.assertEqual(prist_ref, ls_tar(prist))
 def test_rename(self):
     """Renaming orig archive"""
     orig = os.path.join(DATA_DIR, 'gbp-test-1.0.tar.bz2')
     args = ['--pristine-tar', '--pristine-tarball-name=my.tgz', orig]
     eq_(self.mock_import(args), 0)
     self.check_repo(None, None, [])
     self.check_files(ls_tar(orig), self.ls_pristine_tar('my.tgz'))
    def test_option_upstream_tree(self):
        """Test the --git-upstream-tree option"""
        repo = self.init_test_repo('gbp-test')

        # Dummy update to upstream branch
        pkg_branch = repo.get_branch()
        upstr_branch = 'upstream'
        orig_files = ['gbp-test/' + path for \
                path in repo.ls_tree(upstr_branch)] + ['gbp-test']
        repo.set_branch(upstr_branch)
        with open('new-file', 'w') as fobj:
            fobj.write('New file\n')
        with open('new-file2', 'w') as fobj:
            fobj.write('New file 2\n')
        repo.add_files(['new-file', 'new-file2'])
        repo.commit_files('new-file', 'New content')
        repo.commit_files('new-file2', 'New content 2')
        repo.set_branch(pkg_branch)

        # TAG (default) does not contain the new files
        eq_(mock_gbp([]), 0)
        tar_files = ls_tar('../rpmbuild/SOURCES/gbp-test-1.1.tar.bz2')
        self.check_files(orig_files, tar_files)
        shutil.rmtree('../rpmbuild')

        # Branch contains them both
        eq_(mock_gbp(['--git-upstream-tree=BRANCH']), 0)
        tar_files = ls_tar('../rpmbuild/SOURCES/gbp-test-1.1.tar.bz2')
        self.check_files(orig_files +
                         ['gbp-test/new-file', 'gbp-test/new-file2'], tar_files)
        shutil.rmtree('../rpmbuild')

        # The first "extra-commit" in upstream contains only one new file
        eq_(mock_gbp(['--git-upstream-tree=%s^' % upstr_branch]), 0)
        tar_files = ls_tar('../rpmbuild/SOURCES/gbp-test-1.1.tar.bz2')
        self.check_files(orig_files + ['gbp-test/new-file'], tar_files)
        shutil.rmtree('../rpmbuild')

        # Test invalid upstream treeish
        eq_(mock_gbp(['--git-upstream-tree=TAG',
                      '--git-upstream-tag=invalid-tag']), 2)
        self._check_log(-1, ".*Invalid upstream treeish invalid-tag")
        eq_(mock_gbp(['--git-upstream-tree=BRANCH', '--git-native=no',
                      '--git-upstream-branch=invalid-branch']), 2)
        self._check_log(-1, ".*invalid-branch is not a valid branch")
        eq_(mock_gbp(['--git-upstream-tree=invalid-tree']), 2)
        self._check_log(-1, ".*Invalid treeish object")
 def test_nopristinefilter(self):
     """Test --no-pristine-tar-filter"""
     orig = os.path.join(DATA_DIR, 'gbp-test-1.0.tar.bz2')
     eq_(self.mock_import(['--pristine-tar', '--filter=README', orig]), 0)
     self.check_repo(None, None, [])
     self.check_tree('upstream', ['Makefile', 'dummy.sh'])
     self.check_files(ls_tar(orig),
                      self.ls_pristine_tar('gbp-test-1.0.tar.bz2'))
 def test_nofilter_prefix(self):
     """Test prefix mangling without any filtering"""
     orig = os.path.join(DATA_DIR, 'gbp-test-1.0.tar.bz2')
     eq_(self.mock_import(['--pristine-tar', '--orig-prefix=new', orig]), 0)
     self.check_repo(None, None, None)
     self.check_tree('upstream', ['Makefile', 'dummy.sh', 'README'])
     prist_ref = set(
         [fname.replace('gbp-test', 'new') for fname in ls_tar(orig)])
     self.check_files(prist_ref,
                      self.ls_pristine_tar('gbp-test-1.0.tar.bz2'))
    def test_option_submodules(self):
        """Test the --git-submodules option"""
        repo = self.init_test_repo('gbp-test')

        # Create submodule to upstream branch
        sub_repo = self.orig_repos['gbp-test-native']
        pkg_branch = repo.get_branch()
        upstr_branch = 'upstream'
        repo.set_branch(upstr_branch)
        repo.add_submodule(sub_repo.path)
        repo.commit_all('Add submodule')
        repo.set_branch(pkg_branch)

        sub_files = sub_repo.ls_tree('HEAD')
        upstr_files = ['gbp-test/' + path.decode() for
                       path in repo.ls_tree(upstr_branch)]

        # Test the "no" option
        eq_(mock_gbp(['--git-no-submodules', '--git-upstream-tree=%s' %
                      upstr_branch, '--git-ignore-new']), 0)
        tar_files = ls_tar('../rpmbuild/SOURCES/gbp-test-1.1.tar.bz2', False)
        self.check_files(upstr_files, tar_files)
        shutil.rmtree('../rpmbuild')

        # Test the "yes" option
        eq_(mock_gbp(['--git-submodules', '--git-upstream-tree=%s' %
                      upstr_branch, '--git-ignore-new']), 0)
        tar_files = ls_tar('../rpmbuild/SOURCES/gbp-test-1.1.tar.bz2', False)
        ref_files = upstr_files + ['gbp-test/gbp-test-native.repo/' + path.decode() for
                                   path in sub_files]
        self.check_files(ref_files, tar_files)
        shutil.rmtree('../rpmbuild')

        # Test submodule failure
        shutil.rmtree('gbp-test-native.repo')
        repo.create('gbp-test-native.repo')
        eq_(mock_gbp(['--git-submodules', '--git-upstream-tree=%s' %
                      upstr_branch, '--git-ignore-new']), 2)
        self._check_log(-2,
                        ".*Error generating submodules' archives: "
                        "Failed to list submodules of [0-9a-f]{40}: fatal: "
                        "not a tree object")
 def test_basic_import_pristine_tar(self):
     """Test importing with pristine-tar"""
     orig = os.path.join(DATA_DIR, 'gbp-test-1.0.tar.bz2')
     eq_(self.mock_import(['--pristine-tar', '--merge', orig]), 0)
     files = ['Makefile', 'README', 'dummy.sh']
     branches = ['master', 'upstream', 'pristine-tar']
     self.check_repo('master', branches, files)
     subject = self.repo.get_commit_info('pristine-tar')['subject']
     eq_(subject, 'pristine-tar data for %s' % os.path.basename(orig))
     self.check_files(ls_tar(orig),
                      self.ls_pristine_tar('gbp-test-1.0.tar.bz2'))
 def ls_pristine_tar(self, archive):
     """List contents of the tarball committed into pristine-tar"""
     tmpdir = os.path.abspath(tempfile.mkdtemp(dir='.'))
     tarball = os.path.join(tmpdir, archive)
     try:
         popen = subprocess.Popen(['pristine-tar', 'checkout', tarball],
                                  cwd=self.repo.path)
         popen.wait()
         if popen.returncode:
             raise Exception('Pristine-tar checkout failed!')
         return ls_tar(tarball)
     finally:
         shutil.rmtree(tmpdir)
 def test_dir_pristine_filter(self):
     """Test filtering pristine-tar and mangling prefix"""
     tmpdir = tempfile.mkdtemp(dir=self._tmpdir, prefix='dir_filter3_')
     source = UpstreamSource(self._origs['dir'])
     orig, prist = prepare_sources(source, 'test', '1.0', 'test.tar.gz',
                                   ['pkg'], True, 'newpref', tmpdir)
     src_ls = ls_dir(self._origs['dir'])
     orig_filt_ref = set(
         [fname for fname in src_ls if not fname.startswith('pkg')])
     prist_ref = set(['newpref/%s' % fname
                      for fname in orig_filt_ref] + ['newpref'])
     self.assertEqual(orig_filt_ref, ls_dir(orig))
     self.assertEqual(prist_ref, ls_tar(prist))
 def test_dir_pristine_nofilter(self):
     """Test filtering of unpacked sources, not filtering pristine-tar"""
     tmpdir = tempfile.mkdtemp(dir=self._tmpdir, prefix='dir_filter2_')
     source = UpstreamSource(self._origs['dir'])
     orig, prist = prepare_sources(source, 'test', '1.0', 'test.tar.gz',
                                   ['pkg'], False, None, tmpdir)
     src_ls = ls_dir(self._origs['dir'])
     orig_filt_ref = set(
         [fname for fname in src_ls if not fname.startswith('pkg')])
     prist_ref = set(['test-1.0/%s' % fname
                      for fname in src_ls] + ['test-1.0'])
     self.assertEqual(orig_filt_ref, ls_dir(orig))
     self.assertEqual(prist_ref, ls_tar(prist))
示例#16
0
    def test_option_orig_prefix(self):
        """Test the --git-orig-prefix option"""
        repo = self.init_test_repo('gbp-test')

        # Building with invalid prefix should fail
        eq_(mock_gbp(['--git-orig-prefix=foo']), 1)
        upstr_branch = 'srcdata/gbp-test/upstream'
        ref_files = [
            'foo/' + path for path in self.ls_tree(repo, upstr_branch)
        ]
        tar_files = ls_tar('../rpmbuild/SOURCES/gbp-test-1.1.tar.bz2', False)
        self.check_files(tar_files, ref_files)

        # Test invalid keys
        eq_(mock_gbp(['--git-orig-prefix=%(foo)s', '--git-no-build']), 1)
        self._check_log(-1, ".*Unknown key 'foo' in orig prefix format")