当前位置: 首页>>代码示例>>Python>>正文


Python DebianGitRepository.set_branch方法代码示例

本文整理汇总了Python中gbp.deb.git.DebianGitRepository.set_branch方法的典型用法代码示例。如果您正苦于以下问题:Python DebianGitRepository.set_branch方法的具体用法?Python DebianGitRepository.set_branch怎么用?Python DebianGitRepository.set_branch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gbp.deb.git.DebianGitRepository的用法示例。


在下文中一共展示了DebianGitRepository.set_branch方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from gbp.deb.git import DebianGitRepository [as 别名]
# 或者: from gbp.deb.git.DebianGitRepository import set_branch [as 别名]
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
开发者ID:pexip,项目名称:os-git-buildpackage,代码行数:99,代码来源:import_orig.py

示例2: main

# 需要导入模块: from gbp.deb.git import DebianGitRepository [as 别名]
# 或者: from gbp.deb.git.DebianGitRepository import set_branch [as 别名]
def main(argv):
    retval = 0
    current = None
    rem_repo = None

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

    gbp.log.setup(options.color, options.verbose, options.color_scheme)

    if len(args) == 2:
        rem_repo = args[1]
        gbp.log.info("Fetching from '%s'" % rem_repo)
    else:
        gbp.log.info("Fetching from default remote for each branch")

    try:
        repo = DebianGitRepository(os.path.curdir)
    except GitRepositoryError:
        gbp.log.err("%s is not a git repository" % (os.path.abspath('.')))
        return 1

    try:
        branches = []
        try:
            current = repo.get_branch()
        except GitRepositoryError:
            # Not being on any branch is o.k. with --ignore-branch
            if options.ignore_branch:
                current = repo.head
                gbp.log.info("Found detached head at '%s'" % current)
            else:
                raise

        for branch in [options.debian_branch, options.upstream_branch]:
            if repo.has_branch(branch):
                branches += [branch]

        if repo.has_pristine_tar_branch() and options.pristine_tar:
            branches += [repo.pristine_tar_branch]

        (ret, out) = repo.is_clean()
        if not ret:
            gbp.log.err("You have uncommitted changes in your source tree:")
            gbp.log.err(out)
            raise GbpError

        repo.fetch(rem_repo, depth=options.depth)
        repo.fetch(rem_repo, depth=options.depth, tags=True)
        for branch in branches:
            if not fast_forward_branch(rem_repo, branch, repo, options):
                retval = 2

        if options.redo_pq:
            repo.set_branch(options.debian_branch)
            Command("gbp-pq")(["drop"])
            Command("gbp-pq")(["import"])

        repo.set_branch(current)
    except KeyboardInterrupt:
        retval = 1
        gbp.log.err("Interrupted. Aborting.")
    except CommandExecFailed:
        retval = 1
    except (GbpError, GitRepositoryError) as err:
        if str(err):
            gbp.log.err(err)
        retval = 1

    return retval
开发者ID:marquiz,项目名称:git-buildpackage-rpm,代码行数:73,代码来源:pull.py

示例3: main

# 需要导入模块: from gbp.deb.git import DebianGitRepository [as 别名]
# 或者: from gbp.deb.git.DebianGitRepository import set_branch [as 别名]
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:
#.........这里部分代码省略.........
开发者ID:dchenbecker,项目名称:git-buildpackage,代码行数:103,代码来源:import_orig.py

示例4: main

# 需要导入模块: from gbp.deb.git import DebianGitRepository [as 别名]
# 或者: from gbp.deb.git.DebianGitRepository import set_branch [as 别名]
def main(argv):
    retval = 0
    current = None

    parser = GbpOptionParser(command=os.path.basename(argv[0]), prefix='',
                             usage='%prog [options] - safely update a repository from remote')
    branch_group = GbpOptionGroup(parser, "branch options", "branch update and layout options")
    parser.add_option_group(branch_group)
    branch_group.add_boolean_config_file_option(option_name = "ignore-branch", dest="ignore_branch")
    branch_group.add_option("--force", action="store_true", dest="force", default=False,
                      help="force a branch update even if it can't be fast forwarded")
    branch_group.add_option("--redo-pq", action="store_true", dest="redo_pq", default=False,
                      help="redo the patch queue branch after a pull. Warning: this drops the old patch-queue branch")
    branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch")
    branch_group.add_config_file_option(option_name="debian-branch", dest="debian_branch")
    branch_group.add_boolean_config_file_option(option_name="pristine-tar", dest="pristine_tar")
    branch_group.add_option("--depth", action="store", dest="depth", default=0,
                            help="git history depth (for deepening shallow clones)")
    parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
                      help="verbose command execution")
    parser.add_config_file_option(option_name="color", dest="color", type='tristate')
    parser.add_config_file_option(option_name="color-scheme",
                                  dest="color_scheme")


    (options, args) = parser.parse_args(argv)
    gbp.log.setup(options.color, options.verbose, options.color_scheme)

    try:
        repo = DebianGitRepository(os.path.curdir)
    except GitRepositoryError:
        gbp.log.err("%s is not a git repository" % (os.path.abspath('.')))
        return 1

    try:
        branches = []
        try:
            current = repo.get_branch()
        except GitRepositoryError:
            # Not being on any branch is o.k. with --git-ignore-branch
            if  options.ignore_branch:
                current = repo.head
                gbp.log.info("Found detached head at '%s'" % current)
            else:
                raise

        for branch in [ options.debian_branch, options.upstream_branch ]:
            if repo.has_branch(branch):
                branches += [ branch ]

        if repo.has_pristine_tar_branch() and options.pristine_tar:
            branches += [ repo.pristine_tar_branch ]

        (ret, out) = repo.is_clean()
        if not ret:
            gbp.log.err("You have uncommitted changes in your source tree:")
            gbp.log.err(out)
            raise GbpError

        repo.fetch(depth=options.depth)
        repo.fetch(depth=options.depth, tags=True)
        for branch in branches:
            if not fast_forward_branch(branch, repo, options):
                retval = 2

        if options.redo_pq:
            repo.set_branch(options.debian_branch)
            Command("gbp-pq")(["drop"])
            Command("gbp-pq")(["import"])

        repo.set_branch(current)
    except CommandExecFailed:
        retval = 1
    except (GbpError, GitRepositoryError) as err:
        if len(err.__str__()):
            gbp.log.err(err)
        retval = 1

    return retval
开发者ID:hzsunzixiang,项目名称:git-buildpackage,代码行数:81,代码来源:pull.py


注:本文中的gbp.deb.git.DebianGitRepository.set_branch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。