Compare commits

..
34 Commits
Author SHA1 Message Date
Julius Marminge 147f433d38 Scope branch refresh fetch to checked-out upstream refspec
- derive upstream branch from `branch@{upstream}` and guard empty values
- fetch only `+refs/heads/<branch>:refs/remotes/<remote>/<branch>` instead of all remote refs
- add integration test asserting scoped fetch args during `checkoutBranch`
2026-02-15 00:47:31 -08:00
Julius Marminge ca2acb078e Make checkout tolerate upstream refresh failures
- treat post-checkout upstream fetch as best effort so checkout still succeeds
- route refresh fetch through `this.git(...)` for consistent behavior
- add regression test for fetch-timeout during branch checkout
2026-02-15 00:33:36 -08:00
Julius Marminge 4c7720565c Refresh branch upstream after checkout and invalidate git queries
- fetch tracked remote after checkout to update ahead/behind counts
- add integration test for behind count when remote branch advances
- invalidate git React Query data on `turn/completed` events in the web app
2026-02-15 00:25:56 -08:00
Julius Marminge 1f4f693dd6 Shorten no-action hint text in Git actions control
- Replace verbose up-to-date hint with concise "No action needed" copy
2026-02-15 00:15:00 -08:00
Julius Marmingeandcodex 6e46a7be38 Hide drawer on final terminal close
Co-authored-by: codex <[email protected]>
2026-02-15 00:14:02 -08:00
Julius Marmingeandcodex 0be98ea9d1 Clear terminal viewport before final close
Co-authored-by: codex <[email protected]>
2026-02-15 00:11:56 -08:00
Julius Marmingeandcodex 2cd92ae6f5 Stop terminal close from auto-reopening with replayed history
Co-authored-by: codex <[email protected]>
2026-02-15 00:10:44 -08:00
Julius Marmingeandcodex 85fe41bad0 Fix terminal close behavior without toggling drawer
Co-authored-by: codex <[email protected]>
2026-02-15 00:07:10 -08:00
Julius Marminge 0c26396f79 Omit empty push target and track branch in action deps
- Only include `pushTarget` in analytics payload when it exists
- Add `gitStatus.branch` to callback dependencies to keep telemetry current
2026-02-15 00:02:35 -08:00
Julius Marminge cc37865c2d Show push target in Git action progress stages
- Include branch-based remote target in push progress text
- Update logic and tests for commit+push and force-push flows
2026-02-15 00:02:01 -08:00
Julius Marminge a6b9ece840 Use React Query mutations for git worktree operations
- Route worktree create/remove calls through shared git mutation options
- Invalidate git queries on mutation settle to keep branch/worktree data fresh
- Update chat and sidebar flows to use `mutateAsync` for worktree actions
2026-02-15 00:00:41 -08:00
Julius Marminge 65ab532342 Fix toast CTA indentation in GitActionsControl 2026-02-14 23:57:17 -08:00
Julius Marminge cce74f913c Close result toast only after push confirmation
- Add optional `onConfirmed` callback to `runGitActionWithToast`
- Use it from the Push CTA so the existing toast is closed only after user confirms push
2026-02-14 23:57:11 -08:00
Julius Marminge 170c3a7162 Fix push-only progress stages in Git action toasts
- Move `buildGitActionProgressStages` into shared logic for reuse and tests
- Add `forcePushOnly` path so push actions show only `Pushing...`
- Cover push-only and commit+push stage behavior with new logic tests
2026-02-14 23:55:46 -08:00
Julius Marminge 1fe3cf53a7 Hide PR CTAs on default branch and make git invalidation non-blocking
- Only show open/create PR actions after push on non-default branches
- Fire git query invalidation without awaiting mutation success handlers
- Tweak disabled button classes to keep split-button borders/radii aligned
2026-02-14 23:53:29 -08:00
Julius Marminge 07187d3794 Refine disabled git action styling and menu width
- Style disabled quick-action trigger with `aria-disabled` so hover tooltip still works
- Make git action menu popup/items use full-width layout for cleaner alignment
2026-02-14 23:49:43 -08:00
Julius Marminge 758df838d9 kewl 2026-02-14 23:35:48 -08:00
Julius Marminge 669168d08a Polish action button icons and hover tooltips
- Standardize quick action icon sizing and label spacing in chat and git controls
- Replace manual popover hover state handling with `openOnHover` triggers
- Add reusable terminal action button wrapper with hover tooltips for split/new/close controls
2026-02-14 23:35:48 -08:00
Julius Marminge 9bd663be7f Add inline branch creation to branch picker search
- let users create a new local branch directly from the branch combobox search
- remove separate "New branch" form/button flow in `BranchToolbar`
- add `inputClassName` support to `ComboboxInput` for native input styling control
2026-02-14 23:35:48 -08:00
Julius Marminge 58d926fcfb Use action maps for Git dialog title and description
- Replace nested conditional strings with action-to-copy lookup objects
- Keep commit/push/create PR dialog text centralized and easier to maintain
2026-02-14 23:35:48 -08:00
Julius Marminge b5149f5959 Close git action toast before triggering follow-up action
- Dismiss the success toast before handling Push/Open PR/Create PR CTA clicks
- Prevent stale result toasts from lingering while starting the next git action
2026-02-14 23:35:48 -08:00
Julius Marminge ea661fb635 Keep git action success toast visible until dismissed
- set success toast timeout in `GitActionsControl` from `5_000` to `0`
- keeps post-action feedback and push CTA available until user closes it
2026-02-14 23:35:48 -08:00
Julius Marminge 8bbba3d358 Skip commit progress stages when no files changed
- Only include commit-related progress steps for stacked actions when there are working tree changes
- Prevents showing "Generating commit message"/"Committing" during pure push or PR flows
2026-02-14 23:35:48 -08:00
Julius Marminge c0bdd46ddd Streamline git action flow and improve changed-files dialog
- Trigger `commit_push` directly from primary Push actions
- Simplify push confirmation copy and dialog descriptions
- Replace 6-file cap with a scrollable full changed-files list plus totals
2026-02-14 23:35:48 -08:00
Julius Marminge c743239b5e fmt 2026-02-14 23:35:48 -08:00
Julius Marminge f97888a6fd kewl 2026-02-14 23:35:48 -08:00
Julius Marminge 2a6a90a327 Reduce git action success toast duration
- Shorten success notification timeout in `GitActionsControl` from 10s to 5s
2026-02-14 23:35:48 -08:00
Julius Marminge 47019ad79d Prefer upstream branch in push result summary
- show push target as `origin/<branch>` when available
- update summarizeGitResult test expectation accordingly
2026-02-14 23:35:48 -08:00
Julius Marminge 78fabcfde9 Refine git action success toasts with contextual summaries
- replace generic success text with action-specific toast titles/descriptions
- include short SHA/branch details for push and commit outcomes
- add tests for PR/commit/push summaries and description truncation
2026-02-14 23:35:48 -08:00
Julius Marminge 7690837f38 Fix disabled git action tooltip hover handling
- Use the quick action button itself as the popover trigger
- Keep hover tooltips working on disabled controls via pointer-events override
- Remove focus/blur tab-stop handlers from disabled tooltip wrappers
2026-02-14 23:35:48 -08:00
Julius Marminge 85eb379dd7 Improve git status details and streamline quick action flows
- add working-tree file/line stats to git status contracts, server responses, and tests
- refactor web git queries/mutations into shared React Query helpers
- update git quick-action logic/UI to prefer commit/push/PR flows and clearer disabled states
- hide branch toolbar for non-repos and tighten related chat/toolbar behavior
2026-02-14 23:35:48 -08:00
Julius Marminge 5a30594009 git actions 2026-02-14 23:35:48 -08:00
Julius Marminge 02ca9324c5 Use outline styling for Git action buttons
- Change primary Git action button from ghost to outline
- Update Git action options trigger button to outline for consistent affordance
2026-02-14 23:35:48 -08:00
Julius Marminge d3c93752e5 Adopt Base UI components and improve editor open behavior
- migrate web UI to shared Base UI primitives (alerts, buttons, combobox, toast, etc.)
- refactor chat and branch toolbars to use new components and cleaner interactions
- add cross-platform file-manager fallback in `openInEditor` server handling
- update model contracts/tests and web dependencies to support new UI flow
2026-02-14 23:35:48 -08:00
10 changed files with 334 additions and 48 deletions

