簡體   English   中英

如何檢查 git.Repo().remotes.origin.pull() 是否真的用新的代碼/文件更新了目錄

[英]How to check if git.Repo().remotes.origin.pull() actually updated the directory with new code/files

import git # gitpython module
def update_repo(repo)
    repo = git.Repo(repo)
    ret = repo.remotes.origin.pull()
    print(ret)
    # some code I want to execute if and only if repo.remotes.origin.pull() changed something within the directory
update_repo('/Path/To/Repo/.git')
>>> [<git.remote.FetchInfo object at 0x7f83521b21b0>]

我嘗試打印repo.remotes.origin.pull()返回的內容並得到git.remote.FetchInfo object 的列表。 我對其進行了搜索,並在他們的文檔git.remote.FetchInfo中找到了對此的參考,但我完全不明白其中是否有任何內容可以幫助我實現我想要實現的目標。

在一遍又一遍地閱讀文檔時,我終於意識到git.remote.FetchInfo.flags給了我一個 integer 取決於拉動的動作

經過一番測試,我發現如果flag == 4則沒有文件,而flag == 64表示有變化

def update_repo(repo)
    repo = git.Repo(repo)
    ret = repo.remotes.origin.pull()
    print(ret)
    if ret[0].flags == 4:
        return
    # rest of the code I wanted to execute only if a change took place

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM