refactor: Improve all git operations, add stash support, add improved pull request flow, add worktree file copy options, address code review comments, add cherry pick options

This commit is contained in:
gsxdsm
2026-02-17 22:02:58 -08:00
parent f4e87d4c25
commit 9af63bc1ef
89 changed files with 6811 additions and 351 deletions

View File

@@ -126,10 +126,18 @@ export function usePushWorktree() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async ({ worktreePath, force }: { worktreePath: string; force?: boolean }) => {
mutationFn: async ({
worktreePath,
force,
remote,
}: {
worktreePath: string;
force?: boolean;
remote?: string;
}) => {
const api = getElectronAPI();
if (!api.worktree) throw new Error('Worktree API not available');
const result = await api.worktree.push(worktreePath, force);
const result = await api.worktree.push(worktreePath, force, remote);
if (!result.success) {
throw new Error(result.error || 'Failed to push changes');
}
@@ -156,10 +164,10 @@ export function usePullWorktree() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async (worktreePath: string) => {
mutationFn: async ({ worktreePath, remote }: { worktreePath: string; remote?: string }) => {
const api = getElectronAPI();
if (!api.worktree) throw new Error('Worktree API not available');
const result = await api.worktree.pull(worktreePath);
const result = await api.worktree.pull(worktreePath, remote);
if (!result.success) {
throw new Error(result.error || 'Failed to pull changes');
}
@@ -283,17 +291,6 @@ export function useMergeWorktree(projectPath: string) {
});
}
/**
* Result from the switch branch API call
*/
interface SwitchBranchResult {
previousBranch: string;
currentBranch: string;
message: string;
hasConflicts?: boolean;
stashedChanges?: boolean;
}
/**
* Switch to a different branch
*
@@ -316,14 +313,17 @@ export function useSwitchBranch(options?: {
}: {
worktreePath: string;
branchName: string;
}): Promise<SwitchBranchResult> => {
}) => {
const api = getElectronAPI();
if (!api.worktree) throw new Error('Worktree API not available');
const result = await api.worktree.switchBranch(worktreePath, branchName);
if (!result.success) {
throw new Error(result.error || 'Failed to switch branch');
}
return result.result as SwitchBranchResult;
if (!result.result) {
throw new Error('Switch branch returned no result');
}
return result.result;
},
onSuccess: (data, variables) => {
queryClient.invalidateQueries({ queryKey: ['worktrees'] });
@@ -388,6 +388,36 @@ export function useCheckoutBranch() {
});
}
/**
* Generate a PR title and description from branch diff
*
* @returns Mutation for generating a PR description
*/
export function useGeneratePRDescription() {
return useMutation({
mutationFn: async ({
worktreePath,
baseBranch,
}: {
worktreePath: string;
baseBranch?: string;
}) => {
const api = getElectronAPI();
if (!api.worktree) throw new Error('Worktree API not available');
const result = await api.worktree.generatePRDescription(worktreePath, baseBranch);
if (!result.success) {
throw new Error(result.error || 'Failed to generate PR description');
}
return { title: result.title ?? '', body: result.body ?? '' };
},
onError: (error: Error) => {
toast.error('Failed to generate PR description', {
description: error.message,
});
},
});
}
/**
* Generate a commit message from git diff
*