-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_git.py
More file actions
35 lines (28 loc) · 1.27 KB
/
Copy pathinit_git.py
File metadata and controls
35 lines (28 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
import subprocess
import os
import sys
os.chdir(os.path.dirname(os.path.abspath(__file__)))
try:
# 初始化git仓库
result = subprocess.run(['git', 'init'], capture_output=True, text=True, check=True)
print(result.stdout)
# 添加所有文件
result = subprocess.run(['git', 'add', '.'], capture_output=True, text=True, check=True)
# 创建初始提交
result = subprocess.run(['git', 'commit', '-m', 'Initial commit: 打卡与工时统计系统\n\n- 添加前端界面(现代化设计)\n- 添加后端服务器\n- 添加用户认证功能\n- 添加打卡记录和统计功能\n- 添加图表可视化'], capture_output=True, text=True)
if result.returncode == 0:
print("Git repository initialized and initial commit created!")
print(result.stdout)
else:
print("Warning:", result.stderr)
if "nothing to commit" in result.stderr.lower():
print("Repository initialized but nothing to commit (files may already be committed)")
else:
sys.exit(1)
except FileNotFoundError:
print("Error: git command not found. Please install git first.")
sys.exit(1)
except subprocess.CalledProcessError as e:
print(f"Error: {e.stderr}")
sys.exit(1)