Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,8 +17,6 @@ export class GitOperations {
*/
async getConflictedFiles(): Promise<string[]> {
try {
await this.git.status();

const diffOutput = await this.git.diff(['--name-only', '--diff-filter=U']);
const files = diffOutput
.split('\n')
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -15,7 +17,7 @@ export class ConflictResolver {
*/
async openInEditor(filePath: string): Promise<void> {
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+/);
Expand Down Expand Up @@ -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 {
Expand All @@ -84,7 +86,7 @@ export class ConflictResolver {
*/
async getConflictCount(filePath: string): Promise<number> {
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;
Expand Down