Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d4a38f079 | ||
|
|
f3b65dbedf | ||
|
|
38667d323c | ||
|
|
e829f971ce | ||
|
|
37cd7be09b | ||
|
|
aa6412c3ba | ||
|
|
04d86b0559 | ||
|
|
d4447da322 | ||
|
|
2512721b13 | ||
|
|
07d5dc1f25 | ||
|
|
3125dd80a7 | ||
|
|
25579c9942 | ||
|
|
5caae992e3 | ||
|
|
beb9201f5d | ||
|
|
c129be5e21 | ||
|
|
5aaae6cb60 | ||
|
|
8b94f007f2 | ||
|
|
80ce01b8e6 |
No files matched your search
@@ -239,140 +239,6 @@ describe("git integration", () => {
|
||||
expect(current!.name).toBe("feature");
|
||||
});
|
||||
|
||||
it("refreshes upstream behind count after checkout when remote branch advanced", async () => {
|
||||
await using remote = await makeTmpDir();
|
||||
await using source = await makeTmpDir();
|
||||
await using clone = await makeTmpDir();
|
||||
await git(remote.path, "init --bare");
|
||||
|
||||
await initRepoWithCommit(source.path);
|
||||
const defaultBranch = (await listGitBranches({ cwd: source.path })).branches.find(
|
||||
(branch) => branch.current,
|
||||
)!.name;
|
||||
await git(source.path, `remote add origin ${JSON.stringify(remote.path)}`);
|
||||
await git(source.path, `push -u origin ${defaultBranch}`);
|
||||
|
||||
const featureBranch = "feature-behind";
|
||||
await createGitBranch({ cwd: source.path, branch: featureBranch });
|
||||
await checkoutGitBranch({ cwd: source.path, branch: featureBranch });
|
||||
await writeFile(path.join(source.path, "feature.txt"), "feature base\n");
|
||||
await git(source.path, "add feature.txt");
|
||||
await git(source.path, "commit -m 'feature base'");
|
||||
await git(source.path, `push -u origin ${featureBranch}`);
|
||||
await checkoutGitBranch({ cwd: source.path, branch: defaultBranch });
|
||||
|
||||
await git(clone.path, `clone ${JSON.stringify(remote.path)} .`);
|
||||
await git(clone.path, "config user.email '[email protected]'");
|
||||
await git(clone.path, "config user.name 'Test'");
|
||||
await git(clone.path, `checkout -b ${featureBranch} --track origin/${featureBranch}`);
|
||||
await writeFile(path.join(clone.path, "feature.txt"), "feature from remote\n");
|
||||
await git(clone.path, "add feature.txt");
|
||||
await git(clone.path, "commit -m 'remote feature update'");
|
||||
await git(clone.path, `push origin ${featureBranch}`);
|
||||
|
||||
await checkoutGitBranch({ cwd: source.path, branch: featureBranch });
|
||||
const core = new GitCoreService();
|
||||
const details = await core.statusDetails(source.path);
|
||||
|
||||
expect(details.branch).toBe(featureBranch);
|
||||
expect(details.aheadCount).toBe(0);
|
||||
expect(details.behindCount).toBe(1);
|
||||
});
|
||||
|
||||
it("keeps checkout successful when upstream refresh fails", async () => {
|
||||
await using remote = await makeTmpDir();
|
||||
await using source = await makeTmpDir();
|
||||
await git(remote.path, "init --bare");
|
||||
|
||||
await initRepoWithCommit(source.path);
|
||||
const defaultBranch = (await listGitBranches({ cwd: source.path })).branches.find(
|
||||
(branch) => branch.current,
|
||||
)!.name;
|
||||
await git(source.path, `remote add origin ${JSON.stringify(remote.path)}`);
|
||||
await git(source.path, `push -u origin ${defaultBranch}`);
|
||||
|
||||
const featureBranch = "feature-refresh-failure";
|
||||
await git(source.path, `branch ${featureBranch}`);
|
||||
await git(source.path, `checkout ${featureBranch}`);
|
||||
await writeFile(path.join(source.path, "feature.txt"), "feature base\n");
|
||||
await git(source.path, "add feature.txt");
|
||||
await git(source.path, "commit -m 'feature base'");
|
||||
await git(source.path, `push -u origin ${featureBranch}`);
|
||||
await git(source.path, `checkout ${defaultBranch}`);
|
||||
|
||||
class RefreshFailingGitCoreService extends GitCoreService {
|
||||
refreshFetchAttempts = 0;
|
||||
|
||||
override async git(
|
||||
cwd: string,
|
||||
args: readonly string[],
|
||||
allowNonZeroExit = false,
|
||||
): Promise<void> {
|
||||
if (args[0] === "fetch") {
|
||||
this.refreshFetchAttempts += 1;
|
||||
throw new Error("simulated fetch timeout");
|
||||
}
|
||||
await super.git(cwd, args, allowNonZeroExit);
|
||||
}
|
||||
}
|
||||
|
||||
const core = new RefreshFailingGitCoreService();
|
||||
await expect(core.checkoutBranch({ cwd: source.path, branch: featureBranch })).resolves.toBe(
|
||||
undefined,
|
||||
);
|
||||
expect(core.refreshFetchAttempts).toBe(1);
|
||||
expect(await git(source.path, "branch --show-current")).toBe(featureBranch);
|
||||
});
|
||||
|
||||
it("refresh fetch is scoped to the checked out branch upstream refspec", async () => {
|
||||
await using remote = await makeTmpDir();
|
||||
await using source = await makeTmpDir();
|
||||
await git(remote.path, "init --bare");
|
||||
|
||||
await initRepoWithCommit(source.path);
|
||||
const defaultBranch = (await listGitBranches({ cwd: source.path })).branches.find(
|
||||
(branch) => branch.current,
|
||||
)!.name;
|
||||
await git(source.path, `remote add origin ${JSON.stringify(remote.path)}`);
|
||||
await git(source.path, `push -u origin ${defaultBranch}`);
|
||||
|
||||
const featureBranch = "feature/scoped-fetch";
|
||||
await git(source.path, `checkout -b ${featureBranch}`);
|
||||
await writeFile(path.join(source.path, "feature.txt"), "feature base\n");
|
||||
await git(source.path, "add feature.txt");
|
||||
await git(source.path, "commit -m 'feature base'");
|
||||
await git(source.path, `push -u origin ${featureBranch}`);
|
||||
await git(source.path, `checkout ${defaultBranch}`);
|
||||
|
||||
class FetchRecordingGitCoreService extends GitCoreService {
|
||||
fetchArgs: readonly string[] | null = null;
|
||||
|
||||
override async git(
|
||||
cwd: string,
|
||||
args: readonly string[],
|
||||
allowNonZeroExit = false,
|
||||
): Promise<void> {
|
||||
if (args[0] === "fetch") {
|
||||
this.fetchArgs = args;
|
||||
return;
|
||||
}
|
||||
await super.git(cwd, args, allowNonZeroExit);
|
||||
}
|
||||
}
|
||||
|
||||
const core = new FetchRecordingGitCoreService();
|
||||
await core.checkoutBranch({ cwd: source.path, branch: featureBranch });
|
||||
|
||||
expect(await git(source.path, "branch --show-current")).toBe(featureBranch);
|
||||
expect(core.fetchArgs).toEqual([
|
||||
"fetch",
|
||||
"--quiet",
|
||||
"--no-tags",
|
||||
"origin",
|
||||
`+refs/heads/${featureBranch}:refs/remotes/origin/${featureBranch}`,
|
||||
]);
|
||||
});
|
||||
|
||||
it("throws when branch does not exist", async () => {
|
||||
await using tmp = await makeTmpDir();
|
||||
await initRepoWithCommit(tmp.path);
|
||||
|
||||
@@ -553,45 +553,11 @@ export class GitCoreService {
|
||||
});
|
||||
}
|
||||
|
||||
private async refreshCheckedOutBranchUpstream(cwd: string): Promise<void> {
|
||||
const upstreamRef = trimStdout(
|
||||
await this.gitStdout(
|
||||
cwd,
|
||||
["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"],
|
||||
true,
|
||||
),
|
||||
);
|
||||
if (upstreamRef.length === 0 || upstreamRef === "@{upstream}") {
|
||||
return;
|
||||
}
|
||||
|
||||
const separatorIndex = upstreamRef.indexOf("/");
|
||||
if (separatorIndex <= 0) {
|
||||
return;
|
||||
}
|
||||
const remoteName = upstreamRef.slice(0, separatorIndex);
|
||||
const upstreamBranch = upstreamRef.slice(separatorIndex + 1);
|
||||
if (remoteName.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (upstreamBranch.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const refspec = `+refs/heads/${upstreamBranch}:refs/remotes/${upstreamRef}`;
|
||||
await this.git(cwd, ["fetch", "--quiet", "--no-tags", remoteName, refspec], true);
|
||||
}
|
||||
|
||||
async checkoutBranch(input: GitCheckoutInput): Promise<void> {
|
||||
await executeGit(input.cwd, ["checkout", input.branch], {
|
||||
timeoutMs: 10_000,
|
||||
fallbackErrorMessage: "git checkout failed",
|
||||
});
|
||||
try {
|
||||
await this.refreshCheckedOutBranchUpstream(input.cwd);
|
||||
} catch {
|
||||
// Best effort: checkout already succeeded, so avoid surfacing refresh failures.
|
||||
}
|
||||
}
|
||||
|
||||
async initRepo(input: GitInitInput): Promise<void> {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { QueryClient, QueryClientProvider, useQueryClient } from "@tanstack/react-query";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
import ChatView from "./components/ChatView";
|
||||
@@ -11,27 +11,22 @@ import { DEFAULT_THREAD_TERMINAL_HEIGHT, DEFAULT_THREAD_TERMINAL_ID } from "./ty
|
||||
import { onServerWelcome } from "./wsNativeApi";
|
||||
import { useNativeApi } from "./hooks/useNativeApi";
|
||||
import { AnchoredToastProvider, ToastProvider } from "./components/ui/toast";
|
||||
import { invalidateGitQueries } from "./lib/gitReactQuery";
|
||||
|
||||
function EventRouter() {
|
||||
const api = useNativeApi();
|
||||
const { dispatch } = useStore();
|
||||
const queryClient = useQueryClient();
|
||||
const activeAssistantItemRef = useRef<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!api) return;
|
||||
return api.providers.onEvent((event) => {
|
||||
if (event.method === "turn/completed") {
|
||||
void invalidateGitQueries(queryClient);
|
||||
}
|
||||
dispatch({
|
||||
type: "APPLY_EVENT",
|
||||
event,
|
||||
activeAssistantItemRef,
|
||||
});
|
||||
});
|
||||
}, [api, dispatch, queryClient]);
|
||||
}, [api, dispatch]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!api) return;
|
||||
|
||||
@@ -19,11 +19,8 @@ import {
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
gitBranchesQueryOptions,
|
||||
gitCreateWorktreeMutationOptions,
|
||||
} from "~/lib/gitReactQuery";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { gitBranchesQueryOptions } from "~/lib/gitReactQuery";
|
||||
|
||||
import { EDITORS, type EditorId } from "@t3tools/contracts";
|
||||
import { isElectron } from "../env";
|
||||
@@ -128,8 +125,6 @@ function readFileAsDataUrl(file: File): Promise<string> {
|
||||
export default function ChatView() {
|
||||
const { state, dispatch } = useStore();
|
||||
const api = useNativeApi();
|
||||
const queryClient = useQueryClient();
|
||||
const createWorktreeMutation = useMutation(gitCreateWorktreeMutationOptions({ api, queryClient }));
|
||||
const [prompt, setPrompt] = useState("");
|
||||
const [composerImages, setComposerImages] = useState<ComposerImageAttachment[]>([]);
|
||||
const [isDragOverComposer, setIsDragOverComposer] = useState(false);
|
||||
@@ -314,20 +309,14 @@ export default function ChatView() {
|
||||
const closeTerminal = useCallback(
|
||||
(terminalId: string) => {
|
||||
if (!activeThreadId || !api) return;
|
||||
const isFinalTerminal = (activeThread?.terminalIds.length ?? 0) <= 1;
|
||||
const fallbackExitWrite = () =>
|
||||
api.terminal
|
||||
.write({ threadId: activeThreadId, terminalId, data: "exit\n" })
|
||||
.catch(() => undefined);
|
||||
if ("close" in api.terminal && typeof api.terminal.close === "function") {
|
||||
void (async () => {
|
||||
if (isFinalTerminal) {
|
||||
await api.terminal
|
||||
.clear({ threadId: activeThreadId, terminalId })
|
||||
.catch(() => undefined);
|
||||
}
|
||||
await api.terminal.close({ threadId: activeThreadId, terminalId, deleteHistory: true });
|
||||
})().catch(() => fallbackExitWrite());
|
||||
void api.terminal
|
||||
.close({ threadId: activeThreadId, terminalId })
|
||||
.catch(() => fallbackExitWrite());
|
||||
} else {
|
||||
void fallbackExitWrite();
|
||||
}
|
||||
@@ -338,7 +327,7 @@ export default function ChatView() {
|
||||
});
|
||||
setTerminalFocusRequestId((value) => value + 1);
|
||||
},
|
||||
[activeThread?.terminalIds.length, activeThreadId, api, dispatch],
|
||||
[activeThreadId, api, dispatch],
|
||||
);
|
||||
|
||||
const handleRuntimeModeChange = async (mode: "approval-required" | "full-access") => {
|
||||
@@ -674,7 +663,7 @@ export default function ChatView() {
|
||||
) {
|
||||
try {
|
||||
const newBranch = `codething/${crypto.randomUUID().slice(0, 8)}`;
|
||||
const result = await createWorktreeMutation.mutateAsync({
|
||||
const result = await api.git.createWorktree({
|
||||
cwd: activeProject.cwd,
|
||||
branch: activeThread.branch,
|
||||
newBranch,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { GitStatusResult } from "@t3tools/contracts";
|
||||
import { assert, describe, it } from "vitest";
|
||||
import {
|
||||
buildGitActionProgressStages,
|
||||
buildMenuItems,
|
||||
requiresDefaultBranchConfirmation,
|
||||
resolveQuickAction,
|
||||
@@ -597,33 +596,6 @@ describe("requiresDefaultBranchConfirmation", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildGitActionProgressStages", () => {
|
||||
it("shows only push progress when push-only is forced", () => {
|
||||
const stages = buildGitActionProgressStages({
|
||||
action: "commit_push",
|
||||
hasCustomCommitMessage: false,
|
||||
hasWorkingTreeChanges: true,
|
||||
forcePushOnly: true,
|
||||
pushTarget: "origin/feature/test",
|
||||
});
|
||||
assert.deepEqual(stages, ["Pushing to origin/feature/test..."]);
|
||||
});
|
||||
|
||||
it("includes commit stages for commit+push when working tree is dirty", () => {
|
||||
const stages = buildGitActionProgressStages({
|
||||
action: "commit_push",
|
||||
hasCustomCommitMessage: false,
|
||||
hasWorkingTreeChanges: true,
|
||||
pushTarget: "origin/feature/test",
|
||||
});
|
||||
assert.deepEqual(stages, [
|
||||
"Generating commit message...",
|
||||
"Committing...",
|
||||
"Pushing to origin/feature/test...",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("summarizeGitResult", () => {
|
||||
it("returns commit-focused toast for commit action", () => {
|
||||
const result = summarizeGitResult({
|
||||
|
||||
@@ -43,30 +43,6 @@ function truncateText(
|
||||
return `${value.slice(0, Math.max(0, maxLength - 3)).trimEnd()}...`;
|
||||
}
|
||||
|
||||
export function buildGitActionProgressStages(input: {
|
||||
action: GitStackedAction;
|
||||
hasCustomCommitMessage: boolean;
|
||||
hasWorkingTreeChanges: boolean;
|
||||
forcePushOnly?: boolean;
|
||||
pushTarget?: string;
|
||||
}): string[] {
|
||||
const shouldIncludeCommitStages =
|
||||
!input.forcePushOnly && (input.action === "commit" || input.hasWorkingTreeChanges);
|
||||
const commitStages = !shouldIncludeCommitStages
|
||||
? []
|
||||
: input.hasCustomCommitMessage
|
||||
? ["Committing..."]
|
||||
: ["Generating commit message...", "Committing..."];
|
||||
const pushStage = input.pushTarget ? `Pushing to ${input.pushTarget}...` : "Pushing...";
|
||||
if (input.action === "commit") {
|
||||
return commitStages;
|
||||
}
|
||||
if (input.action === "commit_push") {
|
||||
return [...commitStages, pushStage];
|
||||
}
|
||||
return [...commitStages, pushStage, "Creating PR..."];
|
||||
}
|
||||
|
||||
export function summarizeGitResult(result: GitRunStackedActionResult): {
|
||||
title: string;
|
||||
description?: string;
|
||||
@@ -231,7 +207,7 @@ export function resolveQuickAction(
|
||||
label: "Commit",
|
||||
disabled: true,
|
||||
kind: "show_hint",
|
||||
hint: "Branch is up to date. No action needed.",
|
||||
hint: "Branch is up to date. Nothing to commit, push, pull, or open as a PR.",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import { useCallback, useMemo, useState } from "react";
|
||||
import { ChevronDownIcon, CloudUploadIcon, GitCommitIcon, InfoIcon } from "lucide-react";
|
||||
import { GitHubIcon } from "./Icons";
|
||||
import {
|
||||
buildGitActionProgressStages,
|
||||
buildMenuItems,
|
||||
type GitActionIconName,
|
||||
type GitActionMenuItem,
|
||||
@@ -135,6 +134,26 @@ function GitQuickActionIcon({ quickAction }: { quickAction: GitQuickAction }) {
|
||||
return <InfoIcon className={iconClassName} />;
|
||||
}
|
||||
|
||||
function buildGitActionProgressStages(input: {
|
||||
action: GitStackedAction;
|
||||
hasCustomCommitMessage: boolean;
|
||||
hasWorkingTreeChanges: boolean;
|
||||
}): string[] {
|
||||
const shouldIncludeCommitStages = input.action === "commit" || input.hasWorkingTreeChanges;
|
||||
const commitStages = !shouldIncludeCommitStages
|
||||
? []
|
||||
: input.hasCustomCommitMessage
|
||||
? ["Committing..."]
|
||||
: ["Generating commit message...", "Committing..."];
|
||||
if (input.action === "commit") {
|
||||
return commitStages;
|
||||
}
|
||||
if (input.action === "commit_push") {
|
||||
return [...commitStages, "Pushing..."];
|
||||
}
|
||||
return [...commitStages, "Pushing...", "Creating PR..."];
|
||||
}
|
||||
|
||||
export default function GitActionsControl({ api, gitCwd }: GitActionsControlProps) {
|
||||
const queryClient = useQueryClient();
|
||||
const [activeDialogAction, setActiveDialogAction] = useState<GitDialogAction | null>(null);
|
||||
@@ -211,28 +230,14 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
}, [api, gitStatus?.openPr?.url]);
|
||||
|
||||
const runGitActionWithToast = useCallback(
|
||||
async ({
|
||||
action,
|
||||
commitMessage,
|
||||
forcePushOnlyProgress = false,
|
||||
onConfirmed,
|
||||
}: {
|
||||
action: GitStackedAction;
|
||||
commitMessage?: string;
|
||||
forcePushOnlyProgress?: boolean;
|
||||
onConfirmed?: () => void;
|
||||
}) => {
|
||||
async ({ action, commitMessage }: { action: GitStackedAction; commitMessage?: string }) => {
|
||||
const confirmed = await maybeConfirmPushToDefaultBranch(action);
|
||||
if (!confirmed) return;
|
||||
onConfirmed?.();
|
||||
|
||||
const pushTarget = gitStatus?.branch ? `origin/${gitStatus.branch}` : undefined;
|
||||
const progressStages = buildGitActionProgressStages({
|
||||
action,
|
||||
hasCustomCommitMessage: !!commitMessage?.trim(),
|
||||
hasWorkingTreeChanges: !!gitStatus?.hasWorkingTreeChanges,
|
||||
forcePushOnly: forcePushOnlyProgress,
|
||||
...(pushTarget ? { pushTarget } : {}),
|
||||
});
|
||||
const progressToastId = toastManager.add({
|
||||
type: "loading",
|
||||
@@ -267,9 +272,9 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
const prUrl = result.pr.url ?? gitStatus?.openPr?.url;
|
||||
const shouldOfferPushCta = action === "commit" && result.commit.status === "created";
|
||||
const shouldOfferOpenPrCta =
|
||||
(action === "commit_push" || action === "commit_push_pr") && !!prUrl && !isDefaultBranch;
|
||||
(action === "commit_push" || action === "commit_push_pr") && !!prUrl;
|
||||
const shouldOfferCreatePrCta =
|
||||
action === "commit_push" && !prUrl && result.push.status === "pushed" && !isDefaultBranch;
|
||||
action === "commit_push" && !prUrl && result.push.status === "pushed";
|
||||
const closeResultToast = () => {
|
||||
toastManager.close(progressToastId);
|
||||
};
|
||||
@@ -284,11 +289,8 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
actionProps: {
|
||||
children: "Push",
|
||||
onClick: () => {
|
||||
void runGitActionWithToast({
|
||||
action: "commit_push",
|
||||
forcePushOnlyProgress: true,
|
||||
onConfirmed: closeResultToast,
|
||||
});
|
||||
closeResultToast();
|
||||
void runGitActionWithToast({ action: "commit_push" });
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -325,10 +327,8 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
},
|
||||
[
|
||||
api,
|
||||
gitStatus?.branch,
|
||||
gitStatus?.hasWorkingTreeChanges,
|
||||
gitStatus?.openPr?.url,
|
||||
isDefaultBranch,
|
||||
maybeConfirmPushToDefaultBranch,
|
||||
runImmediateGitActionMutation,
|
||||
setActiveDialogAction,
|
||||
@@ -380,7 +380,7 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
return;
|
||||
}
|
||||
if (item.dialogAction === "push") {
|
||||
void runGitActionWithToast({ action: "commit_push", forcePushOnlyProgress: true });
|
||||
void runGitActionWithToast({ action: "commit_push" });
|
||||
return;
|
||||
}
|
||||
if (item.dialogAction) {
|
||||
@@ -399,12 +399,10 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
? "commit_push"
|
||||
: "commit_push_pr";
|
||||
const commitMessage = activeDialogAction === "commit" ? dialogCommitMessage.trim() : "";
|
||||
const forcePushOnlyProgress = activeDialogAction === "push";
|
||||
setActiveDialogAction(null);
|
||||
void runGitActionWithToast({
|
||||
action,
|
||||
...(commitMessage ? { commitMessage } : {}),
|
||||
...(forcePushOnlyProgress ? { forcePushOnlyProgress } : {}),
|
||||
});
|
||||
}, [activeDialogAction, dialogCommitMessage, runGitActionWithToast]);
|
||||
|
||||
@@ -450,10 +448,10 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
openOnHover
|
||||
render={
|
||||
<Button
|
||||
aria-disabled="true"
|
||||
className="cursor-not-allowed rounded-e-none border-e-0 opacity-64 before:rounded-e-none"
|
||||
size="xs"
|
||||
variant="outline"
|
||||
size="xs"
|
||||
disabled={isGitActionRunning || quickAction.disabled}
|
||||
className="cursor-not-allowed disabled:cursor-not-allowed disabled:pointer-events-auto"
|
||||
/>
|
||||
}
|
||||
>
|
||||
@@ -487,7 +485,7 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
>
|
||||
<ChevronDownIcon aria-hidden="true" className="size-4" />
|
||||
</MenuTrigger>
|
||||
<MenuPopup align="end" className="w-full">
|
||||
<MenuPopup align="end" sideOffset={4}>
|
||||
{gitActionMenuItems.map((item) => {
|
||||
const disabledReason = getMenuActionDisabledReason(
|
||||
item,
|
||||
@@ -499,10 +497,9 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
<Popover key={`${item.id}-${item.label}`}>
|
||||
<PopoverTrigger
|
||||
openOnHover
|
||||
nativeButton={false}
|
||||
render={<span className="block w-max cursor-not-allowed" />}
|
||||
render={<span className="inline-flex w-full cursor-not-allowed" />}
|
||||
>
|
||||
<MenuItem className="w-full" disabled>
|
||||
<MenuItem disabled>
|
||||
<GitActionItemIcon icon={item.icon} />
|
||||
{item.label}
|
||||
</MenuItem>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { MonitorIcon, MoonIcon, SunIcon, TerminalIcon } from "lucide-react";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { isElectron } from "../env";
|
||||
import { useTheme } from "../hooks/useTheme";
|
||||
import { DEFAULT_MODEL } from "../model-logic";
|
||||
@@ -13,7 +12,6 @@ import {
|
||||
type Thread,
|
||||
} from "../types";
|
||||
import { useNativeApi } from "../hooks/useNativeApi";
|
||||
import { gitRemoveWorktreeMutationOptions } from "../lib/gitReactQuery";
|
||||
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup";
|
||||
|
||||
const THEME_CYCLE = { system: "light", light: "dark", dark: "system" } as const;
|
||||
@@ -112,8 +110,6 @@ function terminalStatusIndicator(thread: Thread): TerminalStatusIndicator | null
|
||||
export default function Sidebar() {
|
||||
const { state, dispatch } = useStore();
|
||||
const api = useNativeApi();
|
||||
const queryClient = useQueryClient();
|
||||
const removeWorktreeMutation = useMutation(gitRemoveWorktreeMutationOptions({ api, queryClient }));
|
||||
const { theme, setTheme } = useTheme();
|
||||
const [addingProject, setAddingProject] = useState(false);
|
||||
const [newCwd, setNewCwd] = useState("");
|
||||
@@ -311,7 +307,7 @@ export default function Sidebar() {
|
||||
}
|
||||
|
||||
try {
|
||||
await removeWorktreeMutation.mutateAsync({
|
||||
await api.git.removeWorktree({
|
||||
cwd: threadProject.cwd,
|
||||
path: orphanedWorktreePath,
|
||||
});
|
||||
@@ -319,7 +315,7 @@ export default function Sidebar() {
|
||||
// Worktree deletion is best-effort and should not block thread deletion.
|
||||
}
|
||||
},
|
||||
[api, dispatch, removeWorktreeMutation, state.projects, state.threads],
|
||||
[api, dispatch, state.projects, state.threads],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -108,7 +108,7 @@ export function gitRunStackedActionMutationOptions(input: {
|
||||
...(commitMessage ? { commitMessage } : {}),
|
||||
});
|
||||
},
|
||||
onSettled: async () => {
|
||||
onSuccess: async () => {
|
||||
await invalidateGitQueries(input.queryClient);
|
||||
},
|
||||
});
|
||||
@@ -124,49 +124,7 @@ export function gitPullMutationOptions(input: {
|
||||
if (!input.api || !input.cwd) throw new Error("Git pull is unavailable.");
|
||||
return input.api.git.pull({ cwd: input.cwd });
|
||||
},
|
||||
onSettled: async () => {
|
||||
await invalidateGitQueries(input.queryClient);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function gitCreateWorktreeMutationOptions(input: {
|
||||
api: NativeApi | undefined;
|
||||
queryClient: QueryClient;
|
||||
}) {
|
||||
return mutationOptions({
|
||||
mutationFn: async ({
|
||||
cwd,
|
||||
branch,
|
||||
newBranch,
|
||||
}: {
|
||||
cwd: string;
|
||||
branch: string;
|
||||
newBranch: string;
|
||||
}) => {
|
||||
if (!input.api) {
|
||||
throw new Error("Git worktree creation is unavailable.");
|
||||
}
|
||||
return input.api.git.createWorktree({ cwd, branch, newBranch });
|
||||
},
|
||||
onSettled: async () => {
|
||||
await invalidateGitQueries(input.queryClient);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function gitRemoveWorktreeMutationOptions(input: {
|
||||
api: NativeApi | undefined;
|
||||
queryClient: QueryClient;
|
||||
}) {
|
||||
return mutationOptions({
|
||||
mutationFn: async ({ cwd, path }: { cwd: string; path: string }) => {
|
||||
if (!input.api) {
|
||||
throw new Error("Git worktree removal is unavailable.");
|
||||
}
|
||||
return input.api.git.removeWorktree({ cwd, path });
|
||||
},
|
||||
onSettled: async () => {
|
||||
onSuccess: async () => {
|
||||
await invalidateGitQueries(input.queryClient);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -269,7 +269,6 @@ function closeThreadTerminal(thread: Thread, terminalId: string): Thread {
|
||||
|
||||
const remainingTerminalIds = thread.terminalIds.filter((id) => id !== terminalId);
|
||||
if (remainingTerminalIds.length === 0) {
|
||||
const nextTerminalGroupId = fallbackGroupId(DEFAULT_THREAD_TERMINAL_ID);
|
||||
return normalizeThreadTerminals({
|
||||
...thread,
|
||||
terminalOpen: false,
|
||||
@@ -278,11 +277,11 @@ function closeThreadTerminal(thread: Thread, terminalId: string): Thread {
|
||||
activeTerminalId: DEFAULT_THREAD_TERMINAL_ID,
|
||||
terminalGroups: [
|
||||
{
|
||||
id: nextTerminalGroupId,
|
||||
id: fallbackGroupId(DEFAULT_THREAD_TERMINAL_ID),
|
||||
terminalIds: [DEFAULT_THREAD_TERMINAL_ID],
|
||||
},
|
||||
],
|
||||
activeTerminalGroupId: nextTerminalGroupId,
|
||||
activeTerminalGroupId: fallbackGroupId(DEFAULT_THREAD_TERMINAL_ID),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user