git-ai-shen 1.0.2 → 1.0.3

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.
@@ -17,14 +17,30 @@ class GitOperations {
17
17
  */
18
18
  async getFileDiff(filePath) {
19
19
  try {
20
- // 获取未暂存的变更
21
- const diff = await this.git.diff([filePath]);
20
+ // 方案一:使用 -- 分隔符明确指定是文件路径
21
+ const diff = await this.git.diff(['--', filePath]);
22
+
23
+ // 如果返回空,可能是因为文件没被 git 跟踪,试试用 --no-index
24
+ if (!diff) {
25
+ const fullPath = path.join(this.repoPath, filePath);
26
+ if (fs.existsSync(fullPath)) {
27
+ // 文件存在但没被跟踪,用 --no-index 比较
28
+ const noIndexDiff = await this.git.diff(['--no-index', '--', '/dev/null', filePath]);
29
+ return this.parseDiff(noIndexDiff, filePath);
30
+ }
31
+ }
22
32
 
23
- // 解析 diff 信息
24
33
  return this.parseDiff(diff, filePath);
25
34
  } catch (error) {
26
- console.error(`获取 diff 失败: ${error.message}`);
27
- return null;
35
+ // 如果出错,返回一个空的 diff 对象而不是 null
36
+ console.log(`获取 diff 失败: ${error.message}`);
37
+ return {
38
+ file: filePath,
39
+ changes: [],
40
+ summary: '无变更',
41
+ addCount: 0,
42
+ deleteCount: 0
43
+ };
28
44
  }
29
45
  }
30
46
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-ai-shen",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "智能Git提交工具,支持行级代码审查和AI生成提交信息",
5
5
  "main": "bin/git-ai.js",
6
6
  "bin": {