Beispiel #1
0
def debian_branch_merge(repo, tag, version, options):
    try:
        func = globals()["debian_branch_merge_by_%s" % options.merge_mode]
    except KeyError:
        raise GbpError("%s is not a valid merge mode" % options.merge_mode)
    func(repo, tag, version, options)
    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
        debian_version = "%s%s-1" % (epoch, version)
        info = {'version': debian_version}
        env = {'GBP_BRANCH': options.debian_branch,
               'GBP_TAG': tag,
               'GBP_UPSTREAM_VERSION': version,
               'GBP_DEBIAN_VERSION': debian_version,
               }
        Hook('Postimport',
             format_str(options.postimport, info),
             extra_env=env)()
def debian_branch_merge(repo, tag, version, options):
    try:
        func = globals()["debian_branch_merge_by_%s" % options.merge_mode]
    except KeyError:
        raise GbpError("%s is not a valid merge mode" % options.merge_mode)
    func(repo, tag, version, options)
    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
        debian_version = "%s%s-1" % (epoch, version)
        info = {'version': debian_version}
        env = {
            'GBP_BRANCH': options.debian_branch,
            'GBP_TAG': tag,
            'GBP_UPSTREAM_VERSION': version,
            'GBP_DEBIAN_VERSION': debian_version,
        }
        Hook('Postimport', format_str(options.postimport, info),
             extra_env=env)()
Beispiel #3
0
def debian_branch_merge(repo, tag, version, options):
    try:
        func = globals()["debian_branch_merge_by_%s" % options.merge_mode]
    except KeyError:
        raise GbpError("%s is not a valid merge mode" % options.merge_mode)
    func(repo, tag, version, options)
    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.debian_branch}
        gbpc.Command(format_str(options.postimport, info), extra_env=env, shell=True)()
Beispiel #4
0
def postimport_hook(repo, tag, version, options):
    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
        debian_version = "%s%s-1" % (epoch, version)
        info = {'version': debian_version}
        env = {
            'GBP_BRANCH': options.debian_branch,
            'GBP_TAG': tag,
            'GBP_UPSTREAM_VERSION': version,
            'GBP_DEBIAN_VERSION': debian_version,
        }
        Hook('Postimport', format_str(options.postimport, info),
             extra_env=env)()
Beispiel #5
0
def postimport_hook(repo, tag, version, options):
    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
        debian_version = "%s%s-1" % (epoch, version)
        info = {'version': debian_version}
        env = {'GBP_BRANCH': options.debian_branch,
               'GBP_TAG': tag,
               'GBP_UPSTREAM_VERSION': version,
               'GBP_DEBIAN_VERSION': debian_version,
               }
        Hook('Postimport',
             format_str(options.postimport, info),
             extra_env=env)()
def debian_branch_merge(repo, tag, version, options):
    try:
        func = globals()["debian_branch_merge_by_%s" % options.merge_mode]
    except KeyError:
        raise GbpError("%s is not a valid merge mode" % options.merge_mode)
    func(repo, tag, version, options)
    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.debian_branch}
        gbpc.Command(format_str(options.postimport, info),
                     extra_env=env,
                     shell=True)()
def main(argv):
    ret = 0

    (options, args) = parse_args(argv)
    try:
        sources = find_sources(options, args)
        if not sources:
            return ret
    except GbpError as err:
        if len(err.__str__()):
            gbp.log.err(err)
        return 1 

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

        # an empty repo has no branches:
        initial_branch = repo.get_branch()
        is_empty = False if initial_branch else True
        initial_head = None if is_empty else repo.rev_parse('HEAD', short=40)

        (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)

        # Collect upstream branches, ensuring they're unique and exist if appropriate
        upstream_branches = []
        for source in sources:
            source.detect_name_version_and_component(repo, options)
            upstream_branch = options.upstream_branch
            if source.component:
                upstream_branch += '-' + source.component
            if upstream_branch in upstream_branches:
                raise GbpError("Duplicate component '%s'" % ( component, ))
            if not repo.has_branch(upstream_branch) and not is_empty:
                raise GbpError(no_upstream_branch_msg % upstream_branch)
            upstream_branches.append(upstream_branch)

        # Unpack/repack each source, ensuring that there's no git metadata present
        for source in sources:
            source.unpack_or_repack_as_necessary(options)

        # Import each source into the relevant upstream branch, and create tag
        for source in sources:
            source.import_into_upstream_branch(repo, options)

        # If merge has been requested, merge each upstream branch onto the debian branch
        # TODO: what happens if a merge fails?
        if options.merge:
            for source in sources:
                source.merge_into_debian_branch(repo, options)

        # If the repository is empty and master isn't the selected debian branch, merge onto master, too
        # TODO: what happens if a merge fails?
        if is_empty and options.debian_branch != 'master':
            options.debian_branch = 'master'
            for source in sources:
                source.merge_into_debian_branch(repo, options)

        # TODO: why is this conditional on merge?
        if options.merge and options.postimport:
            epoch = ''
            repo.set_branch(options.debian_branch)
            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, sources[0].version) }
            env = { 'GBP_BRANCH': options.debian_branch }
            gbpc.Command(options.postimport % info, extra_env=env, shell=True)()

        if not is_empty:
            # Restore the working copy to the pre-import state
            current_head = repo.rev_parse('HEAD', short=40)
            if current_head != initial_head:
                repo.force_head(initial_head, hard=True)
    except (gbpc.CommandExecFailed, GbpError) as err:
        if len(err.__str__()):
            gbp.log.err(err)
        ret = 1
    finally:
        for source in sources:
            source.cleanup(options)

    if not ret:
        gbp.log.info("Successfully imported version %s of %s" % (sources[0].version, sources[0].name))
    return ret
Beispiel #8
0
def main(argv):
    ret = 0
    tmpdir = ''
    pristine_orig = None
    linked = False

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

    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:
            raise GbpError(no_upstream_branch_msg % options.upstream_branch)

        (sourcepackage, 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)

        if not source.is_dir():
            tmpdir = tempfile.mkdtemp(dir='../')
            source.unpack(tmpdir, options.filters)
            gbp.log.debug("Unpacked '%s' to '%s'" % (source.path, source.unpacked))

        if source.needs_repack(options):
            gbp.log.debug("Filter pristine-tar: repacking '%s' from '%s'" % (source.path, source.unpacked))
            (source, tmpdir)  = repack_source(source, sourcepackage, version, tmpdir, options.filters)

        (pristine_orig, linked) = prepare_pristine_tar(source.path,
                                                       sourcepackage,
                                                       version)

        # Don't mess up our repo with git metadata from an upstream tarball
        try:
            if os.path.isdir(os.path.join(source.unpacked, '.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" % sourcepackage)
            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(source.unpacked,
                                     msg=msg,
                                     branch=import_branch,
                                     other_parents=parents,
                                     )

            if options.pristine_tar:
                if pristine_orig:
                    repo.pristine_tar.commit(pristine_orig, upstream_branch)
                else:
                    gbp.log.warn("'%s' not an archive, skipping pristine-tar" % source.path)

            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.debian_branch)
                repo.set_branch(options.debian_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.debian_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 in [ options.upstream_branch,
                                   repo.pristine_tar_branch]:
                repo.force_head(current_branch, hard=True)
        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 as err:
        if len(err.__str__()):
            gbp.log.err(err)
        ret = 1

    if pristine_orig and linked and not options.symlink_orig:
        os.unlink(pristine_orig)

    if tmpdir:
        cleanup_tmp_tree(tmpdir)

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