Ejemplo n.º 1
0
def main(argv):
    ret = 0
    tmpdir = None
    pristine_orig = None
    linked = False
    repo = None

    (options, args) = parse_args(argv)
    if not options:
        return ExitCodes.parse_error

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

        is_empty = repo.is_empty()

        if not repo.has_branch(options.upstream_branch) and not is_empty:
            raise GbpError(no_upstream_branch_msg % options.upstream_branch)

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

        # Download the main tarball
        if options.download:
            upstream = download_orig(args[0])
        else:
            upstream = find_upstream(options.uscan, args, options.version)
            if not upstream:
                return ExitCodes.uscan_up_to_date

        # The main tarball
        (name, version) = detect_name_and_version(repo, upstream, options)
        # Additional tarballs we expect to exist
        component_tarballs = get_component_tarballs(name,
                                                    version,
                                                    upstream.path,
                                                    options.components)

        tag = repo.version_to_tag(options.upstream_tag, version)
        if repo.has_tag(tag):
            raise GbpError("Upstream tag '%s' already exists" % tag)

        if repo.bare:
            set_bare_repo_options(options)

        upstream, tmpdir = unpack_tarballs(name, upstream, version, component_tarballs, options)
        try:
            postunpack_hook(repo, tmpdir, options)
        except gbpc.CommandExecFailed:
            raise GbpError()  # The hook already printed an error message

        (pristine_orig, linked) = prepare_pristine_tar(upstream.path,
                                                       name,
                                                       version)

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

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

            msg = upstream_import_commit_msg(options, version)

            commit = repo.commit_dir(upstream.unpacked,
                                     msg=msg,
                                     branch=import_branch,
                                     other_parents=repo.vcs_tag_parent(options.vcs_tag, version),
                                     create_missing_branch=is_empty,
                                     )

            if options.pristine_tar:
                if pristine_orig:
                    repo.rrr_branch('pristine-tar')
                    repo.create_pristine_tar_commits(import_branch,
                                                     pristine_orig,
                                                     component_tarballs)
                else:
                    gbp.log.warn("'%s' not an archive, skipping pristine-tar" % upstream.path)

            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(branch=options.debian_branch, rev=commit)
                repo.force_head(options.debian_branch, hard=True)
                # In an empty repo avoid master branch defaulted to by
                # git and check out debian branch instead.
                if not repo.bare:
                    cur = repo.branch
                    if cur != options.debian_branch:
                        repo.set_branch(options.debian_branch)
                        repo.delete_branch(cur)
            elif options.merge:
                repo.rrr_branch(options.debian_branch)
                debian_branch_merge(repo, tag, version, options)

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

            postimport_hook(repo, tag, version, options)
        except (gbpc.CommandExecFailed, GitRepositoryError) as err:
            msg = str(err) or 'Unknown error, please report a bug'
            raise GbpError("Import of %s failed: %s" % (upstream.path, msg))
        except KeyboardInterrupt:
            raise GbpError("Import of %s failed: aborted by user" % (upstream.path))
    except GbpError as err:
        if str(err):
            gbp.log.err(err)
        ret = 1
        rollback(repo, options)

    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, upstream.path))
    return ret
Ejemplo n.º 2
0
def main(argv):
    ret = 0
    repo = None

    (options, args) = parse_args(argv)
    if not options:
        return ExitCodes.parse_error

    # TODO: honor --filter option
    # TODO: add --filter-with-copyright which takes d/copyright into account
    # TODO: handle automatic versions based on timestamp + sha1
    # TODO: handle updating of upstream branch from remote
    try:
        try:
            repo = RollbackDebianGitRepository('.')
        except GitRepositoryError:
            raise GbpError("%s is not a git repository" %
                           (os.path.abspath('.')))

        commit, version = get_commit_and_version_to_merge(repo, options)

        is_empty = repo.is_empty()

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

        try:
            tag = repo.version_to_tag(options.upstream_tag, version)
            if not repo.has_tag(tag):
                gbp.log.info(
                    "Upstream tag '%s' not found. Creating it for you." % tag)
                repo.create_tag(name=tag,
                                msg="Upstream version %s" % version,
                                commit="%s^0" % commit,
                                sign=options.sign_tags,
                                keyid=options.keyid)

            if is_empty:
                repo.create_branch(branch=options.debian_branch, rev=commit)
                repo.force_head(options.debian_branch, hard=True)
                # In an empty repo avoid master branch defaulted to by
                # git and check out debian branch instead.
                if not repo.bare:
                    cur = repo.branch
                    if cur != options.debian_branch:
                        repo.set_branch(options.debian_branch)
                        repo.delete_branch(cur)
            else:
                repo.rrr_branch(options.debian_branch)
                debian_branch_merge(repo, tag, version, options)

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

            postimport_hook(repo, tag, version, options)
        except (gbpc.CommandExecFailed, GitRepositoryError) as err:
            msg = str(err) or 'Unknown error, please report a bug'
            raise GbpError("Import of %s failed: %s" % (commit, msg))
        except KeyboardInterrupt:
            raise GbpError("Import of %s failed: aborted by user" %
                           (options.git_ref))
    except GbpError as err:
        if str(err):
            gbp.log.err(err)
        ret = 1
        rollback(repo, options)

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