zen-gitsync 2.1.2 → 2.1.6
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/LICENSE +21 -21
- package/README.md +96 -96
- package/index.js +2 -2
- package/package.json +69 -66
- package/src/config.js +51 -51
- package/src/gitCommit.js +261 -261
- package/src/ui/public/assets/index-8gQo1ABk.js +20 -0
- package/src/ui/public/assets/index-IcGOG2Ja.css +1 -0
- package/src/ui/public/assets/{vendor-Dy1zosHw.js → vendor-Bm8yNvvz.js} +1 -1
- package/src/ui/public/favicon.svg +26 -26
- package/src/ui/public/index.html +3 -3
- package/src/ui/public/logo.svg +26 -26
- package/src/ui/server/index.js +141 -51
- package/src/ui/client/README.md +0 -5
- package/src/ui/client/auto-imports.d.ts +0 -10
- package/src/ui/client/components.d.ts +0 -33
- package/src/ui/client/index.html +0 -13
- package/src/ui/client/package.json +0 -28
- package/src/ui/client/public/favicon.svg +0 -27
- package/src/ui/client/public/logo.svg +0 -27
- package/src/ui/client/public/vite.svg +0 -1
- package/src/ui/client/src/App.vue +0 -984
- package/src/ui/client/src/assets/logo.svg +0 -27
- package/src/ui/client/src/components/CommitForm.vue +0 -2167
- package/src/ui/client/src/components/GitStatus.vue +0 -1621
- package/src/ui/client/src/components/LogList.vue +0 -1937
- package/src/ui/client/src/main.ts +0 -7
- package/src/ui/client/src/stores/configStore.ts +0 -212
- package/src/ui/client/src/stores/gitLogStore.ts +0 -790
- package/src/ui/client/src/stores/gitStore.ts +0 -443
- package/src/ui/client/src/vite-env.d.ts +0 -1
- package/src/ui/client/stats.html +0 -4949
- package/src/ui/client/tsconfig.app.json +0 -14
- package/src/ui/client/tsconfig.json +0 -7
- package/src/ui/client/tsconfig.node.json +0 -24
- package/src/ui/client/vite.config.ts +0 -50
- package/src/ui/public/assets/index-C0FIVyIy.css +0 -1
- package/src/ui/public/assets/index-FuuBZ-mS.js +0 -20
|
@@ -1,443 +0,0 @@
|
|
|
1
|
-
import { defineStore } from 'pinia'
|
|
2
|
-
import { ref } from 'vue'
|
|
3
|
-
import { ElMessage } from 'element-plus'
|
|
4
|
-
|
|
5
|
-
// 删除防抖变量
|
|
6
|
-
// let branchStatusDebounceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
7
|
-
// const BRANCH_STATUS_DEBOUNCE_DELAY = 1000; // 1秒防抖延迟
|
|
8
|
-
|
|
9
|
-
export const useGitStore = defineStore('git', () => {
|
|
10
|
-
// 状态
|
|
11
|
-
const currentBranch = ref('')
|
|
12
|
-
const allBranches = ref<string[]>([])
|
|
13
|
-
const userName = ref('')
|
|
14
|
-
const userEmail = ref('')
|
|
15
|
-
const isChangingBranch = ref(false)
|
|
16
|
-
const isCreatingBranch = ref(false)
|
|
17
|
-
const isGitRepo = ref(false) // 当前目录是否是Git仓库
|
|
18
|
-
const lastCheckedTime = ref(0) // 上次检查Git仓库状态的时间戳
|
|
19
|
-
|
|
20
|
-
// 添加分支状态相关变量
|
|
21
|
-
const branchAhead = ref(0) // 当前分支领先远程分支的提交数
|
|
22
|
-
const branchBehind = ref(0) // 当前分支落后远程分支的提交数
|
|
23
|
-
const hasUpstream = ref(false) // 当前分支是否有上游分支
|
|
24
|
-
const upstreamBranch = ref('') // 上游分支名称
|
|
25
|
-
// 添加上次获取分支状态的时间戳
|
|
26
|
-
const lastBranchStatusTime = ref(0)
|
|
27
|
-
// 添加上次获取分支列表的时间戳
|
|
28
|
-
const lastBranchesTime = ref(0)
|
|
29
|
-
|
|
30
|
-
// 添加重置方法
|
|
31
|
-
function $reset() {
|
|
32
|
-
currentBranch.value = ''
|
|
33
|
-
allBranches.value = []
|
|
34
|
-
userName.value = ''
|
|
35
|
-
userEmail.value = ''
|
|
36
|
-
isChangingBranch.value = false
|
|
37
|
-
isCreatingBranch.value = false
|
|
38
|
-
isGitRepo.value = false
|
|
39
|
-
lastCheckedTime.value = 0
|
|
40
|
-
branchAhead.value = 0
|
|
41
|
-
branchBehind.value = 0
|
|
42
|
-
hasUpstream.value = false
|
|
43
|
-
upstreamBranch.value = ''
|
|
44
|
-
lastBranchStatusTime.value = 0
|
|
45
|
-
lastBranchesTime.value = 0
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// 获取分支状态(领先/落后远程)
|
|
49
|
-
async function getBranchStatus() {
|
|
50
|
-
if (!isGitRepo.value) return;
|
|
51
|
-
|
|
52
|
-
// 移除时间戳缓存判断,简化逻辑
|
|
53
|
-
try {
|
|
54
|
-
console.log('获取分支状态...');
|
|
55
|
-
const response = await fetch('/api/branch-status');
|
|
56
|
-
const data = await response.json();
|
|
57
|
-
|
|
58
|
-
if (data) {
|
|
59
|
-
branchAhead.value = data.ahead || 0;
|
|
60
|
-
branchBehind.value = data.behind || 0;
|
|
61
|
-
hasUpstream.value = data.hasUpstream || false;
|
|
62
|
-
upstreamBranch.value = data.upstreamBranch || '';
|
|
63
|
-
|
|
64
|
-
// 更新获取时间戳
|
|
65
|
-
lastBranchStatusTime.value = Date.now();
|
|
66
|
-
|
|
67
|
-
// 添加调试日志
|
|
68
|
-
console.log(`分支状态更新:领先 ${branchAhead.value} 个提交,落后 ${branchBehind.value} 个提交,上游分支:${hasUpstream.value ? upstreamBranch.value : '无'}`);
|
|
69
|
-
}
|
|
70
|
-
} catch (error) {
|
|
71
|
-
console.error('获取分支状态失败:', error);
|
|
72
|
-
// 出错时重置状态
|
|
73
|
-
branchAhead.value = 0;
|
|
74
|
-
branchBehind.value = 0;
|
|
75
|
-
hasUpstream.value = false;
|
|
76
|
-
upstreamBranch.value = '';
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// 检查当前目录是否是Git仓库
|
|
81
|
-
async function checkGitRepo() {
|
|
82
|
-
// 如果距离上次检查不到1秒,直接返回缓存的结果
|
|
83
|
-
const now = Date.now()
|
|
84
|
-
if (now - lastCheckedTime.value < 1000) {
|
|
85
|
-
console.log('使用缓存的Git仓库状态:', isGitRepo.value ? '是' : '不是')
|
|
86
|
-
return isGitRepo.value
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
const response = await fetch('/api/current_directory')
|
|
91
|
-
const data = await response.json()
|
|
92
|
-
isGitRepo.value = data.isGitRepo === true
|
|
93
|
-
lastCheckedTime.value = now // 更新检查时间
|
|
94
|
-
console.log(`当前目录${isGitRepo.value ? '是' : '不是'}Git仓库`)
|
|
95
|
-
return isGitRepo.value
|
|
96
|
-
} catch (error) {
|
|
97
|
-
console.error('检查Git仓库状态失败:', error)
|
|
98
|
-
isGitRepo.value = false
|
|
99
|
-
lastCheckedTime.value = now // 即使失败也更新检查时间,避免频繁重试
|
|
100
|
-
return false
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// 获取当前分支
|
|
105
|
-
async function getCurrentBranch() {
|
|
106
|
-
try {
|
|
107
|
-
const response = await fetch('/api/branch')
|
|
108
|
-
const data = await response.json()
|
|
109
|
-
if (data.branch) {
|
|
110
|
-
currentBranch.value = data.branch
|
|
111
|
-
// 不再在这里调用 getBranchStatus
|
|
112
|
-
}
|
|
113
|
-
} catch (error) {
|
|
114
|
-
console.error('获取分支信息失败:', error)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// 获取所有分支
|
|
119
|
-
async function getAllBranches() {
|
|
120
|
-
if (!isGitRepo.value) return;
|
|
121
|
-
|
|
122
|
-
// 移除时间戳缓存判断,简化逻辑
|
|
123
|
-
try {
|
|
124
|
-
console.log('获取所有分支...');
|
|
125
|
-
const response = await fetch('/api/branches')
|
|
126
|
-
const data = await response.json()
|
|
127
|
-
if (data.branches && Array.isArray(data.branches)) {
|
|
128
|
-
allBranches.value = data.branches
|
|
129
|
-
// 更新获取时间戳
|
|
130
|
-
lastBranchesTime.value = Date.now();
|
|
131
|
-
console.log(`获取到${data.branches.length}个分支`);
|
|
132
|
-
}
|
|
133
|
-
} catch (error) {
|
|
134
|
-
console.error('获取所有分支信息失败:', error)
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// 切换分支
|
|
139
|
-
async function changeBranch(branch: string) {
|
|
140
|
-
console.log('切换到分支:', branch)
|
|
141
|
-
|
|
142
|
-
try {
|
|
143
|
-
isChangingBranch.value = true
|
|
144
|
-
const response = await fetch('/api/checkout', {
|
|
145
|
-
method: 'POST',
|
|
146
|
-
headers: {
|
|
147
|
-
'Content-Type': 'application/json'
|
|
148
|
-
},
|
|
149
|
-
body: JSON.stringify({ branch })
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
const result = await response.json()
|
|
153
|
-
if (result.success) {
|
|
154
|
-
ElMessage({
|
|
155
|
-
message: `已切换到分支: ${branch}`,
|
|
156
|
-
type: 'success'
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
// 分别刷新分支信息和分支状态
|
|
160
|
-
await getCurrentBranch()
|
|
161
|
-
await getBranchStatus()
|
|
162
|
-
|
|
163
|
-
return true
|
|
164
|
-
} else {
|
|
165
|
-
ElMessage({
|
|
166
|
-
message: `切换分支失败: ${result.error}`,
|
|
167
|
-
type: 'error'
|
|
168
|
-
})
|
|
169
|
-
return false
|
|
170
|
-
}
|
|
171
|
-
} catch (error) {
|
|
172
|
-
ElMessage({
|
|
173
|
-
message: `切换分支失败: ${(error as Error).message}`,
|
|
174
|
-
type: 'error'
|
|
175
|
-
})
|
|
176
|
-
return false
|
|
177
|
-
} finally {
|
|
178
|
-
isChangingBranch.value = false
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// 获取Git用户信息
|
|
183
|
-
async function getUserInfo() {
|
|
184
|
-
try {
|
|
185
|
-
const response = await fetch('/api/user-info')
|
|
186
|
-
const data = await response.json()
|
|
187
|
-
if (data.name && data.email) {
|
|
188
|
-
userName.value = data.name
|
|
189
|
-
userEmail.value = data.email
|
|
190
|
-
}
|
|
191
|
-
} catch (error) {
|
|
192
|
-
console.error('获取用户信息失败:', error)
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// 创建新分支
|
|
197
|
-
async function createBranch(newBranchName: string, baseBranch: string) {
|
|
198
|
-
if (!newBranchName.trim()) {
|
|
199
|
-
ElMessage({
|
|
200
|
-
message: '分支名称不能为空',
|
|
201
|
-
type: 'warning'
|
|
202
|
-
})
|
|
203
|
-
return false
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
try {
|
|
207
|
-
isCreatingBranch.value = true
|
|
208
|
-
|
|
209
|
-
const response = await fetch('/api/create-branch', {
|
|
210
|
-
method: 'POST',
|
|
211
|
-
headers: {
|
|
212
|
-
'Content-Type': 'application/json'
|
|
213
|
-
},
|
|
214
|
-
body: JSON.stringify({
|
|
215
|
-
newBranchName,
|
|
216
|
-
baseBranch: baseBranch || currentBranch.value
|
|
217
|
-
})
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
const result = await response.json()
|
|
221
|
-
if (result.success) {
|
|
222
|
-
ElMessage({
|
|
223
|
-
message: `已创建并切换到分支: ${newBranchName}`,
|
|
224
|
-
type: 'success'
|
|
225
|
-
})
|
|
226
|
-
|
|
227
|
-
// 分别刷新分支信息和状态
|
|
228
|
-
await getCurrentBranch()
|
|
229
|
-
await getBranchStatus()
|
|
230
|
-
await getAllBranches()
|
|
231
|
-
|
|
232
|
-
return true
|
|
233
|
-
} else {
|
|
234
|
-
ElMessage({
|
|
235
|
-
message: `创建分支失败: ${result.error}`,
|
|
236
|
-
type: 'error'
|
|
237
|
-
})
|
|
238
|
-
return false
|
|
239
|
-
}
|
|
240
|
-
} catch (error) {
|
|
241
|
-
ElMessage({
|
|
242
|
-
message: `创建分支失败: ${(error as Error).message}`,
|
|
243
|
-
type: 'error'
|
|
244
|
-
})
|
|
245
|
-
return false
|
|
246
|
-
} finally {
|
|
247
|
-
isCreatingBranch.value = false
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// 清除Git用户配置
|
|
252
|
-
async function clearUserConfig() {
|
|
253
|
-
try {
|
|
254
|
-
const response = await fetch('/api/clear-user-config', {
|
|
255
|
-
method: 'POST'
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
const result = await response.json();
|
|
259
|
-
if (result.success) {
|
|
260
|
-
// 清空本地状态
|
|
261
|
-
userName.value = '';
|
|
262
|
-
userEmail.value = '';
|
|
263
|
-
ElMessage({
|
|
264
|
-
message: '已清除Git用户配置',
|
|
265
|
-
type: 'success'
|
|
266
|
-
});
|
|
267
|
-
return true;
|
|
268
|
-
} else {
|
|
269
|
-
ElMessage({
|
|
270
|
-
message: `清除配置失败: ${result.error}`,
|
|
271
|
-
type: 'error'
|
|
272
|
-
});
|
|
273
|
-
return false;
|
|
274
|
-
}
|
|
275
|
-
} catch (error) {
|
|
276
|
-
ElMessage({
|
|
277
|
-
message: `清除配置失败: ${(error as Error).message}`,
|
|
278
|
-
type: 'error'
|
|
279
|
-
});
|
|
280
|
-
return false;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// 恢复Git用户配置
|
|
285
|
-
async function restoreUserConfig(name: string, email: string) {
|
|
286
|
-
try {
|
|
287
|
-
const response = await fetch('/api/restore-user-config', {
|
|
288
|
-
method: 'POST',
|
|
289
|
-
headers: {
|
|
290
|
-
'Content-Type': 'application/json'
|
|
291
|
-
},
|
|
292
|
-
body: JSON.stringify({ name, email })
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
const result = await response.json();
|
|
296
|
-
if (result.success) {
|
|
297
|
-
// 更新本地状态
|
|
298
|
-
userName.value = name;
|
|
299
|
-
userEmail.value = email;
|
|
300
|
-
ElMessage({
|
|
301
|
-
message: '已恢复Git用户配置',
|
|
302
|
-
type: 'success'
|
|
303
|
-
});
|
|
304
|
-
return true;
|
|
305
|
-
} else {
|
|
306
|
-
ElMessage({
|
|
307
|
-
message: `恢复配置失败: ${result.error}`,
|
|
308
|
-
type: 'error'
|
|
309
|
-
});
|
|
310
|
-
return false;
|
|
311
|
-
}
|
|
312
|
-
} catch (error) {
|
|
313
|
-
ElMessage({
|
|
314
|
-
message: `恢复配置失败: ${(error as Error).message}`,
|
|
315
|
-
type: 'error'
|
|
316
|
-
});
|
|
317
|
-
return false;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// 执行git pull操作
|
|
322
|
-
async function gitPull() {
|
|
323
|
-
if (!isGitRepo.value) {
|
|
324
|
-
ElMessage({
|
|
325
|
-
message: '当前目录不是Git仓库',
|
|
326
|
-
type: 'warning'
|
|
327
|
-
});
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
try {
|
|
332
|
-
const response = await fetch('/api/pull', {
|
|
333
|
-
method: 'POST'
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
const result = await response.json();
|
|
337
|
-
if (result.success) {
|
|
338
|
-
ElMessage({
|
|
339
|
-
message: '拉取成功',
|
|
340
|
-
type: 'success'
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
// 刷新分支状态
|
|
344
|
-
await getBranchStatus();
|
|
345
|
-
return true;
|
|
346
|
-
} else {
|
|
347
|
-
// 改进错误提示
|
|
348
|
-
if (result.needsMerge) {
|
|
349
|
-
ElMessage({
|
|
350
|
-
message: `需要合并更改: ${result.pullOutput || '存在冲突需要手动解决'}`,
|
|
351
|
-
type: 'warning',
|
|
352
|
-
duration: 5000
|
|
353
|
-
});
|
|
354
|
-
} else {
|
|
355
|
-
ElMessage({
|
|
356
|
-
message: `拉取失败: ${result.error}`,
|
|
357
|
-
type: 'error'
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
return false;
|
|
361
|
-
}
|
|
362
|
-
} catch (error) {
|
|
363
|
-
ElMessage({
|
|
364
|
-
message: `拉取失败: ${(error as Error).message}`,
|
|
365
|
-
type: 'error'
|
|
366
|
-
});
|
|
367
|
-
return false;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
// 执行git fetch --all操作
|
|
372
|
-
async function gitFetchAll() {
|
|
373
|
-
if (!isGitRepo.value) {
|
|
374
|
-
ElMessage({
|
|
375
|
-
message: '当前目录不是Git仓库',
|
|
376
|
-
type: 'warning'
|
|
377
|
-
});
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
try {
|
|
382
|
-
const response = await fetch('/api/fetch-all', {
|
|
383
|
-
method: 'POST'
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
const result = await response.json();
|
|
387
|
-
if (result.success) {
|
|
388
|
-
ElMessage({
|
|
389
|
-
message: '获取所有远程分支信息成功',
|
|
390
|
-
type: 'success'
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
// 刷新分支状态
|
|
394
|
-
await getBranchStatus();
|
|
395
|
-
return true;
|
|
396
|
-
} else {
|
|
397
|
-
ElMessage({
|
|
398
|
-
message: `获取远程分支信息失败: ${result.error}`,
|
|
399
|
-
type: 'error'
|
|
400
|
-
});
|
|
401
|
-
return false;
|
|
402
|
-
}
|
|
403
|
-
} catch (error) {
|
|
404
|
-
ElMessage({
|
|
405
|
-
message: `获取远程分支信息失败: ${(error as Error).message}`,
|
|
406
|
-
type: 'error'
|
|
407
|
-
});
|
|
408
|
-
return false;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
return {
|
|
413
|
-
// 状态
|
|
414
|
-
currentBranch,
|
|
415
|
-
allBranches,
|
|
416
|
-
userName,
|
|
417
|
-
userEmail,
|
|
418
|
-
isChangingBranch,
|
|
419
|
-
isCreatingBranch,
|
|
420
|
-
isGitRepo,
|
|
421
|
-
lastCheckedTime,
|
|
422
|
-
branchAhead,
|
|
423
|
-
branchBehind,
|
|
424
|
-
hasUpstream,
|
|
425
|
-
upstreamBranch,
|
|
426
|
-
lastBranchStatusTime,
|
|
427
|
-
lastBranchesTime,
|
|
428
|
-
|
|
429
|
-
// 方法
|
|
430
|
-
$reset,
|
|
431
|
-
checkGitRepo,
|
|
432
|
-
getCurrentBranch,
|
|
433
|
-
getAllBranches,
|
|
434
|
-
changeBranch,
|
|
435
|
-
getUserInfo,
|
|
436
|
-
createBranch,
|
|
437
|
-
clearUserConfig,
|
|
438
|
-
restoreUserConfig,
|
|
439
|
-
getBranchStatus,
|
|
440
|
-
gitPull,
|
|
441
|
-
gitFetchAll
|
|
442
|
-
}
|
|
443
|
-
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|