Initial commit
This commit is contained in:
53
push_files.py
Normal file
53
push_files.py
Normal file
@@ -0,0 +1,53 @@
|
||||
#########################################################
|
||||
## @file : push_files
|
||||
## @desc :
|
||||
## @create : 2025/6/22
|
||||
## @author : Chengan,doubao 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}")
|
||||
Reference in New Issue
Block a user