Skip to content

Commit 15bcf77

Browse files
feat(svn): 当存在未跟踪文件时显示内容预览
当SVN工作目录中存在未跟踪文件时,现在会显示前3个文件的内容预览(针对小文件)或文件类型信息。这有助于开发者快速了解未跟踪文件的内容,而无需手动检查每个文件。
1 parent 5de97ab commit 15bcf77

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/utils/svn.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,44 @@ export async function getSvnWorkingState(cwd: string): Promise<{
453453
// Diff might not be available
454454
}
455455

456+
// If diff is empty but we have untracked files, provide additional information
457+
if (!diff.trim() && status.trim()) {
458+
const untrackedFiles = status
459+
.split("\n")
460+
.filter((line) => line.trim().startsWith("?"))
461+
.map((line) => line.trim().substring(1).trim())
462+
463+
if (untrackedFiles.length > 0) {
464+
console.log("[DEBUG] Found untracked files, attempting to show content preview")
465+
let additionalInfo = "\n\nNote: The following files are untracked (not under version control):\n"
466+
467+
for (const file of untrackedFiles.slice(0, 3)) {
468+
// Limit to first 3 files
469+
try {
470+
const filePath = path.resolve(cwd, file)
471+
const stats = await fs.stat(filePath)
472+
473+
if (stats.isFile() && stats.size < 10000) {
474+
// Only show content for small files
475+
const content = await fs.readFile(filePath, "utf-8")
476+
const preview = content.length > 500 ? content.substring(0, 500) + "..." : content
477+
additionalInfo += `\n--- Content of ${file} ---\n${preview}\n`
478+
} else {
479+
additionalInfo += `\n--- ${file} (${stats.isFile() ? "file" : "directory"}) ---\n`
480+
}
481+
} catch (error) {
482+
additionalInfo += `\n--- ${file} (unable to read: ${error.message}) ---\n`
483+
}
484+
}
485+
486+
if (untrackedFiles.length > 3) {
487+
additionalInfo += `\n... and ${untrackedFiles.length - 3} more untracked files`
488+
}
489+
490+
diff = additionalInfo
491+
}
492+
}
493+
456494
const result = { status, diff }
457495
console.log("[DEBUG] getSvnWorkingState returning:", JSON.stringify(result))
458496
return result

0 commit comments

Comments
 (0)