zen-gitsync 2.0.5 → 2.0.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/README.md +31 -2
- package/package.json +3 -1
- package/src/ui/client/src/App.vue +417 -123
- package/src/ui/client/src/components/CommitForm.vue +284 -211
- package/src/ui/client/src/components/GitStatus.vue +556 -171
- package/src/ui/client/src/components/LogList.vue +778 -94
- package/src/ui/client/src/stores/gitLogStore.ts +328 -13
- package/src/ui/client/stats.html +1 -1
- package/src/ui/public/assets/index-DaPynzAr.js +10 -0
- package/src/ui/public/assets/index-qfIezZmd.css +1 -0
- package/src/ui/public/assets/vendor-BcSuWc8z.js +45 -0
- package/src/ui/public/index.html +3 -3
- package/src/ui/server/index.js +287 -40
- package/src/ui/public/assets/index-CALk9kKc.js +0 -9
- package/src/ui/public/assets/index-D3zIiSNw.css +0 -1
- package/src/ui/public/assets/vendor-BfXVsoKv.js +0 -45
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { defineStore } from 'pinia'
|
|
2
|
-
import { ref } from 'vue'
|
|
2
|
+
import { ref, onMounted, onUnmounted } from 'vue'
|
|
3
3
|
import { ElMessage } from 'element-plus'
|
|
4
4
|
import { useGitStore } from './gitStore'
|
|
5
|
+
import { io, Socket } from 'socket.io-client'
|
|
5
6
|
|
|
6
7
|
// 定义Git操作间隔时间(毫秒)
|
|
7
8
|
const GIT_OPERATION_DELAY = 300
|
|
@@ -10,6 +11,11 @@ export const useGitLogStore = defineStore('gitLog', () => {
|
|
|
10
11
|
// 引用gitStore获取仓库状态
|
|
11
12
|
const gitStore = useGitStore()
|
|
12
13
|
|
|
14
|
+
// 定义socket连接
|
|
15
|
+
let socket: Socket | null = null
|
|
16
|
+
// 自动更新状态开关
|
|
17
|
+
const autoUpdateEnabled = ref(true)
|
|
18
|
+
|
|
13
19
|
// 状态
|
|
14
20
|
const log = ref<any[]>([])
|
|
15
21
|
const status = ref<{ staged: string[], unstaged: string[], untracked: string[] }>({
|
|
@@ -28,6 +34,163 @@ export const useGitLogStore = defineStore('gitLog', () => {
|
|
|
28
34
|
const isPushing = ref(false)
|
|
29
35
|
const isResetting = ref(false)
|
|
30
36
|
|
|
37
|
+
// Socket.io连接处理
|
|
38
|
+
function initSocketConnection() {
|
|
39
|
+
// 如果已经有socket连接,先断开
|
|
40
|
+
if (socket) {
|
|
41
|
+
socket.disconnect()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 创建新连接
|
|
45
|
+
try {
|
|
46
|
+
// 修正Socket.IO连接URL,使用固定的后端服务器端口3000
|
|
47
|
+
const backendUrl = 'http://localhost:3000'
|
|
48
|
+
|
|
49
|
+
console.log('尝试连接Socket.IO服务器:', backendUrl)
|
|
50
|
+
|
|
51
|
+
socket = io(backendUrl, {
|
|
52
|
+
reconnectionDelayMax: 10000,
|
|
53
|
+
reconnection: true,
|
|
54
|
+
reconnectionAttempts: 10,
|
|
55
|
+
reconnectionDelay: 1000, // 初始重连延迟1秒
|
|
56
|
+
timeout: 20000, // 连接超时时间
|
|
57
|
+
autoConnect: true, // 自动连接
|
|
58
|
+
forceNew: true, // 强制创建新连接
|
|
59
|
+
transports: ['websocket', 'polling'] // 优先使用WebSocket
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
// 检查socket是否成功创建
|
|
63
|
+
if (!socket) {
|
|
64
|
+
console.error('Socket.IO初始化失败: socket为null')
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
console.log('Socket.IO初始化成功,socket ID:', socket.id || '未连接')
|
|
68
|
+
|
|
69
|
+
// 监听连接事件
|
|
70
|
+
socket.on('connect', () => {
|
|
71
|
+
console.log('成功连接到Socket.IO服务器')
|
|
72
|
+
|
|
73
|
+
// 如果自动更新开启,向服务器请求开始监控
|
|
74
|
+
if (autoUpdateEnabled.value && socket) {
|
|
75
|
+
socket.emit('start_monitoring')
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
// 监听断开连接事件
|
|
80
|
+
socket.on('disconnect', (reason) => {
|
|
81
|
+
console.log('与Socket.IO服务器断开连接:', reason)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// 监听Git状态更新事件
|
|
85
|
+
socket.on('git_status_update', (data) => {
|
|
86
|
+
if (!autoUpdateEnabled.value) return
|
|
87
|
+
|
|
88
|
+
console.log('收到Git状态更新通知:', new Date().toLocaleTimeString())
|
|
89
|
+
|
|
90
|
+
// 更新状态文本
|
|
91
|
+
if (data.status) {
|
|
92
|
+
statusText.value = data.status
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 更新文件列表
|
|
96
|
+
if (data.porcelain !== undefined) {
|
|
97
|
+
parseStatusPorcelain(data.porcelain)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 根据文件列表判断是否需要更新日志
|
|
101
|
+
const hasChanges = fileList.value.length > 0
|
|
102
|
+
|
|
103
|
+
// 如果有变化,更新状态
|
|
104
|
+
if (hasChanges) {
|
|
105
|
+
// 自动刷新日志,但不要显示消息通知
|
|
106
|
+
fetchLog(false)
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
// 监听监控状态
|
|
111
|
+
socket.on('monitoring_status', (data) => {
|
|
112
|
+
console.log('文件监控状态:', data.active ? '已启动' : '已停止')
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
// 添加额外的连接问题诊断
|
|
116
|
+
socket.on('connect_error', (error) => {
|
|
117
|
+
console.error('Socket连接错误:', error.message)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
socket.on('connect_timeout', () => {
|
|
121
|
+
console.error('Socket连接超时')
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
socket.on('reconnect', (attemptNumber) => {
|
|
125
|
+
console.log(`Socket重连成功,尝试次数: ${attemptNumber}`)
|
|
126
|
+
|
|
127
|
+
// 重连后检查自动更新状态
|
|
128
|
+
if (autoUpdateEnabled.value) {
|
|
129
|
+
console.log('重连后重新发送start_monitoring请求')
|
|
130
|
+
socket?.emit('start_monitoring')
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
socket.on('reconnect_attempt', (attemptNumber) => {
|
|
135
|
+
console.log(`Socket尝试重连,第 ${attemptNumber} 次尝试`)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
socket.on('reconnect_error', (error) => {
|
|
139
|
+
console.error('Socket重连错误:', error.message)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
socket.on('reconnect_failed', () => {
|
|
143
|
+
console.error('Socket重连失败,已达到最大重试次数')
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
// 手动尝试连接
|
|
147
|
+
if (socket && !socket.connected) {
|
|
148
|
+
console.log('Socket未连接,尝试手动连接...')
|
|
149
|
+
socket.connect()
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
console.error('Socket.IO连接初始化失败:', error)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 切换自动更新状态
|
|
157
|
+
function toggleAutoUpdate() {
|
|
158
|
+
// autoUpdateEnabled.value = !autoUpdateEnabled.value
|
|
159
|
+
console.log('toggleAutoUpdate调用,当前值:', autoUpdateEnabled.value)
|
|
160
|
+
|
|
161
|
+
if (!socket) {
|
|
162
|
+
console.error('无法切换自动更新状态: socket连接不存在')
|
|
163
|
+
ElMessage.error('无法连接到服务器,自动更新可能不会生效')
|
|
164
|
+
|
|
165
|
+
// 尝试重新初始化socket连接
|
|
166
|
+
console.log('尝试重新建立socket连接...')
|
|
167
|
+
initSocketConnection()
|
|
168
|
+
|
|
169
|
+
// 即使socket可能不存在,也保存设置
|
|
170
|
+
localStorage.setItem('zen-gitsync-auto-update', autoUpdateEnabled.value.toString())
|
|
171
|
+
return
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
try {
|
|
175
|
+
if (autoUpdateEnabled.value) {
|
|
176
|
+
console.log('发送start_monitoring命令...')
|
|
177
|
+
socket.emit('start_monitoring')
|
|
178
|
+
ElMessage.success('自动更新已启用')
|
|
179
|
+
} else {
|
|
180
|
+
console.log('发送stop_monitoring命令...')
|
|
181
|
+
socket.emit('stop_monitoring')
|
|
182
|
+
ElMessage.info('自动更新已禁用')
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// 保存设置到localStorage
|
|
186
|
+
localStorage.setItem('zen-gitsync-auto-update', autoUpdateEnabled.value.toString())
|
|
187
|
+
console.log('已保存自动更新设置到本地存储:', autoUpdateEnabled.value)
|
|
188
|
+
} catch (error) {
|
|
189
|
+
console.error('切换自动更新状态时出错:', error)
|
|
190
|
+
ElMessage.error(`切换自动更新失败: ${(error as Error).message}`)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
31
194
|
// 解析 git status --porcelain 输出,提取文件及类型
|
|
32
195
|
function parseStatusPorcelain(statusText: string) {
|
|
33
196
|
if (statusText === undefined || statusText === '') {
|
|
@@ -44,12 +207,37 @@ export const useGitLogStore = defineStore('gitLog', () => {
|
|
|
44
207
|
const match = line.match(/^([ MADRCU\?]{2})\s+(.+)$/)
|
|
45
208
|
if (match) {
|
|
46
209
|
let type = ''
|
|
47
|
-
const code = match[1]
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
210
|
+
const code = match[1]
|
|
211
|
+
const indexStatus = code.charAt(0)
|
|
212
|
+
const workTreeStatus = code.charAt(1)
|
|
213
|
+
|
|
214
|
+
// 根据暂存区状态和工作区状态确定文件类型
|
|
215
|
+
if (indexStatus === 'A') {
|
|
216
|
+
// 已暂存的新文件
|
|
217
|
+
type = 'added'
|
|
218
|
+
} else if (indexStatus === 'M') {
|
|
219
|
+
// 已暂存的修改文件
|
|
220
|
+
type = 'added'
|
|
221
|
+
} else if (indexStatus === 'D') {
|
|
222
|
+
// 已暂存的删除文件
|
|
223
|
+
type = 'added'
|
|
224
|
+
} else if (indexStatus === 'R') {
|
|
225
|
+
// 已暂存的重命名文件
|
|
226
|
+
type = 'added'
|
|
227
|
+
} else if (indexStatus === ' ' && workTreeStatus === 'M') {
|
|
228
|
+
// 已修改未暂存的文件
|
|
229
|
+
type = 'modified'
|
|
230
|
+
} else if (indexStatus === ' ' && workTreeStatus === 'D') {
|
|
231
|
+
// 已删除未暂存的文件
|
|
232
|
+
type = 'deleted'
|
|
233
|
+
} else if (code === '??') {
|
|
234
|
+
// 未跟踪的文件
|
|
235
|
+
type = 'untracked'
|
|
236
|
+
} else {
|
|
237
|
+
// 其他情况
|
|
238
|
+
type = 'other'
|
|
239
|
+
}
|
|
240
|
+
|
|
53
241
|
files.push({ path: match[2], type })
|
|
54
242
|
}
|
|
55
243
|
}
|
|
@@ -57,7 +245,7 @@ export const useGitLogStore = defineStore('gitLog', () => {
|
|
|
57
245
|
}
|
|
58
246
|
|
|
59
247
|
// 获取提交日志
|
|
60
|
-
async function fetchLog() {
|
|
248
|
+
async function fetchLog(showMessage = true) {
|
|
61
249
|
// 检查是否是Git仓库
|
|
62
250
|
if (!gitStore.isGitRepo) {
|
|
63
251
|
console.log('当前目录不是Git仓库,跳过加载提交历史')
|
|
@@ -73,12 +261,21 @@ export const useGitLogStore = defineStore('gitLog', () => {
|
|
|
73
261
|
log.value = data
|
|
74
262
|
}
|
|
75
263
|
console.log(`提交历史加载完成,共 ${log.value.length} 条记录`)
|
|
264
|
+
|
|
265
|
+
if (showMessage) {
|
|
266
|
+
ElMessage({
|
|
267
|
+
message: '提交历史已更新',
|
|
268
|
+
type: 'success'
|
|
269
|
+
})
|
|
270
|
+
}
|
|
76
271
|
} catch (error) {
|
|
77
272
|
console.error('获取提交历史失败:', error)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
273
|
+
if (showMessage) {
|
|
274
|
+
ElMessage({
|
|
275
|
+
message: `获取提交历史失败: ${(error as Error).message}`,
|
|
276
|
+
type: 'error'
|
|
277
|
+
})
|
|
278
|
+
}
|
|
82
279
|
} finally {
|
|
83
280
|
isLoadingLog.value = false
|
|
84
281
|
}
|
|
@@ -121,6 +318,7 @@ export const useGitLogStore = defineStore('gitLog', () => {
|
|
|
121
318
|
|
|
122
319
|
// 获取Git状态 (porcelain格式)
|
|
123
320
|
async function fetchStatusPorcelain() {
|
|
321
|
+
console.log('开始获取Git状态(porcelain格式)...')
|
|
124
322
|
// 检查是否是Git仓库
|
|
125
323
|
if (!gitStore.isGitRepo) {
|
|
126
324
|
console.log('当前目录不是Git仓库,跳过加载Git状态')
|
|
@@ -190,6 +388,100 @@ export const useGitLogStore = defineStore('gitLog', () => {
|
|
|
190
388
|
}
|
|
191
389
|
}
|
|
192
390
|
|
|
391
|
+
// 添加单个文件到暂存区
|
|
392
|
+
async function addFileToStage(filePath: string) {
|
|
393
|
+
// 检查是否是Git仓库
|
|
394
|
+
if (!gitStore.isGitRepo) {
|
|
395
|
+
ElMessage.warning('当前目录不是Git仓库')
|
|
396
|
+
return false
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
try {
|
|
400
|
+
isAddingFiles.value = true
|
|
401
|
+
const response = await fetch('/api/add-file', {
|
|
402
|
+
method: 'POST',
|
|
403
|
+
headers: {
|
|
404
|
+
'Content-Type': 'application/json'
|
|
405
|
+
},
|
|
406
|
+
body: JSON.stringify({ filePath })
|
|
407
|
+
})
|
|
408
|
+
|
|
409
|
+
const result = await response.json()
|
|
410
|
+
if (result.success) {
|
|
411
|
+
ElMessage({
|
|
412
|
+
message: '文件已暂存',
|
|
413
|
+
type: 'success'
|
|
414
|
+
})
|
|
415
|
+
|
|
416
|
+
// 刷新状态
|
|
417
|
+
fetchStatus()
|
|
418
|
+
|
|
419
|
+
return true
|
|
420
|
+
} else {
|
|
421
|
+
ElMessage({
|
|
422
|
+
message: `暂存文件失败: ${result.error}`,
|
|
423
|
+
type: 'error'
|
|
424
|
+
})
|
|
425
|
+
return false
|
|
426
|
+
}
|
|
427
|
+
} catch (error) {
|
|
428
|
+
ElMessage({
|
|
429
|
+
message: `暂存文件失败: ${(error as Error).message}`,
|
|
430
|
+
type: 'error'
|
|
431
|
+
})
|
|
432
|
+
return false
|
|
433
|
+
} finally {
|
|
434
|
+
isAddingFiles.value = false
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// 取消暂存单个文件
|
|
439
|
+
async function unstageFile(filePath: string) {
|
|
440
|
+
// 检查是否是Git仓库
|
|
441
|
+
if (!gitStore.isGitRepo) {
|
|
442
|
+
ElMessage.warning('当前目录不是Git仓库')
|
|
443
|
+
return false
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
try {
|
|
447
|
+
isResetting.value = true
|
|
448
|
+
const response = await fetch('/api/unstage-file', {
|
|
449
|
+
method: 'POST',
|
|
450
|
+
headers: {
|
|
451
|
+
'Content-Type': 'application/json'
|
|
452
|
+
},
|
|
453
|
+
body: JSON.stringify({ filePath })
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
const result = await response.json()
|
|
457
|
+
if (result.success) {
|
|
458
|
+
ElMessage({
|
|
459
|
+
message: '已取消暂存文件',
|
|
460
|
+
type: 'success'
|
|
461
|
+
})
|
|
462
|
+
|
|
463
|
+
// 刷新状态
|
|
464
|
+
fetchStatus()
|
|
465
|
+
|
|
466
|
+
return true
|
|
467
|
+
} else {
|
|
468
|
+
ElMessage({
|
|
469
|
+
message: `取消暂存失败: ${result.error}`,
|
|
470
|
+
type: 'error'
|
|
471
|
+
})
|
|
472
|
+
return false
|
|
473
|
+
}
|
|
474
|
+
} catch (error) {
|
|
475
|
+
ElMessage({
|
|
476
|
+
message: `取消暂存失败: ${(error as Error).message}`,
|
|
477
|
+
type: 'error'
|
|
478
|
+
})
|
|
479
|
+
return false
|
|
480
|
+
} finally {
|
|
481
|
+
isResetting.value = false
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
193
485
|
// 添加延时函数
|
|
194
486
|
function delay(ms: number) {
|
|
195
487
|
return new Promise(resolve => setTimeout(resolve, ms))
|
|
@@ -435,6 +727,25 @@ export const useGitLogStore = defineStore('gitLog', () => {
|
|
|
435
727
|
}
|
|
436
728
|
}
|
|
437
729
|
|
|
730
|
+
// 在组件挂载时初始化socket连接
|
|
731
|
+
onMounted(() => {
|
|
732
|
+
// 从localStorage加载自动更新设置
|
|
733
|
+
const savedAutoUpdate = localStorage.getItem('zen-gitsync-auto-update')
|
|
734
|
+
if (savedAutoUpdate !== null) {
|
|
735
|
+
autoUpdateEnabled.value = savedAutoUpdate === 'true'
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
initSocketConnection()
|
|
739
|
+
})
|
|
740
|
+
|
|
741
|
+
// 在组件卸载时断开socket连接
|
|
742
|
+
onUnmounted(() => {
|
|
743
|
+
if (socket) {
|
|
744
|
+
socket.disconnect()
|
|
745
|
+
socket = null
|
|
746
|
+
}
|
|
747
|
+
})
|
|
748
|
+
|
|
438
749
|
return {
|
|
439
750
|
// 状态
|
|
440
751
|
log,
|
|
@@ -447,6 +758,7 @@ export const useGitLogStore = defineStore('gitLog', () => {
|
|
|
447
758
|
isResetting,
|
|
448
759
|
isCommiting,
|
|
449
760
|
isPushing,
|
|
761
|
+
autoUpdateEnabled,
|
|
450
762
|
|
|
451
763
|
// 方法
|
|
452
764
|
fetchLog,
|
|
@@ -454,11 +766,14 @@ export const useGitLogStore = defineStore('gitLog', () => {
|
|
|
454
766
|
fetchStatusPorcelain,
|
|
455
767
|
parseStatusPorcelain,
|
|
456
768
|
addToStage,
|
|
769
|
+
addFileToStage,
|
|
770
|
+
unstageFile,
|
|
457
771
|
commitChanges,
|
|
458
772
|
pushToRemote,
|
|
459
773
|
addAndCommit,
|
|
460
774
|
addCommitAndPush,
|
|
461
775
|
resetHead,
|
|
462
|
-
resetToRemote
|
|
776
|
+
resetToRemote,
|
|
777
|
+
toggleAutoUpdate
|
|
463
778
|
}
|
|
464
779
|
})
|