代码拉取完成,页面将自动刷新
#!/usr/bin/env python3
# @Date : 2020-05-25
# @Author : Bright Li (brt2@qq.com)
# @Link : https://gitee.com/brt2
from collections import defaultdict
from git import Repo
def git_status(repo_or_dir, type_) -> list:
""" type_:
("untracked", "modified", "added", "deleted", "renamed")
"""
repo_obj = Repo(repo_or_dir) if isinstance(repo_or_dir, str) else repo_or_dir
dict_status = defaultdict(list)
str_status = repo_obj.git.execute(["git", "status", "-s"])
for line in str_status.splitlines():
status, path_file = line.split()
path_file = path_file.strip('"') # 去除对路径的双引号
dict_status[status].append(path_file)
map_type2files = {
"untracked" : "??",
"modified" : "M",
"added" : "A",
"deleted" : "D",
"renamed" : "R",
}
return dict_status[map_type2files[type_]]
if __name__ == "__main__":
if not repo.is_dirty():
print("无文件要提交,干净的工作区")
exit()
list_untracked = repo.untracked_files # 新建项
list_modified = get_status("modified") # 修改项
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。