No files matched your search

+134
View File
@@ -239,6 +239,140 @@ 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);
+34
View File
@@ -553,11 +553,45 @@ 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> {
+7 -2
View File
@@ -1,4 +1,4 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { QueryClient, QueryClientProvider, useQueryClient } from "@tanstack/react-query";
import { useEffect, useRef } from "react";
import ChatView from "./components/ChatView";
@@ -11,22 +11,27 @@ 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]);
}, [api, dispatch, queryClient]);
useEffect(() => {
if (!api) return;
+18 -7
View File
@@ -19,8 +19,11 @@ import {
useRef,
useState,
} from "react";
import { useQuery } from "@tanstack/react-query";
import { gitBranchesQueryOptions } from "~/lib/gitReactQuery";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import {
gitBranchesQueryOptions,
gitCreateWorktreeMutationOptions,
} from "~/lib/gitReactQuery";
import { EDITORS, type EditorId } from "@t3tools/contracts";
import { isElectron } from "../env";
@@ -125,6 +128,8 @@ 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);
@@ -309,14 +314,20 @@ 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 api.terminal
.close({ threadId: activeThreadId, terminalId })
.catch(() => fallbackExitWrite());
void (async () => {
if (isFinalTerminal) {
await api.terminal
.clear({ threadId: activeThreadId, terminalId })
.catch(() => undefined);
}
await api.terminal.close({ threadId: activeThreadId, terminalId, deleteHistory: true });
})().catch(() => fallbackExitWrite());
} else {
void fallbackExitWrite();
}
@@ -327,7 +338,7 @@ export default function ChatView() {
});
setTerminalFocusRequestId((value) => value + 1);
},
[activeThreadId, api, dispatch],
[activeThread?.terminalIds.length, activeThreadId, api, dispatch],
);
const handleRuntimeModeChange = async (mode: "approval-required" | "full-access") => {
@@ -663,7 +674,7 @@ export default function ChatView() {
) {
try {
const newBranch = `codething/${crypto.randomUUID().slice(0, 8)}`;
const result = await api.git.createWorktree({
const result = await createWorktreeMutation.mutateAsync({
cwd: activeProject.cwd,
branch: activeThread.branch,
newBranch,
@@ -1,6 +1,7 @@
import type { GitStatusResult } from "@t3tools/contracts";
import { assert, describe, it } from "vitest";
import {
buildGitActionProgressStages,
buildMenuItems,
requiresDefaultBranchConfirmation,
resolveQuickAction,
@@ -596,6 +597,33 @@ 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,6 +43,30 @@ 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;
@@ -207,7 +231,7 @@ export function resolveQuickAction(
label: "Commit",
disabled: true,
kind: "show_hint",
hint: "Branch is up to date. Nothing to commit, push, pull, or open as a PR.",
hint: "Branch is up to date. No action needed.",
};
}
+35 -32
View File
@@ -4,6 +4,7 @@ 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,
@@ -134,26 +135,6 @@ 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);
@@ -230,14 +211,28 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
}, [api, gitStatus?.openPr?.url]);
const runGitActionWithToast = useCallback(
async ({ action, commitMessage }: { action: GitStackedAction; commitMessage?: string }) => {
async ({
action,
commitMessage,
forcePushOnlyProgress = false,
onConfirmed,
}: {
action: GitStackedAction;
commitMessage?: string;
forcePushOnlyProgress?: boolean;
onConfirmed?: () => void;
}) => {
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",
@@ -272,9 +267,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;
(action === "commit_push" || action === "commit_push_pr") && !!prUrl && !isDefaultBranch;
const shouldOfferCreatePrCta =
action === "commit_push" && !prUrl && result.push.status === "pushed";
action === "commit_push" && !prUrl && result.push.status === "pushed" && !isDefaultBranch;
const closeResultToast = () => {
toastManager.close(progressToastId);
};
@@ -289,8 +284,11 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
actionProps: {
children: "Push",
onClick: () => {
closeResultToast();
void runGitActionWithToast({ action: "commit_push" });
void runGitActionWithToast({
action: "commit_push",
forcePushOnlyProgress: true,
onConfirmed: closeResultToast,
});
},
},
}
@@ -327,8 +325,10 @@ 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" });
void runGitActionWithToast({ action: "commit_push", forcePushOnlyProgress: true });
return;
}
if (item.dialogAction) {
@@ -399,10 +399,12 @@ 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]);
@@ -448,10 +450,10 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
openOnHover
render={
<Button
variant="outline"
aria-disabled="true"
className="cursor-not-allowed rounded-e-none border-e-0 opacity-64 before:rounded-e-none"
size="xs"
disabled={isGitActionRunning || quickAction.disabled}
className="cursor-not-allowed disabled:cursor-not-allowed disabled:pointer-events-auto"
variant="outline"
/>
}
>
@@ -485,7 +487,7 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
>
<ChevronDownIcon aria-hidden="true" className="size-4" />
</MenuTrigger>
<MenuPopup align="end" sideOffset={4}>
<MenuPopup align="end" className="w-full">
{gitActionMenuItems.map((item) => {
const disabledReason = getMenuActionDisabledReason(
item,
@@ -497,9 +499,10 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
<Popover key={`${item.id}-${item.label}`}>
<PopoverTrigger
openOnHover
render={<span className="inline-flex w-full cursor-not-allowed" />}
nativeButton={false}
render={<span className="block w-max cursor-not-allowed" />}
>
<MenuItem disabled>
<MenuItem className="w-full" disabled>
<GitActionItemIcon icon={item.icon} />
{item.label}
</MenuItem>
+6 -2
View File
@@ -1,5 +1,6 @@
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";
@@ -12,6 +13,7 @@ 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;
@@ -110,6 +112,8 @@ 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("");
@@ -307,7 +311,7 @@ export default function Sidebar() {
}
try {
await api.git.removeWorktree({
await removeWorktreeMutation.mutateAsync({
cwd: threadProject.cwd,
path: orphanedWorktreePath,
});
@@ -315,7 +319,7 @@ export default function Sidebar() {
// Worktree deletion is best-effort and should not block thread deletion.
}
},
[api, dispatch, state.projects, state.threads],
[api, dispatch, removeWorktreeMutation, state.projects, state.threads],
);
useEffect(() => {
+44 -2
View File
@@ -108,7 +108,7 @@ export function gitRunStackedActionMutationOptions(input: {
...(commitMessage ? { commitMessage } : {}),
});
},
onSuccess: async () => {
onSettled: async () => {
await invalidateGitQueries(input.queryClient);
},
});
@@ -124,7 +124,49 @@ export function gitPullMutationOptions(input: {
if (!input.api || !input.cwd) throw new Error("Git pull is unavailable.");
return input.api.git.pull({ cwd: input.cwd });
},
onSuccess: async () => {
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 () => {
await invalidateGitQueries(input.queryClient);
},
});
+3 -2
View File
@@ -269,6 +269,7 @@ 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,
@@ -277,11 +278,11 @@ function closeThreadTerminal(thread: Thread, terminalId: string): Thread {
activeTerminalId: DEFAULT_THREAD_TERMINAL_ID,
terminalGroups: [
{
id: fallbackGroupId(DEFAULT_THREAD_TERMINAL_ID),
id: nextTerminalGroupId,
terminalIds: [DEFAULT_THREAD_TERMINAL_ID],
},
],
activeTerminalGroupId: fallbackGroupId(DEFAULT_THREAD_TERMINAL_ID),
activeTerminalGroupId: nextTerminalGroupId,
});
}