Skip to content

Commit 65edf1d

Browse files
committed
refactor(git): Use async file exists check
- Replaced sync file check - Used FileSystemService - Fixed file path quoting
1 parent b21caa0 commit 65edf1d

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

services/aiService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ const AiService = {
7575
const blameAnalyses: string[] = [];
7676

7777
for (const file of changedFiles) {
78-
const analysisResult = GitBlameAnalyzer.analyzeChanges(file);
78+
// biome-ignore lint/nursery/noAwaitInLoop: <explanation>
79+
const analysisResult = await GitBlameAnalyzer.analyzeChanges(file);
7980
blameAnalyses.push(analysisResult);
8081
}
8182

services/gitBlameAnalyzer.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as fs from "node:fs";
21
import * as path from "node:path";
32
import { errorMessages, repoPath } from "../lib/constants.ts";
43
import { logError } from "../lib/Logger.ts";
54
import CommandService from "./commandService.ts";
5+
import FileSystemService from "./fileSystemService.ts";
66
import GitService from "./gitService.ts";
77

88
type BlameInfo = {
@@ -15,10 +15,10 @@ type BlameInfo = {
1515
};
1616

1717
const GitBlameAnalyzer = {
18-
getGitBlame(filePath: string): BlameInfo[] {
18+
async getGitBlame(filePath: string): Promise<BlameInfo[]> {
1919
try {
2020
const absoluteFilePath = path.resolve(repoPath as string, filePath);
21-
if (!fs.existsSync(absoluteFilePath)) {
21+
if (!(await FileSystemService.fileExists(absoluteFilePath))) {
2222
throw new Error(`${errorMessages.fileNotFound}: ${absoluteFilePath}`);
2323
}
2424

@@ -74,7 +74,7 @@ const GitBlameAnalyzer = {
7474
executeGitBlame(filePath: string): string {
7575
const { ok: output, error } = CommandService.execute(
7676
"git",
77-
["blame", "--line-porcelain", filePath],
77+
["blame", "--line-porcelain", filePath.replaceAll('"', "")],
7878
repoPath
7979
);
8080

@@ -92,7 +92,7 @@ const GitBlameAnalyzer = {
9292
if (error !== undefined) throw error;
9393
return output.stdout;
9494
},
95-
analyzeChanges(filePath: string): string {
95+
async analyzeChanges(filePath: string): Promise<string> {
9696
try {
9797
// First check if file is deleted or new, as these don't need blame analysis
9898
// Use git status to check file state
@@ -107,7 +107,7 @@ const GitBlameAnalyzer = {
107107
}
108108

109109
// For existing files, we need to get blame info
110-
const blame = GitBlameAnalyzer.getGitBlame(normalizedPath);
110+
const blame = await GitBlameAnalyzer.getGitBlame(normalizedPath);
111111

112112
const diff = GitBlameAnalyzer.getDiff(normalizedPath);
113113

0 commit comments

Comments
 (0)