feat: phase 6 of git implementation

This commit is contained in:
2026-02-16 15:34:48 +01:00
parent 339e513a2d
commit e9743cb70f
8 changed files with 249 additions and 2 deletions

View File

@@ -69,6 +69,14 @@ export interface GitHistoryEntry {
syncStatus?: GitHistorySyncStatus;
}
export interface GitRemoteStateDto {
localBranch: string | null;
upstreamBranch: string | null;
hasUpstream: boolean;
ahead: number;
behind: number;
}
export type GitHistorySyncStatus = 'both' | 'local-only' | 'remote-only';
export type GitInitPhase =
@@ -711,6 +719,26 @@ export class GitEngine {
});
}
async getRemoteState(projectPath: string): Promise<GitRemoteStateDto> {
const git = simpleGit(projectPath);
const status = await git.status();
const localBranch = typeof status.current === 'string' && status.current.trim().length > 0
? status.current
: null;
const upstreamBranch = typeof status.tracking === 'string' && status.tracking.trim().length > 0
? status.tracking
: null;
return {
localBranch,
upstreamBranch,
hasUpstream: Boolean(upstreamBranch),
ahead: typeof status.ahead === 'number' ? status.ahead : Number(status.ahead ?? 0),
behind: typeof status.behind === 'number' ? status.behind : Number(status.behind ?? 0),
};
}
async fetch(projectPath: string): Promise<GitActionResult> {
const git = this.createNonInteractiveGit(projectPath);
try {

View File

@@ -68,6 +68,11 @@ export function registerIpcHandlers(): void {
return engine.getHistory(projectPath, limit);
});
safeHandle('git:remoteState', async (_, projectPath: string) => {
const engine = getGitEngine();
return engine.getRemoteState(projectPath);
});
safeHandle('git:fetch', async (_, projectPath: string) => {
const engine = getGitEngine();
return engine.fetch(projectPath);

View File

@@ -14,6 +14,7 @@ export const electronAPI: ElectronAPI = {
getDiffContent: (projectPath: string, filePath: string) => ipcRenderer.invoke('git:diffContent', projectPath, filePath),
getCommitDiffContent: (projectPath: string, commitHash: string) => ipcRenderer.invoke('git:commitDiffContent', projectPath, commitHash),
getHistory: (projectPath: string, limit?: number) => ipcRenderer.invoke('git:history', projectPath, limit),
getRemoteState: (projectPath: string) => ipcRenderer.invoke('git:remoteState', projectPath),
fetch: (projectPath: string) => ipcRenderer.invoke('git:fetch', projectPath),
pull: (projectPath: string) => ipcRenderer.invoke('git:pull', projectPath),
push: (projectPath: string) => ipcRenderer.invoke('git:push', projectPath),

View File

@@ -271,6 +271,14 @@ export interface GitHistoryEntry {
syncStatus?: GitHistorySyncStatus;
}
export interface GitRemoteStateDto {
localBranch: string | null;
upstreamBranch: string | null;
hasUpstream: boolean;
ahead: number;
behind: number;
}
export type GitInitPhase =
| 'checking-git'
| 'initializing-repo'
@@ -395,6 +403,7 @@ export interface ElectronAPI {
getDiffContent: (projectPath: string, filePath: string) => Promise<GitDiffContentDto>;
getCommitDiffContent: (projectPath: string, commitHash: string) => Promise<GitCommitDiffContentDto>;
getHistory: (projectPath: string, limit?: number) => Promise<GitHistoryEntry[]>;
getRemoteState: (projectPath: string) => Promise<GitRemoteStateDto>;
fetch: (projectPath: string) => Promise<GitActionResult>;
pull: (projectPath: string) => Promise<GitActionResult>;
push: (projectPath: string) => Promise<GitActionResult>;