zen-gitsync 2.0.4 → 2.0.5

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.
@@ -13,6 +13,18 @@ export const useGitStore = defineStore('git', () => {
13
13
  const isGitRepo = ref(false) // 当前目录是否是Git仓库
14
14
  const lastCheckedTime = ref(0) // 上次检查Git仓库状态的时间戳
15
15
 
16
+ // 添加重置方法
17
+ function $reset() {
18
+ currentBranch.value = ''
19
+ allBranches.value = []
20
+ userName.value = ''
21
+ userEmail.value = ''
22
+ isChangingBranch.value = false
23
+ isCreatingBranch.value = false
24
+ isGitRepo.value = false
25
+ lastCheckedTime.value = 0
26
+ }
27
+
16
28
  // 检查当前目录是否是Git仓库
17
29
  async function checkGitRepo() {
18
30
  // 如果距离上次检查不到1秒,直接返回缓存的结果
@@ -193,6 +205,76 @@ export const useGitStore = defineStore('git', () => {
193
205
  }
194
206
  }
195
207
 
208
+ // 清除Git用户配置
209
+ async function clearUserConfig() {
210
+ try {
211
+ const response = await fetch('/api/clear-user-config', {
212
+ method: 'POST'
213
+ });
214
+
215
+ const result = await response.json();
216
+ if (result.success) {
217
+ // 清空本地状态
218
+ userName.value = '';
219
+ userEmail.value = '';
220
+ ElMessage({
221
+ message: '已清除Git用户配置',
222
+ type: 'success'
223
+ });
224
+ return true;
225
+ } else {
226
+ ElMessage({
227
+ message: `清除配置失败: ${result.error}`,
228
+ type: 'error'
229
+ });
230
+ return false;
231
+ }
232
+ } catch (error) {
233
+ ElMessage({
234
+ message: `清除配置失败: ${(error as Error).message}`,
235
+ type: 'error'
236
+ });
237
+ return false;
238
+ }
239
+ }
240
+
241
+ // 恢复Git用户配置
242
+ async function restoreUserConfig(name: string, email: string) {
243
+ try {
244
+ const response = await fetch('/api/restore-user-config', {
245
+ method: 'POST',
246
+ headers: {
247
+ 'Content-Type': 'application/json'
248
+ },
249
+ body: JSON.stringify({ name, email })
250
+ });
251
+
252
+ const result = await response.json();
253
+ if (result.success) {
254
+ // 更新本地状态
255
+ userName.value = name;
256
+ userEmail.value = email;
257
+ ElMessage({
258
+ message: '已恢复Git用户配置',
259
+ type: 'success'
260
+ });
261
+ return true;
262
+ } else {
263
+ ElMessage({
264
+ message: `恢复配置失败: ${result.error}`,
265
+ type: 'error'
266
+ });
267
+ return false;
268
+ }
269
+ } catch (error) {
270
+ ElMessage({
271
+ message: `恢复配置失败: ${(error as Error).message}`,
272
+ type: 'error'
273
+ });
274
+ return false;
275
+ }
276
+ }
277
+
196
278
  return {
197
279
  // 状态
198
280
  currentBranch,
@@ -205,12 +287,15 @@ export const useGitStore = defineStore('git', () => {
205
287
  lastCheckedTime,
206
288
 
207
289
  // 方法
290
+ $reset,
208
291
  checkGitRepo,
209
292
  getCurrentBranch,
210
293
  getAllBranches,
211
294
  changeBranch,
212
295
  getUserInfo,
213
296
  createBranch,
214
- loadInitialData
297
+ loadInitialData,
298
+ clearUserConfig,
299
+ restoreUserConfig
215
300
  }
216
301
  })