feat: commit push/pull/fetch and others
This commit is contained in:
@@ -98,6 +98,11 @@ export interface GitLfsPruneResult {
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface GitActionResult {
|
||||
success: boolean;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
let gitEngineInstance: GitEngine | null = null;
|
||||
|
||||
export function getGitEngine(): GitEngine {
|
||||
@@ -274,6 +279,67 @@ export class GitEngine {
|
||||
}));
|
||||
}
|
||||
|
||||
async fetch(projectPath: string): Promise<GitActionResult> {
|
||||
const git = simpleGit(projectPath);
|
||||
try {
|
||||
await git.fetch(['--prune']);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to fetch remote updates.',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async pull(projectPath: string): Promise<GitActionResult> {
|
||||
const git = simpleGit(projectPath);
|
||||
try {
|
||||
await git.pull();
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to pull remote changes.',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async push(projectPath: string): Promise<GitActionResult> {
|
||||
const git = simpleGit(projectPath);
|
||||
try {
|
||||
await git.push();
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to push local commits.',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async commitAll(projectPath: string, message: string): Promise<GitActionResult> {
|
||||
const normalizedMessage = message.trim();
|
||||
if (!normalizedMessage) {
|
||||
return {
|
||||
success: false,
|
||||
error: 'Commit message is required.',
|
||||
};
|
||||
}
|
||||
|
||||
const git = simpleGit(projectPath);
|
||||
try {
|
||||
await git.add(['-A']);
|
||||
await git.commit(normalizedMessage);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to create commit.',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async ensureGitignore(projectPath: string): Promise<GitIgnoreEnsureResult> {
|
||||
const gitignorePath = path.join(projectPath, '.gitignore');
|
||||
|
||||
|
||||
@@ -63,6 +63,26 @@ export function registerIpcHandlers(): void {
|
||||
return engine.getHistory(projectPath, limit);
|
||||
});
|
||||
|
||||
safeHandle('git:fetch', async (_, projectPath: string) => {
|
||||
const engine = getGitEngine();
|
||||
return engine.fetch(projectPath);
|
||||
});
|
||||
|
||||
safeHandle('git:pull', async (_, projectPath: string) => {
|
||||
const engine = getGitEngine();
|
||||
return engine.pull(projectPath);
|
||||
});
|
||||
|
||||
safeHandle('git:push', async (_, projectPath: string) => {
|
||||
const engine = getGitEngine();
|
||||
return engine.push(projectPath);
|
||||
});
|
||||
|
||||
safeHandle('git:commitAll', async (_, projectPath: string, message: string) => {
|
||||
const engine = getGitEngine();
|
||||
return engine.commitAll(projectPath, message);
|
||||
});
|
||||
|
||||
safeHandle('git:init', async (event, projectPath: string, remoteUrl?: string) => {
|
||||
const engine = getGitEngine();
|
||||
return engine.initializeRepo(projectPath, remoteUrl, (progress) => {
|
||||
|
||||
@@ -13,6 +13,10 @@ export const electronAPI: ElectronAPI = {
|
||||
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),
|
||||
fetch: (projectPath: string) => ipcRenderer.invoke('git:fetch', projectPath),
|
||||
pull: (projectPath: string) => ipcRenderer.invoke('git:pull', projectPath),
|
||||
push: (projectPath: string) => ipcRenderer.invoke('git:push', projectPath),
|
||||
commitAll: (projectPath: string, message: string) => ipcRenderer.invoke('git:commitAll', projectPath, message),
|
||||
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) => {
|
||||
|
||||
@@ -293,6 +293,11 @@ export interface GitLfsPruneResult {
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface GitActionResult {
|
||||
success: boolean;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
// Post-Media Link types
|
||||
export interface MediaLinkData {
|
||||
id: string;
|
||||
@@ -370,6 +375,10 @@ export interface ElectronAPI {
|
||||
getDiff: (projectPath: string, filePath: string) => Promise<GitDiffDto>;
|
||||
getDiffContent: (projectPath: string, filePath: string) => Promise<GitDiffContentDto>;
|
||||
getHistory: (projectPath: string, limit?: number) => Promise<GitHistoryEntry[]>;
|
||||
fetch: (projectPath: string) => Promise<GitActionResult>;
|
||||
pull: (projectPath: string) => Promise<GitActionResult>;
|
||||
push: (projectPath: string) => Promise<GitActionResult>;
|
||||
commitAll: (projectPath: string, message: string) => Promise<GitActionResult>;
|
||||
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