zen-gitsync 2.9.8 → 2.9.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -148
- package/package.json +1 -1
- package/src/ui/public/assets/{index-C-ZzwQYX.css → index-CzUoE1WP.css} +1 -1
- package/src/ui/public/assets/index-GE6lIBHK.js +79 -0
- package/src/ui/public/index.html +2 -2
- package/src/ui/server/index.js +143 -5311
- package/src/ui/server/index_pro.js +5483 -0
- package/src/ui/server/middleware/requestLogger.js +37 -0
- package/src/ui/server/routes/branchStatus.js +168 -0
- package/src/ui/server/routes/config.js +586 -0
- package/src/ui/server/routes/exec.js +247 -0
- package/src/ui/server/routes/fileOpen.js +173 -0
- package/src/ui/server/routes/fs.js +443 -0
- package/src/ui/server/routes/git/diff.js +206 -0
- package/src/ui/server/routes/git/diffUtils.js +114 -0
- package/src/ui/server/routes/git/stash.js +481 -0
- package/src/ui/server/routes/git/tags.js +158 -0
- package/src/ui/server/routes/git.js +176 -0
- package/src/ui/server/routes/gitOps.js +974 -0
- package/src/ui/server/routes/npm.js +981 -0
- package/src/ui/server/routes/process.js +68 -0
- package/src/ui/server/routes/status.js +24 -0
- package/src/ui/server/routes/terminal.js +244 -0
- package/src/ui/server/socket/registerUiSocketHandlers.js +212 -0
- package/src/ui/server/utils/createSavePortToFile.js +32 -0
- package/src/ui/server/utils/startServerOnAvailablePort.js +87 -0
- package/src/ui/public/assets/index-DXmNo3gw.js +0 -79
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
export function registerGitTagRoutes({ app, execGitCommand, clearCommandHistory }) {
|
|
2
|
+
// ============ Git Tag 相关接口 ============
|
|
3
|
+
|
|
4
|
+
// 创建标签
|
|
5
|
+
app.post('/api/create-tag', async (req, res) => {
|
|
6
|
+
try {
|
|
7
|
+
const { tagName, message, type, commit } = req.body;
|
|
8
|
+
|
|
9
|
+
if (!tagName) {
|
|
10
|
+
return res.status(400).json({ success: false, error: '缺少标签名称' });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let command = 'git tag';
|
|
14
|
+
|
|
15
|
+
if (type === 'annotated') {
|
|
16
|
+
// 附注标签
|
|
17
|
+
if (!message) {
|
|
18
|
+
return res.status(400).json({ success: false, error: '附注标签需要提供说明信息' });
|
|
19
|
+
}
|
|
20
|
+
command += ` -a "${tagName}" -m "${message}"`;
|
|
21
|
+
} else {
|
|
22
|
+
// 轻量标签
|
|
23
|
+
command += ` "${tagName}"`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 如果指定了commit,添加到命令中
|
|
27
|
+
if (commit && commit.trim()) {
|
|
28
|
+
command += ` ${commit.trim()}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const { stdout } = await execGitCommand(command);
|
|
32
|
+
|
|
33
|
+
res.json({
|
|
34
|
+
success: true,
|
|
35
|
+
message: '标签创建成功',
|
|
36
|
+
output: stdout
|
|
37
|
+
});
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error('创建标签失败:', error);
|
|
40
|
+
res.status(500).json({ success: false, error: error.message });
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// 获取标签列表
|
|
45
|
+
app.get('/api/list-tags', async (req, res) => {
|
|
46
|
+
try {
|
|
47
|
+
// 使用 git tag -n --format 获取详细信息
|
|
48
|
+
const { stdout } = await execGitCommand(
|
|
49
|
+
'git tag -n --format="%(refname:short)|%(objectname:short)|%(creatordate:iso8601)|%(subject)"'
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (!stdout.trim()) {
|
|
53
|
+
return res.json({ success: true, tags: [] });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const tags = stdout.trim().split('\n').map(line => {
|
|
57
|
+
const [name, commit, date, message] = line.split('|');
|
|
58
|
+
return {
|
|
59
|
+
name: name || '',
|
|
60
|
+
commit: commit || '',
|
|
61
|
+
date: date || '',
|
|
62
|
+
message: message || '',
|
|
63
|
+
type: 'lightweight' // 默认为轻量标签
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// 检测哪些是附注标签
|
|
68
|
+
for (const tag of tags) {
|
|
69
|
+
try {
|
|
70
|
+
const { stdout: typeCheck } = await execGitCommand(
|
|
71
|
+
`git cat-file -t ${tag.name}`,
|
|
72
|
+
{ log: false }
|
|
73
|
+
);
|
|
74
|
+
if (typeCheck.trim() === 'tag') {
|
|
75
|
+
tag.type = 'annotated';
|
|
76
|
+
}
|
|
77
|
+
} catch (error) {
|
|
78
|
+
// 忽略错误,保持默认值
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
res.json({ success: true, tags });
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error('获取标签列表失败:', error);
|
|
85
|
+
res.status(500).json({ success: false, error: error.message });
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// 推送标签到远程
|
|
90
|
+
app.post('/api/push-tag', async (req, res) => {
|
|
91
|
+
try {
|
|
92
|
+
const { tagName } = req.body;
|
|
93
|
+
|
|
94
|
+
if (!tagName) {
|
|
95
|
+
return res.status(400).json({ success: false, error: '缺少标签名称' });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const { stdout } = await execGitCommand(`git push origin ${tagName}`);
|
|
99
|
+
|
|
100
|
+
res.json({
|
|
101
|
+
success: true,
|
|
102
|
+
message: '标签推送成功',
|
|
103
|
+
output: stdout
|
|
104
|
+
});
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.error('推送标签失败:', error);
|
|
107
|
+
res.status(500).json({ success: false, error: error.message });
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// 推送所有标签到远程
|
|
112
|
+
app.post('/api/push-all-tags', async (req, res) => {
|
|
113
|
+
try {
|
|
114
|
+
const { stdout } = await execGitCommand('git push origin --tags');
|
|
115
|
+
|
|
116
|
+
res.json({
|
|
117
|
+
success: true,
|
|
118
|
+
message: '所有标签推送成功',
|
|
119
|
+
output: stdout
|
|
120
|
+
});
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.error('推送所有标签失败:', error);
|
|
123
|
+
res.status(500).json({ success: false, error: error.message });
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// 删除标签
|
|
128
|
+
app.post('/api/delete-tag', async (req, res) => {
|
|
129
|
+
try {
|
|
130
|
+
const { tagName } = req.body;
|
|
131
|
+
|
|
132
|
+
if (!tagName) {
|
|
133
|
+
return res.status(400).json({ success: false, error: '缺少标签名称' });
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const { stdout } = await execGitCommand(`git tag -d ${tagName}`);
|
|
137
|
+
|
|
138
|
+
res.json({
|
|
139
|
+
success: true,
|
|
140
|
+
message: '标签删除成功',
|
|
141
|
+
output: stdout
|
|
142
|
+
});
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.error('删除标签失败:', error);
|
|
145
|
+
res.status(500).json({ success: false, error: error.message });
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// 添加命令历史的清空API
|
|
150
|
+
app.post('/api/clear-command-history', async (req, res) => {
|
|
151
|
+
try {
|
|
152
|
+
const result = clearCommandHistory();
|
|
153
|
+
res.json({ success: result });
|
|
154
|
+
} catch (error) {
|
|
155
|
+
res.status(500).json({ success: false, error: error.message });
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
|
|
3
|
+
export function registerGitRoutes({
|
|
4
|
+
app,
|
|
5
|
+
execGitCommand,
|
|
6
|
+
clearBranchCache
|
|
7
|
+
}) {
|
|
8
|
+
// 获取所有分支
|
|
9
|
+
app.get('/api/branches', async (req, res) => {
|
|
10
|
+
try {
|
|
11
|
+
// 获取本地分支 - 使用简单的git branch命令
|
|
12
|
+
const { stdout: localBranches } = await execGitCommand('git branch');
|
|
13
|
+
|
|
14
|
+
// 获取远程分支
|
|
15
|
+
const { stdout: remoteBranches } = await execGitCommand('git branch -r');
|
|
16
|
+
|
|
17
|
+
// 处理本地分支 - 正确解析git branch的标准输出格式
|
|
18
|
+
const localBranchList = localBranches.split('\n')
|
|
19
|
+
.filter(Boolean)
|
|
20
|
+
.map(b => b.trim())
|
|
21
|
+
.map(b => b.startsWith('* ') ? b.substring(2) : b); // 移除星号并保留分支名
|
|
22
|
+
|
|
23
|
+
// 处理远程分支,保留完整的远程分支名称
|
|
24
|
+
const remoteBranchList = remoteBranches.split('\n')
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
.map(b => b.trim())
|
|
27
|
+
.filter(b => b !== 'origin' && !b.includes('HEAD')); // 过滤掉单纯的origin和HEAD引用
|
|
28
|
+
|
|
29
|
+
// 合并分支列表
|
|
30
|
+
const allBranches = [
|
|
31
|
+
...localBranchList,
|
|
32
|
+
...remoteBranchList
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
res.json({ branches: allBranches });
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error('获取分支列表失败:', error);
|
|
38
|
+
res.status(500).json({ error: error.message });
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// 创建新分支
|
|
43
|
+
app.post('/api/create-branch', express.json(), async (req, res) => {
|
|
44
|
+
try {
|
|
45
|
+
const { newBranchName, baseBranch } = req.body;
|
|
46
|
+
|
|
47
|
+
if (!newBranchName) {
|
|
48
|
+
return res.status(400).json({ success: false, error: '分支名称不能为空' });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 构建创建分支的命令
|
|
52
|
+
let command = `git branch ${newBranchName}`;
|
|
53
|
+
|
|
54
|
+
// 如果指定了基础分支,则基于该分支创建
|
|
55
|
+
if (baseBranch) {
|
|
56
|
+
command = `git branch ${newBranchName} ${baseBranch}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 执行创建分支命令
|
|
60
|
+
await execGitCommand(command);
|
|
61
|
+
|
|
62
|
+
// 切换到新创建的分支
|
|
63
|
+
await execGitCommand(`git checkout ${newBranchName}`);
|
|
64
|
+
|
|
65
|
+
// 清除分支缓存,因为分支已切换
|
|
66
|
+
clearBranchCache();
|
|
67
|
+
|
|
68
|
+
res.json({ success: true, branch: newBranchName });
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error('创建分支失败:', error);
|
|
71
|
+
res.status(500).json({ success: false, error: error.message });
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// 切换分支
|
|
76
|
+
app.post('/api/checkout', async (req, res) => {
|
|
77
|
+
try {
|
|
78
|
+
const { branch } = req.body;
|
|
79
|
+
if (!branch) {
|
|
80
|
+
return res.status(400).json({ success: false, error: '分支名称不能为空' });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 执行分支切换
|
|
84
|
+
await execGitCommand(`git checkout ${branch}`);
|
|
85
|
+
|
|
86
|
+
// 清除分支缓存,因为分支已切换
|
|
87
|
+
clearBranchCache();
|
|
88
|
+
|
|
89
|
+
res.json({ success: true });
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error('切换分支失败:', error);
|
|
92
|
+
res.status(500).json({ success: false, error: error.message });
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// 合并分支
|
|
97
|
+
app.post('/api/merge', async (req, res) => {
|
|
98
|
+
try {
|
|
99
|
+
const { branch, noCommit, noFf, squash, message } = req.body;
|
|
100
|
+
|
|
101
|
+
if (!branch) {
|
|
102
|
+
return res.status(400).json({ success: false, error: '分支名称不能为空' });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 构建Git合并命令 - 直接使用传入的分支名(可能包含origin/前缀)
|
|
106
|
+
let command = `git merge ${branch}`;
|
|
107
|
+
|
|
108
|
+
// 添加可选参数
|
|
109
|
+
if (noCommit) {
|
|
110
|
+
command += ' --no-commit';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (noFf) {
|
|
114
|
+
command += ' --no-ff';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (squash) {
|
|
118
|
+
command += ' --squash';
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (message) {
|
|
122
|
+
command += ` -m "${message}"`;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
// 执行合并命令
|
|
127
|
+
const { stdout } = await execGitCommand(command);
|
|
128
|
+
|
|
129
|
+
res.json({
|
|
130
|
+
success: true,
|
|
131
|
+
message: '分支合并成功',
|
|
132
|
+
output: stdout
|
|
133
|
+
});
|
|
134
|
+
} catch (error) {
|
|
135
|
+
// 检查是否有合并冲突
|
|
136
|
+
const errorMsg = error.message || '';
|
|
137
|
+
const hasConflicts = errorMsg.includes('CONFLICT') ||
|
|
138
|
+
errorMsg.includes('Automatic merge failed');
|
|
139
|
+
|
|
140
|
+
if (hasConflicts) {
|
|
141
|
+
res.status(409).json({
|
|
142
|
+
success: false,
|
|
143
|
+
hasConflicts: true,
|
|
144
|
+
error: '合并过程中发生冲突,需要手动解决',
|
|
145
|
+
details: errorMsg
|
|
146
|
+
});
|
|
147
|
+
} else {
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
console.error('合并分支失败:', error);
|
|
153
|
+
res.status(500).json({
|
|
154
|
+
success: false,
|
|
155
|
+
error: `合并分支失败: ${error.message}`
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// 获取Git用户配置信息
|
|
161
|
+
app.get('/api/user-info', async (req, res) => {
|
|
162
|
+
try {
|
|
163
|
+
// 获取全局用户名
|
|
164
|
+
const { stdout: userName } = await execGitCommand('git config --global user.name');
|
|
165
|
+
// 获取全局用户邮箱
|
|
166
|
+
const { stdout: userEmail } = await execGitCommand('git config --global user.email');
|
|
167
|
+
|
|
168
|
+
res.json({
|
|
169
|
+
name: userName.trim(),
|
|
170
|
+
email: userEmail.trim()
|
|
171
|
+
});
|
|
172
|
+
} catch (error) {
|
|
173
|
+
res.status(500).json({ error: error.message });
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|