def test_dir(self):
     """Basic test for unpacked sources, no filtering etc"""
     tmpdir = tempfile.mkdtemp(dir=self._tmpdir, prefix='dir_basic_')
     source = UpstreamSource(self._origs['dir'])
     orig, prist = prepare_sources(source, 'test', '1.0', None, None, False,
                                   None, tmpdir)
     self.assertEqual(ls_dir(self._origs['dir']), ls_dir(orig))
     self.assertEqual(prist, '')
 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))
 def test_dir_filter(self):
     """Test filtering of unpacked sources"""
     tmpdir = tempfile.mkdtemp(dir=self._tmpdir, prefix='dir_filter_')
     source = UpstreamSource(self._origs['dir'])
     orig, prist = prepare_sources(source, 'test', '1.0', None, ['pkg'],
                                   False, None, tmpdir)
     orig_filt_ref = set([
         fname for fname in ls_dir(self._origs['dir'])
         if not fname.startswith('pkg')
     ])
     self.assertEqual(orig_filt_ref, ls_dir(orig))
     self.assertEqual(prist, '')
 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_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))
 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))
Exemplo n.º 8
0
def main(argv):
    ret = 0

    (options, args) = parse_args(argv)
    if not options:
        return 1

    tmpdir = tempfile.mkdtemp(dir=options.tmp_dir, prefix='import-orig-rpm_')
    try:
        try:
            repo = RpmGitRepository('.')
        except GitRepositoryError:
            raise GbpError, "%s is not a git repository" % (
                os.path.abspath('.'))

        spec = find_spec(repo, options)
        source = find_source(spec, options, args)

        # an empty repo has now branches:
        initial_branch = repo.get_branch()
        is_empty = False if initial_branch else True

        if not repo.has_branch(options.upstream_branch):
            if options.create_missing_branches:
                gbp.log.info("Will create missing branch '%s'" %
                             options.upstream_branch)
            elif is_empty:
                options.create_missing_branches = True
            else:
                raise GbpError(no_upstream_branch_msg %
                               options.upstream_branch)

        sourcepackage, version = detect_name_and_version(
            repo, source, spec, options)

        (clean, out) = repo.is_clean()
        if not clean and not is_empty:
            gbp.log.err(
                "Repository has uncommitted changes, commit these first: ")
            raise GbpError, out

        if repo.bare:
            set_bare_repo_options(options)

        # Prepare sources for importing
        if options.pristine_tar:
            prepare_pristine = pristine_tarball_name(
                source, sourcepackage, version, options.pristine_tarball_name)
        else:
            prepare_pristine = None
        unpacked_orig, pristine_orig = \
                prepare_sources(source, sourcepackage, version,
                                prepare_pristine, options.filters,
                                options.filter_pristine_tar,
                                options.orig_prefix, tmpdir)

        # Don't mess up our repo with git metadata from an upstream tarball
        if os.path.isdir(os.path.join(unpacked_orig, '.git/')):
            raise GbpError("The orig tarball contains .git metadata - "
                           "giving up.")
        try:
            filter_msg = ["", " (filtering out %s)" % options.filters
                          ][len(options.filters) > 0]
            gbp.log.info("Importing '%s' to branch '%s'%s..." %
                         (source.path, options.upstream_branch, filter_msg))
            gbp.log.info("Source package is %s" % sourcepackage)
            gbp.log.info("Upstream version is %s" % version)

            msg = upstream_import_commit_msg(options, version)

            if options.vcs_tag:
                parents = [repo.rev_parse("%s^{}" % options.vcs_tag)]
            else:
                parents = None

            commit = repo.commit_dir(
                unpacked_orig,
                msg=msg,
                branch=options.upstream_branch,
                other_parents=parents,
                create_missing_branch=options.create_missing_branches)
            if options.pristine_tar and pristine_orig:
                gbp.log.info("Pristine-tar: commiting %s" % pristine_orig)
                repo.pristine_tar.commit(pristine_orig,
                                         options.upstream_branch)

            tag_str_fields = dict(upstreamversion=version, vendor="Upstream")
            tag = repo.version_to_tag(options.upstream_tag, tag_str_fields)
            repo.create_tag(name=tag,
                            msg="Upstream version %s" % version,
                            commit=commit,
                            sign=options.sign_tags,
                            keyid=options.keyid)
            if options.merge:
                gbp.log.info("Merging to '%s'" % options.packaging_branch)
                if repo.has_branch(options.packaging_branch):
                    repo.set_branch(options.packaging_branch)
                    try:
                        repo.merge(tag)
                    except GitRepositoryError:
                        raise GbpError, """Merge failed, please resolve."""
                else:
                    repo.create_branch(options.packaging_branch,
                                       rev=options.upstream_branch)
                    if repo.get_branch() == options.packaging_branch:
                        repo.force_head(options.packaging_branch, hard=True)
                if options.postimport:
                    info = {'upstreamversion': version}
                    env = {'GBP_BRANCH': options.packaging_branch}
                    gbpc.Command(options.postimport % info,
                                 extra_env=env,
                                 shell=True)()
            # Update working copy and index if we've possibly updated the
            # checked out branch
            current_branch = repo.get_branch()
            if (current_branch == options.upstream_branch
                    or current_branch == repo.pristine_tar_branch):
                repo.force_head(current_branch, hard=True)
        except (GitRepositoryError, gbpc.CommandExecFailed):
            raise GbpError, "Import of %s failed" % source.path
    except GbpError, err:
        if len(err.__str__()):
            gbp.log.err(err)
        ret = 1
