feat: better diff. integration

This commit is contained in:
2026-02-16 12:03:22 +01:00
parent 9d71aa63fb
commit c5c3a55a5c
14 changed files with 336 additions and 33 deletions

View File

@@ -41,6 +41,20 @@ export interface GitDiffDto {
patch: string;
}
export interface GitDiffContentDto {
filePath: string;
original: string;
modified: string;
}
export interface GitHistoryEntry {
hash: string;
shortHash: string;
date: string;
subject: string;
author: string;
}
export type GitInitPhase =
| 'checking-git'
| 'initializing-repo'
@@ -232,6 +246,34 @@ export class GitEngine {
};
}
async getDiffContent(projectPath: string, filePath: string): Promise<GitDiffContentDto> {
const git = simpleGit(projectPath);
const [original, modified] = await Promise.all([
git.show([`HEAD:${filePath}`]).catch(() => ''),
fsPromises.readFile(path.join(projectPath, filePath), 'utf8').catch(() => ''),
]);
return {
filePath,
original,
modified,
};
}
async getHistory(projectPath: string, limit = 20): Promise<GitHistoryEntry[]> {
const git = simpleGit(projectPath);
const history = await git.log({ maxCount: limit });
return history.all.map((entry) => ({
hash: entry.hash,
shortHash: entry.hash.slice(0, 7),
date: entry.date,
subject: entry.message,
author: entry.author_name,
}));
}
async ensureGitignore(projectPath: string): Promise<GitIgnoreEnsureResult> {
const gitignorePath = path.join(projectPath, '.gitignore');