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

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

    if len(args) != 2 or args[0] not in ['commit']:
        gbp.log.err("No action given")
        return 1
    else:
        tarball = args[1]

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

        debsource = DebianSource('.')
        # FIXME: this should be a single call
        sources = [DebianUpstreamSource(tarball)]
        sources += get_component_tarballs(debsource.sourcepkg,
                                          debsource.upstream_version,
                                          sources[0].path, options.components)
        upstream_tag = repo.version_to_tag(options.upstream_tag,
                                           debsource.upstream_version)
        repo.create_pristine_tar_commits(upstream_tag, sources)
        ret = 0
    except (GitRepositoryError, GbpError, CommandExecFailed) as err:
        if str(err):
            gbp.log.err(err)
    except KeyboardInterrupt:
        gbp.log.err("Interrupted. Aborting.")

    if not ret:
        comp_msg = (' with additional tarballs for %s' %
                    ", ".join([os.path.basename(t.path)
                               for t in sources[1:]])) if sources[1:] else ''
        gbp.log.info(
            "Successfully committed pristine-tar data for version %s of %s%s" %
            (debsource.version, tarball, comp_msg))
    return ret
Ejemplo n.º 2
0
def main(argv):
    ret = 1
    repo = None

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

    if len(args) != 2 or args[0] not in ['commit']:
        gbp.log.err("No action given")
        return 1
    else:
        tarball = args[1]

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

        source = DebianSource('.')
        component_tarballs = get_component_tarballs(source.sourcepkg,
                                                    source.upstream_version,
                                                    tarball,
                                                    options.components)
        upstream_tag = repo.version_to_tag(options.upstream_tag,
                                           source.upstream_version)
        repo.create_pristine_tar_commits(upstream_tag,
                                         tarball,
                                         component_tarballs)
        ret = 0
    except (GitRepositoryError, GbpError, CommandExecFailed) as err:
        if str(err):
            gbp.log.err(err)
    except KeyboardInterrupt:
        gbp.log.err("Interrupted. Aborting.")

    if not ret:
        comp_msg = (' with additional tarballs for %s'
                    % ", ".join([os.path.basename(t[1]) for t in component_tarballs])) if component_tarballs else ''
        gbp.log.info("Successfully committed pristine-tar data for version %s of %s%s" % (source.upstream_version,
                                                                                          tarball,
                                                                                          comp_msg))
    return ret
Ejemplo n.º 3
0
def main(argv):
    ret = 0
    repo = None

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

    if len(args) != 2 or args[0] not in ['commit']:
        gbp.log.err("No action given")
        return 1
    else:
        tarball = args[1]

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

        source = DebianSource('.')
        component_tarballs = get_component_tarballs(source.sourcepkg,
                                                    source.upstream_version,
                                                    tarball,
                                                    options.components)
        upstream_tag = repo.version_to_tag(options.upstream_tag,
                                           source.upstream_version)
        repo.create_pristine_tar_commits(upstream_tag, tarball,
                                         component_tarballs)
    except (GitRepositoryError, GbpError, CommandExecFailed) as err:
        if str(err):
            gbp.log.err(err)
        ret = 1

    if not ret:
        comp_msg = (' with additional tarballs for %s' % ", ".join(
            [os.path.basename(t[1])
             for t in component_tarballs])) if component_tarballs else ''
        gbp.log.info(
            "Successfully committed pristine-tar data for version %s of %s%s" %
            (source.upstream_version, tarball, comp_msg))
    return ret
Ejemplo n.º 4
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 = ImportOrigDebianGitRepository('.')
        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:
            source = download_orig(args[0])
        else:
            source = find_source(options.uscan, args)
        if not source:
            return ExitCodes.failed

        # The main tarball
        (sourcepackage,
         version) = detect_name_and_version(repo, source, options)
        # Additional tarballs we expect to exist
        component_tarballs = get_component_tarballs(sourcepackage, version,
                                                    source.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)

        source, tmpdir = unpack_tarballs(sourcepackage, source, version,
                                         component_tarballs, options)

        (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:
            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..." %
                         (source.path, import_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)

            commit = repo.commit_dir(
                source.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_pristinetar_commits(import_branch,
                                                    pristine_orig,
                                                    component_tarballs)
                else:
                    gbp.log.warn("'%s' not an archive, skipping pristine-tar" %
                                 source.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)
            elif options.merge:
                repo.rrr_branch(options.debian_branch)
                debian_branch_merge(repo, tag, version, options)
                postimport_hook(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)
        except (gbpc.CommandExecFailed, GitRepositoryError) as err:
            msg = str(err) or 'Unknown error, please report a bug'
            raise GbpError("Import of %s failed: %s" % (source.path, msg))
    except GbpError as err:
        if str(err):
            gbp.log.err(err)
        ret = 1
        if repo and repo.has_rollbacks() and options.rollback:
            gbp.log.err("Error detected, Will roll back changes.")
            try:
                repo.rollback()
                # Make sure the very last line as an error message
                gbp.log.err("Rolled back changes after import error.")
            except Exception as e:
                gbp.log.err("%s" % e)
                gbp.log.err("Clean up manually and please report a bug: %s" %
                            repo.rollback_errors)

    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
Ejemplo n.º 5
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.º 6
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:
            sources = [download_orig(args[0])]
        else:
            sources = [find_upstream(options.uscan, args, options.version)]
            if not sources[0]:
                return ExitCodes.uscan_up_to_date

        # The main tarball
        (name, version) = detect_name_and_version(repo, sources[0], options)
        # Additional tarballs we expect to exist
        sources += get_component_tarballs(name, version, sources[0].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)

        sources, tmpdir = unpack_tarballs(repo, name, sources, version, options)

        if options.verbose:
            for source in sources:
                gbp.log.info(source)

        (pristine_orig, linked) = prepare_pristine_tar(sources[0].path,
                                                       name,
                                                       version)

        # Don't mess up our repo with git metadata from an upstream tarball
        try:
            if os.path.isdir(os.path.join(sources[0].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..." % (sources[0].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(sources[0].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')
                    for source in sources:
                        # Enforce signature file exists with --upstream-signatures=on
                        if options.upstream_signatures.is_on() and not source.signaturefile:
                            raise GbpError("%s does not have a signature file" % source.path)
                        elif options.upstream_signatures.is_off():
                            source.signaturefile = None
                    # For all practical purposes we're interested in pristine_orig's path
                    if pristine_orig != sources[0].path:
                        sources[0]._path = pristine_orig
                    repo.create_pristine_tar_commits(import_branch, sources)
                else:
                    gbp.log.warn("'%s' not an archive, skipping pristine-tar" % sources[0].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" % (sources[0].path, msg))
        except KeyboardInterrupt:
            raise GbpError("Import of %s failed: aborted by user" % (sources[0].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, sources[0].path))
    return ret