Exemplo n.º 9
0
def main(argv):
    ret = 0

    (options, args) = parse_args(argv)
    if not options:
        return 1

    tmpdir = tempfile.mkdtemp(dir=options.tmp_dir, prefix='import-orig_')

    try:
        source = find_source(options.uscan, args)
        if not source:
            return ret

        try:
            repo = DebianGitRepository('.')
        except GitRepositoryError:
            raise GbpError("%s is not a git repository" %
                           (os.path.abspath('.')))

        # an empty repo has now branches:
        initial_branch = repo.get_branch()
        is_empty = False if initial_branch else True

        if not repo.has_branch(options.upstream_branch) and not is_empty:
            if options.create_missing_branches:
                gbp.log.info("Will create missing branch '%s'" %
                             options.upstream_branch)
            else:
                raise GbpError(no_upstream_branch_msg %
                               options.upstream_branch)

        (pkg_name, version) = detect_name_and_version(repo, source, options)

        (clean, out) = repo.is_clean()
        if not clean and not is_empty:
            gbp.log.err(
                "Repository has uncommitted changes, commit these first: ")
            raise GbpError(out)

        if repo.bare:
            set_bare_repo_options(options)

        # Prepare sources for importing
        pristine_name = pristine_tarball_name(source, pkg_name, version)
        prepare_pristine = pristine_name if options.pristine_tar else None
        unpacked_orig, pristine_orig = prepare_sources(
            source, pkg_name, version, prepare_pristine, options.filters,
            options.filter_pristine_tar, None, tmpdir)

        # Don't mess up our repo with git metadata from an upstream tarball
        try:
            if os.path.isdir(os.path.join(unpacked_orig, '.git/')):
                raise GbpError(
                    "The orig tarball contains .git metadata - giving up.")
        except OSError:
            pass

        try:
            upstream_branch = [options.upstream_branch, 'master'][is_empty]
            filter_msg = ["", " (filtering out %s)" % options.filters
                          ][len(options.filters) > 0]
            gbp.log.info("Importing '%s' to branch '%s'%s..." %
                         (source.path, upstream_branch, filter_msg))
            gbp.log.info("Source package is %s" % pkg_name)
            gbp.log.info("Upstream version is %s" % version)

            import_branch = [options.upstream_branch, None][is_empty]
            msg = upstream_import_commit_msg(options, version)

            if options.vcs_tag:
                parents = [repo.rev_parse("%s^{}" % options.vcs_tag)]
            else:
                parents = None

            commit = repo.commit_dir(
                unpacked_orig,
                msg=msg,
                branch=import_branch,
                other_parents=parents,
                create_missing_branch=options.create_missing_branches)

            if options.pristine_tar and pristine_orig:
                repo.pristine_tar.commit(pristine_orig, upstream_branch)

            tag = repo.version_to_tag(options.upstream_tag, version)
            repo.create_tag(name=tag,
                            msg="Upstream version %s" % version,
                            commit=commit,
                            sign=options.sign_tags,
                            keyid=options.keyid)
            if is_empty:
                repo.create_branch(options.upstream_branch, rev=commit)
                repo.force_head(options.upstream_branch, hard=True)
            elif options.merge:
                gbp.log.info("Merging to '%s'" % options.packaging_branch)
                repo.set_branch(options.packaging_branch)
                try:
                    repo.merge(tag)
                except GitRepositoryError:
                    raise GbpError("Merge failed, please resolve.")
                if options.postimport:
                    epoch = ''
                    if os.access('debian/changelog', os.R_OK):
                        # No need to check the changelog file from the
                        # repository, since we're certain that we're on
                        # the debian-branch
                        cp = ChangeLog(filename='debian/changelog')
                        if cp.has_epoch():
                            epoch = '%s:' % cp.epoch
                    info = {'version': "%s%s-1" % (epoch, version)}
                    env = {'GBP_BRANCH': options.packaging_branch}
                    gbpc.Command(format_msg(options.postimport, info),
                                 extra_env=env,
                                 shell=True)()
            # Update working copy and index if we've possibly updated the
            # checked out branch
            current_branch = repo.get_branch()
            if current_branch in [
                    options.upstream_branch, repo.pristine_tar_branch
            ]:
                repo.force_head(current_branch, hard=True)
            # Create symlink, if requested
            if options.symlink_orig:
                if source.is_tarball():
                    link = os.path.join('..', pristine_name)
                    if not (os.path.exists(link)
                            and os.path.samefile(link, source.path)):
                        gbp.log.info('Creating symlink to %s' % source.path)
                        os.symlink(source.path, link)
                else:
                    gbp.log.warn('Orig source not a tarball, not symlinked')

        except (gbpc.CommandExecFailed, GitRepositoryError) as err:
            msg = err.__str__() if len(err.__str__()) else ''
            raise GbpError("Import of %s failed: %s" % (source.path, msg))
    except (GbpError, GitRepositoryError) as err:
        if len(err.__str__()):
            gbp.log.err(err)
        ret = 1

    if tmpdir:
        cleanup_tmp_tree(tmpdir)

    if not ret:
        gbp.log.info("Successfully imported version %s of %s" %
                     (version, source.path))
    return ret