拉/取时如何检索文件列表?假设上游设置并拉动上游。
repo = git.Repo('/repo_location/')
result = repo.git.pull()
根据API参考,它表示返回是可迭代列表。但是我不能那样用它。
如果我print(result)
它会正确打印到stdout,但不会在我迭代时打印。
答案 0 :(得分:0)
我发现没有gitpython方法来执行此操作,因此我执行了git diff-tree
:
repo = Repo(repo_dir)
# first get the remote information to get all changed files, than pull the repository
# has to be done in this order, because after pulling the local repository does not differ from the remote
repo.remote().fetch()
repo.remote().pull()
# the "-t"-option also lists all changed directories
diff_tree = repo.git.execute('git diff-tree --name-status -t master origin/master')
for line in diff_tree.splitlines():
change_status, file_path = line.split('\t')