zen-gitsync 2.10.24 → 2.10.25

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.
@@ -6,10 +6,10 @@
6
6
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
8
8
  <title>Zen GitSync</title>
9
- <script type="module" crossorigin src="/assets/index-b9vh2ATa.js"></script>
10
- <link rel="modulepreload" crossorigin href="/assets/vendor-DrABRxF7.js">
9
+ <script type="module" crossorigin src="/assets/index-B_4pBzHH.js"></script>
10
+ <link rel="modulepreload" crossorigin href="/assets/vendor-fjnRPl5Q.js">
11
11
  <link rel="stylesheet" crossorigin href="/assets/vendor-DpSHka1A.css">
12
- <link rel="stylesheet" crossorigin href="/assets/index-D_n92IoC.css">
12
+ <link rel="stylesheet" crossorigin href="/assets/index-aLDYiWyf.css">
13
13
  </head>
14
14
  <body>
15
15
  <div id="app"></div>
@@ -2,7 +2,7 @@ import express from 'express';
2
2
  import { createServer } from 'http';
3
3
  import { fileURLToPath } from 'url';
4
4
  import path from 'path';
5
- import { execGitCommand, getCommandHistory, addCommandToHistory, clearCommandHistory, registerSocketIO, execGitAddWithLockFilter } from '../../utils/index.js';
5
+ import { execGitCommand, getCommandHistory, addCommandToHistory, clearCommandHistory, registerSocketIO, execGitAddWithLockFilter, checkAndClearGitLock } from '../../utils/index.js';
6
6
  import open from 'open';
7
7
  import config from '../../config.js';
8
8
  import chalk from 'chalk';
@@ -230,6 +230,7 @@ async function startUIServer(noOpen = false, savePort = false) {
230
230
  execGitAddWithLockFilter,
231
231
  addCommandToHistory,
232
232
  clearCommandHistory,
233
+ checkAndClearGitLock,
233
234
  getIsGitRepo: () => isGitRepo,
234
235
  setRecentPushStatus: (v) => { recentPushStatus = v; }
235
236
  });
@@ -16,6 +16,7 @@ export function registerGitOpsRoutes({
16
16
  execGitAddWithLockFilter,
17
17
  addCommandToHistory,
18
18
  clearCommandHistory,
19
+ checkAndClearGitLock,
19
20
  getIsGitRepo,
20
21
  setRecentPushStatus
21
22
  }) {
@@ -643,6 +644,9 @@ export function registerGitOpsRoutes({
643
644
  });
644
645
  }
645
646
 
647
+ // 尝试清理 Git 锁文件
648
+ await checkAndClearGitLock();
649
+
646
650
  // 执行 git reset --hard origin/branch 命令
647
651
  await execGitCommand(`git reset --hard origin/${branch}`);
648
652
  res.json({ success: true });
@@ -655,6 +659,28 @@ export function registerGitOpsRoutes({
655
659
  }
656
660
  });
657
661
 
662
+ // 清除本地所有更改,包括未跟踪文件 (git reset --hard && git clean -fd)
663
+ app.post('/api/discard-all-changes', async (req, res) => {
664
+ try {
665
+ // 尝试清理 Git 锁文件
666
+ await checkAndClearGitLock();
667
+
668
+ // 1. 执行 git reset --hard 丢弃已跟踪文件的更改
669
+ await execGitCommand('git reset --hard');
670
+
671
+ // 2. 执行 git clean -fd 移除未跟踪的文件和目录
672
+ await execGitCommand('git clean -fd');
673
+
674
+ res.json({ success: true });
675
+ } catch (error) {
676
+ console.error('清除所有更改失败:', error);
677
+ res.status(500).json({
678
+ success: false,
679
+ error: `清除所有更改失败: ${error.message}`
680
+ });
681
+ }
682
+ });
683
+
658
684
  // 获取提交的文件列表
659
685
  app.get('/api/commit-files', async (req, res) => {
660
686
  try {
@@ -365,6 +365,39 @@ function execGitCommand(command, options = {}) {
365
365
  })
366
366
  }
367
367
 
368
+ /**
369
+ * 检查并尝试清理 Git 锁文件
370
+ * @returns {Promise<boolean>} 是否清理成功
371
+ */
372
+ async function checkAndClearGitLock() {
373
+ try {
374
+ const cwd = getCwd();
375
+ let gitRoot;
376
+ try {
377
+ // 使用 execSync 快速获取 Git 根目录
378
+ const rootOutput = execSync('git rev-parse --show-toplevel', { cwd, encoding: 'utf-8' });
379
+ gitRoot = rootOutput.trim();
380
+ } catch (e) {
381
+ gitRoot = cwd;
382
+ }
383
+
384
+ const lockFilePath = path.join(gitRoot, '.git', 'index.lock');
385
+ try {
386
+ await fs.access(lockFilePath);
387
+ // 如果文件存在,尝试删除它
388
+ await fs.unlink(lockFilePath);
389
+ console.log(chalk.green(`✅ 已清理 Git 锁文件: ${lockFilePath}`));
390
+ return true;
391
+ } catch (e) {
392
+ // 文件不存在,不需要清理
393
+ return false;
394
+ }
395
+ } catch (error) {
396
+ console.error(chalk.red('清理 Git 锁文件失败:'), error.message);
397
+ return false;
398
+ }
399
+ }
400
+
368
401
  // Function to get command history
369
402
  function getCommandHistory() {
370
403
  return [...commandHistory];
@@ -1001,6 +1034,7 @@ export {
1001
1034
  coloredLog, errorLog, execSyncGitCommand,
1002
1035
  execGitCommand, getCommandHistory, addCommandToHistory, // Add command history exports
1003
1036
  clearCommandHistory,
1037
+ checkAndClearGitLock,
1004
1038
  registerSocketIO, // 导出注册Socket.io的函数
1005
1039
  getCwd, judgePlatform, showHelp, judgeLog, printGitLog,
1006
1040
  judgeHelp, exec_exit, judgeUnmerged, delay, formatDuration,