Initial commit

This commit is contained in:
douboer
2025-09-05 17:10:11 +08:00
parent 80a1bee0e0
commit 67f33b2d80
138 changed files with 24432 additions and 0 deletions

53
push_files.py Normal file
View File

@@ -0,0 +1,53 @@
#########################################################
## @file : push_files
## @desc :
## @create : 2025/6/22
## @author : Chengandoubao AI
## @email : douboer@gmail.com
#########################################################
from logger_utils import CommonLogger
import subprocess
def get_uncommitted_changes(log_file=None):
"""获取所有未提交的修改,并区分新增、删除、修改状态"""
logger = CommonLogger(log_file).get_logger()
changes = {
'added': [],
'deleted': [],
'modified': []
}
try:
# 获取工作区和暂存区的完整状态
status_output = subprocess.check_output(
["git", "status", "--porcelain"],
text=True,
stderr=subprocess.DEVNULL
).splitlines()
for line in status_output:
status_code = line[:2].strip()
file_path = line[3:].strip()
if status_code == '??':
changes['added'].append(file_path)
elif status_code == 'D':
changes['deleted'].append(file_path)
elif status_code in ('M', 'AM', 'MD'):
changes['modified'].append(file_path)
except subprocess.CalledProcessError:
logger.exception("获取未提交修改时发生错误")
logger.info(f"未提交修改: {changes}")
return changes
# 使用示例
changes = get_uncommitted_changes(log_file='logs/push_files.log')
for status, files in changes.items():
if files:
print(f"\n{status.upper()}:")
for file in files:
print(f" - {file}")