feat: better diff. integration
This commit is contained in:
@@ -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');
|
||||
|
||||
|
||||
@@ -80,6 +80,8 @@ export {
|
||||
type RepoState,
|
||||
type GitStatusDto,
|
||||
type GitDiffDto,
|
||||
type GitDiffContentDto,
|
||||
type GitHistoryEntry,
|
||||
type GitStatusFile,
|
||||
type GitStatusCounts,
|
||||
type GitInitResult,
|
||||
|
||||
@@ -53,6 +53,16 @@ export function registerIpcHandlers(): void {
|
||||
return engine.getDiff(projectPath, filePath);
|
||||
});
|
||||
|
||||
safeHandle('git:diffContent', async (_, projectPath: string, filePath: string) => {
|
||||
const engine = getGitEngine();
|
||||
return engine.getDiffContent(projectPath, filePath);
|
||||
});
|
||||
|
||||
safeHandle('git:history', async (_, projectPath: string, limit?: number) => {
|
||||
const engine = getGitEngine();
|
||||
return engine.getHistory(projectPath, limit);
|
||||
});
|
||||
|
||||
safeHandle('git:init', async (event, projectPath: string, remoteUrl?: string) => {
|
||||
const engine = getGitEngine();
|
||||
return engine.initializeRepo(projectPath, remoteUrl, (progress) => {
|
||||
|
||||
@@ -11,6 +11,8 @@ export const electronAPI: ElectronAPI = {
|
||||
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),
|
||||
getDiffContent: (projectPath: string, filePath: string) => ipcRenderer.invoke('git:diffContent', projectPath, filePath),
|
||||
getHistory: (projectPath: string, limit?: number) => ipcRenderer.invoke('git:history', projectPath, limit),
|
||||
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) => {
|
||||
|
||||
@@ -241,6 +241,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'
|
||||
@@ -354,6 +368,8 @@ export interface ElectronAPI {
|
||||
getRepoState: (projectPath: string) => Promise<GitRepoState>;
|
||||
getStatus: (projectPath: string) => Promise<GitStatusDto>;
|
||||
getDiff: (projectPath: string, filePath: string) => Promise<GitDiffDto>;
|
||||
getDiffContent: (projectPath: string, filePath: string) => Promise<GitDiffContentDto>;
|
||||
getHistory: (projectPath: string, limit?: number) => Promise<GitHistoryEntry[]>;
|
||||
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