From c5ca300fda5114b89b73372140b75834c9bf0ea9 Mon Sep 17 00:00:00 2001 From: Sulthonzh Date: Thu, 4 Jun 2026 06:16:02 +0700 Subject: [PATCH] fix: path resolution uses workingDir, eliminate wasted git status call, optimize getConflictStatus - ConflictResolver now stores workingDir and uses it for all resolve() calls (fixes files not found when cwd differs from git working directory) - Removed unused git.status() call in getConflictedFiles (was discarded anyway) - getConflictStatus runs getConflictedFiles + getMergeInfo in parallel - Removed unused StatusFile interface --- src/git.ts | 14 +++++--------- src/resolver.ts | 8 +++++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/git.ts b/src/git.ts index 110dcf7..eea5730 100644 --- a/src/git.ts +++ b/src/git.ts @@ -3,11 +3,6 @@ import { resolve } from 'path'; import { readFile } from 'fs/promises'; import { existsSync } from 'fs'; -interface StatusFile { - index: string; - path: string; -} - export class GitOperations { private git: SimpleGit; private workingDir: string; @@ -22,8 +17,6 @@ export class GitOperations { */ async getConflictedFiles(): Promise { try { - await this.git.status(); - const diffOutput = await this.git.diff(['--name-only', '--diff-filter=U']); const files = diffOutput .split('\n') @@ -217,8 +210,11 @@ export class GitOperations { mergeMessage?: string; operation?: string; }> { - const files = await this.getConflictedFiles(); - const info = await this.getMergeInfo(); + // Get conflicts and branch in parallel to avoid sequential git calls + const [files, info] = await Promise.all([ + this.getConflictedFiles(), + this.getMergeInfo(), + ]); return { hasConflicts: files.length > 0, files, diff --git a/src/resolver.ts b/src/resolver.ts index 8c85808..5959622 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -5,8 +5,10 @@ import { GitOperations } from './git'; export class ConflictResolver { private gitOps: GitOperations; + private workingDir: string; constructor(cwd?: string) { + this.workingDir = cwd ? resolve(cwd) : process.cwd(); this.gitOps = new GitOperations(cwd); } @@ -15,7 +17,7 @@ export class ConflictResolver { */ async openInEditor(filePath: string): Promise { const editor = process.env.EDITOR || process.env.VISUAL || this.getDefaultEditor(); - const fullPath = resolve(filePath); + const fullPath = resolve(this.workingDir, filePath); // Split editor command to handle flags like "code --wait" or "vim -f" const parts = editor.split(/\s+/); @@ -61,7 +63,7 @@ export class ConflictResolver { */ async validateResolution(filePath: string): Promise<{ valid: boolean; reason?: string }> { try { - const content = await readFile(resolve(filePath), 'utf-8'); + const content = await readFile(resolve(this.workingDir, filePath), 'utf-8'); if (this.gitOps.hasConflictMarkers(content)) { return { @@ -84,7 +86,7 @@ export class ConflictResolver { */ async getConflictCount(filePath: string): Promise { try { - const content = await readFile(resolve(filePath), 'utf-8'); + const content = await readFile(resolve(this.workingDir, filePath), 'utf-8'); return this.gitOps.countConflicts(content); } catch { return 0;