从gitPython返回的FetchInfo对象中的差异,当有东西要提取/拉取时,而没有东西?

问题描述 投票:0回答:1

我正在尝试评估某个代码段之前可能需要提取的远程存储库中是否存在更改。

[我是通过FetchInfo提取fetch()对象到远程原点的:

>>> import git
>>> my_repo = git.Repo.init(my_dir)
>>> repo_fetch = my_repo.remotes.origin.fetch()[0]
>>> repo_fetch
<git.remote.FetchInfo object at 0x10192c650>

但是,我无法在the documentation中清楚地看到何时有东西要取/拉和没有东西之间有什么区别。

[我知道pull()在本地存储库为最新时输出包含strAlready up to date.变量,但我不想提取,我只想获取。

当我知道远程仓库中没有任何更改时,我会看到其属性上的一些差异:

>>> repo_fetch.ref 
<git.RemoteReference "refs/remotes/origin/master">
>>> repo_fetch.flags
4
>>> repo_fetch.note
''
>>> repo_fetch.old_commit
>>> repo_fetch.remote_ref_path
'master    '

以及何时发生are更改:

>>> repo_fetch.ref 
<git.RemoteReference "refs/remotes/origin/master">
>>> repo_fetch.flags
64
>>> repo_fetch.note
''
>>> repo_fetch.old_commit
<git.Commit "[some_string]">
>>> repo_fetch.remote_ref_path
' '
python python-3.x gitpython
1个回答
0
投票

键是flags属性,在the documentation中不是很直观或清楚地显示:

ERROR = 128
FAST_FORWARD = 64
FORCED_UPDATE = 32
HEAD_UPTODATE = 4
NEW_HEAD = 2
NEW_TAG = 1
REJECTED = 16
TAG_UPDATE = 8

出于问题的目的,只要标志不等于4HEAD_UPTODATE),与本地和远程存储库相同时,我需要采取不同的操作。

© www.soinside.com 2019 - 2024. All rights reserved.