feat: phase 3 for git integration

This commit is contained in:
2026-02-16 11:46:47 +01:00
parent 4c437cbea2
commit 9d71aa63fb
18 changed files with 499 additions and 7 deletions

View File

@@ -36,6 +36,11 @@ export interface GitStatusDto {
counts: GitStatusCounts;
}
export interface GitDiffDto {
filePath: string;
patch: string;
}
export type GitInitPhase =
| 'checking-git'
| 'initializing-repo'
@@ -217,6 +222,16 @@ export class GitEngine {
};
}
async getDiff(projectPath: string, filePath: string): Promise<GitDiffDto> {
const git = simpleGit(projectPath);
const patch = await git.diff(['--', filePath]);
return {
filePath,
patch,
};
}
async ensureGitignore(projectPath: string): Promise<GitIgnoreEnsureResult> {
const gitignorePath = path.join(projectPath, '.gitignore');

View File

@@ -79,6 +79,7 @@ export {
type GitAvailability,
type RepoState,
type GitStatusDto,
type GitDiffDto,
type GitStatusFile,
type GitStatusCounts,
type GitInitResult,

View File

@@ -48,6 +48,11 @@ export function registerIpcHandlers(): void {
return engine.getStatus(projectPath);
});
safeHandle('git:diff', async (_, projectPath: string, filePath: string) => {
const engine = getGitEngine();
return engine.getDiff(projectPath, filePath);
});
safeHandle('git:init', async (event, projectPath: string, remoteUrl?: string) => {
const engine = getGitEngine();
return engine.initializeRepo(projectPath, remoteUrl, (progress) => {

View File

@@ -10,6 +10,7 @@ export const electronAPI: ElectronAPI = {
checkAvailability: () => ipcRenderer.invoke('git:checkAvailability'),
getRepoState: (projectPath: string) => ipcRenderer.invoke('git:getRepoState', projectPath),
getStatus: (projectPath: string) => ipcRenderer.invoke('git:status', projectPath),
getDiff: (projectPath: string, filePath: string) => ipcRenderer.invoke('git:diff', projectPath, filePath),
ensureGitignore: (projectPath: string) => ipcRenderer.invoke('git:ensureGitignore', projectPath),
pruneLfs: (projectPath: string, options?: { dryRun?: boolean; verifyRemote?: boolean }) => ipcRenderer.invoke('git:pruneLfs', projectPath, options),
init: (projectPath: string, remoteUrl?: string) => {

View File

@@ -236,6 +236,11 @@ export interface GitStatusDto {
counts: GitStatusCounts;
}
export interface GitDiffDto {
filePath: string;
patch: string;
}
export type GitInitPhase =
| 'checking-git'
| 'initializing-repo'
@@ -348,6 +353,7 @@ export interface ElectronAPI {
checkAvailability: () => Promise<GitAvailability>;
getRepoState: (projectPath: string) => Promise<GitRepoState>;
getStatus: (projectPath: string) => Promise<GitStatusDto>;
getDiff: (projectPath: string, filePath: string) => Promise<GitDiffDto>;
ensureGitignore: (projectPath: string) => Promise<GitIgnoreEnsureResult>;
pruneLfs: (projectPath: string, options?: { dryRun?: boolean; verifyRemote?: boolean }) => Promise<GitLfsPruneResult>;
init: (projectPath: string, remoteUrl?: string) => Promise<GitInitResult>;