feat: phase 3 for git integration
This commit is contained in:
@@ -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');
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ export {
|
||||
type GitAvailability,
|
||||
type RepoState,
|
||||
type GitStatusDto,
|
||||
type GitDiffDto,
|
||||
type GitStatusFile,
|
||||
type GitStatusCounts,
|
||||
type GitInitResult,
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user