本文整理汇总了Python中pygit2.Repository.merge_base方法的典型用法代码示例。如果您正苦于以下问题:Python Repository.merge_base方法的具体用法?Python Repository.merge_base怎么用?Python Repository.merge_base使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygit2.Repository
的用法示例。
在下文中一共展示了Repository.merge_base方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _fast_forward
# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import merge_base [as 别名]
def _fast_forward(self, local_path, merge_target, branch):
# fast-forward all the branches.
# pygit2 repo
repo = Repository(discover_repository(local_path))
# convert merge_target from hex into oid.
fetch_head = repo.revparse_single(merge_target)
# try to resolve a common anscestor between fetched and local
try:
head = repo.revparse_single(branch)
except KeyError:
# Doesn't exist. Create and done.
repo.create_reference(branch, fetch_head.oid)
return True, 'Created new branch: %s' % branch
if head.oid == fetch_head.oid:
return True, 'Source and target are identical.'
# raises KeyError if no merge bases found.
common_oid = repo.merge_base(head.oid, fetch_head.oid)
# Three different outcomes between the remaining cases.
if common_oid.hex not in (head.oid.hex, fetch_head.oid.hex):
# common ancestor is beyond both of these, not going to
# attempt a merge here and will assume this:
return False, 'Branch will diverge.'
elif common_oid.hex == fetch_head.oid.hex:
# Remote is also the common ancestor, so nothing to do.
return True, 'No new changes found.'
# This case remains: common_oid.hex == head.oid.hex, meaning
# this local repository is the ancestor of further changes
# fetched from the remote - remote newer, so fast-forward.
ref = repo.lookup_reference(branch)
ref.delete()
repo.create_reference(branch, fetch_head.oid)
return True, 'Fast-forwarded branch: %s' % branch