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


Python Git.shadowPush方法代码示例

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


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

示例1: __init__

# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import shadowPush [as 别名]

#.........这里部分代码省略.........
            junk, id = interact.printAndPick(ids, lineMode=True, prompt=prompt)
            assert id, 'invalid id: "%s"' % id
        else:
            id = ids[0]

        if not preAction:
            preAction = lambda x: x
        oldRecord = Record.load(id)
        items = oldRecord.elements().items()
        elements  = dict(oldRecord.elements())
        elements  = self.preActionOfEdit(elements)
        newRecord = self.makeLogEntry(**elements)
        newRecord.save(oldRecord=oldRecord)

    def perror(self, msg):
        print(msg, file=sys.stderr)

    def push(self, remote):
        """ Sync with the git server

        Push using shadow-git tools, first shadow-push,
        if rejected because of unfetched update on the
        server side, do a shadow-fetch and shadow-merge,
        then a shadow-push again. In case of conflict
        that can not be automatically resolved, exit,
        after manually solved the conflict, user can
        then try to push again.
        """
        if not self.preActionOfPushAndFetch(remote):
            return False

        for i in range(2):              # try twice at most
            print('pushing...')
            stat, msg = self.git.shadowPush(remote)
            if stat == Git.TOFETCH:
                print('push rejected, need to fetch')
                if self.fetch(remote):
                    continue
            elif stat == Git.UNKNOWN:
                self.perror('unknown error:\n' + msg.decode())
            elif stat == Git.SUCCESS:
                print('push done.')
                return True
            return False


    def preActionOfPushAndFetch(self, remote):
        """ Actions to carry out before push/fetch
        """
        if not self.git.shadowInit():
            return False
        if not self.git.setRemote(remote):
            return False
        return True


    def fetch(self, remote):
        """ Fetch from the git server
        """
        if not self.preActionOfPushAndFetch(remote):
            return False

        print('fetching...')
        stat, msg = self.git.shadowFetch(remote)
        if not stat:
            self.perror('fetch failed:\n' + msg.decode())
开发者ID:iesugrace,项目名称:service-info-manager,代码行数:70,代码来源:log.py


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