fix: 修复 .lobsterignore 和变动行数计算

修复内容:
1. .lobsterignore 匹配
   - 修复目录匹配逻辑
   - 支持嵌套目录匹配(node_modules/, .git/, __pycache__/)
   - 正确处理目录下的文件

2. 变动行数计算
   - 修复空字符串处理
   - 空文件 -> 有内容正确计算
   - 有内容 -> 空文件正确计算

测试验证:
- test_simple.py 所有测试通过
- .lobsterignore 匹配正确
- 分块读取正常
- 变动行数计算准确
- 冲突判定逻辑完整(包含 HARD_CONFLICT)
This commit is contained in:
道童
2026-04-05 14:18:32 +00:00
parent 479d67923c
commit 3529c3647d
2 changed files with 394 additions and 7 deletions

View File

@@ -116,9 +116,16 @@ class IgnorePattern:
if fnmatch(relative_str, pattern):
return True
# 匹配目录
if pattern.endswith('/') and fnmatch(str(relative_path.parent), pattern.rstrip('/')):
return True
# 匹配目录(检查路径的每个部分)
if pattern.endswith('/') or pattern in ['node_modules', '__pycache__', '.git']:
# 检查路径中是否包含该目录
parts = relative_str.split(os.sep)
dir_pattern = pattern.rstrip('/')
if dir_pattern in parts:
return True
# 检查是否是该目录下的文件
if fnmatch(relative_str, f"{dir_pattern}/*"):
return True
# 递归匹配子目录
if pattern.startswith('*/'):
@@ -501,11 +508,15 @@ class DiffChecker:
Returns:
变动行数(+新增 -删除)
"""
old_lines = set(old_content.split('\n'))
new_lines = set(new_content.split('\n'))
# 处理空字符串
old_lines = old_content.split('\n') if old_content else []
new_lines = new_content.split('\n') if new_content else []
added = len(new_lines - old_lines)
removed = len(old_lines - new_lines)
old_set = set(old_lines)
new_set = set(new_lines)
added = len(new_set - old_set)
removed = len(old_set - new_set)
return added - removed