Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
147f433d38 | ||
|
|
ca2acb078e | ||
|
|
4c7720565c | ||
|
|
1f4f693dd6 | ||
|
|
6e46a7be38 | ||
|
|
0be98ea9d1 | ||
|
|
2cd92ae6f5 | ||
|
|
85fe41bad0 | ||
|
|
0c26396f79 | ||
|
|
cc37865c2d | ||
|
|
a6b9ece840 | ||
|
|
65ab532342 | ||
|
|
cce74f913c | ||
|
|
170c3a7162 | ||
|
|
1fe3cf53a7 | ||
|
|
07187d3794 | ||
|
|
758df838d9 | ||
|
|
669168d08a | ||
|
|
9bd663be7f | ||
|
|
58d926fcfb | ||
|
|
b5149f5959 | ||
|
|
ea661fb635 | ||
|
|
8bbba3d358 | ||
|
|
c0bdd46ddd | ||
|
|
c743239b5e | ||
|
|
f97888a6fd | ||
|
|
2a6a90a327 | ||
|
|
47019ad79d | ||
|
|
78fabcfde9 | ||
|
|
7690837f38 | ||
|
|
85eb379dd7 | ||
|
|
5a30594009 | ||
|
|
02ca9324c5 | ||
|
|
d3c93752e5 |
No files matched your search
@@ -239,6 +239,140 @@ describe("git integration", () => {
|
|||||||
expect(current!.name).toBe("feature");
|
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 () => {
|
it("throws when branch does not exist", async () => {
|
||||||
await using tmp = await makeTmpDir();
|
await using tmp = await makeTmpDir();
|
||||||
await initRepoWithCommit(tmp.path);
|
await initRepoWithCommit(tmp.path);
|
||||||
|
|||||||
@@ -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> {
|
async checkoutBranch(input: GitCheckoutInput): Promise<void> {
|
||||||
await executeGit(input.cwd, ["checkout", input.branch], {
|
await executeGit(input.cwd, ["checkout", input.branch], {
|
||||||
timeoutMs: 10_000,
|
timeoutMs: 10_000,
|
||||||
fallbackErrorMessage: "git checkout failed",
|
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> {
|
async initRepo(input: GitInitInput): Promise<void> {
|
||||||
|
|||||||
@@ -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 { useEffect, useRef } from "react";
|
||||||
|
|
||||||
import ChatView from "./components/ChatView";
|
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 { onServerWelcome } from "./wsNativeApi";
|
||||||
import { useNativeApi } from "./hooks/useNativeApi";
|
import { useNativeApi } from "./hooks/useNativeApi";
|
||||||
import { AnchoredToastProvider, ToastProvider } from "./components/ui/toast";
|
import { AnchoredToastProvider, ToastProvider } from "./components/ui/toast";
|
||||||
|
import { invalidateGitQueries } from "./lib/gitReactQuery";
|
||||||
|
|
||||||
function EventRouter() {
|
function EventRouter() {
|
||||||
const api = useNativeApi();
|
const api = useNativeApi();
|
||||||
const { dispatch } = useStore();
|
const { dispatch } = useStore();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
const activeAssistantItemRef = useRef<string | null>(null);
|
const activeAssistantItemRef = useRef<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!api) return;
|
if (!api) return;
|
||||||
return api.providers.onEvent((event) => {
|
return api.providers.onEvent((event) => {
|
||||||
|
if (event.method === "turn/completed") {
|
||||||
|
void invalidateGitQueries(queryClient);
|
||||||
|
}
|
||||||
dispatch({
|
dispatch({
|
||||||
type: "APPLY_EVENT",
|
type: "APPLY_EVENT",
|
||||||
event,
|
event,
|
||||||
activeAssistantItemRef,
|
activeAssistantItemRef,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, [api, dispatch]);
|
}, [api, dispatch, queryClient]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!api) return;
|
if (!api) return;
|
||||||
|
|||||||
@@ -19,8 +19,11 @@ import {
|
|||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { gitBranchesQueryOptions } from "~/lib/gitReactQuery";
|
import {
|
||||||
|
gitBranchesQueryOptions,
|
||||||
|
gitCreateWorktreeMutationOptions,
|
||||||
|
} from "~/lib/gitReactQuery";
|
||||||
|
|
||||||
import { EDITORS, type EditorId } from "@t3tools/contracts";
|
import { EDITORS, type EditorId } from "@t3tools/contracts";
|
||||||
import { isElectron } from "../env";
|
import { isElectron } from "../env";
|
||||||
@@ -125,6 +128,8 @@ function readFileAsDataUrl(file: File): Promise<string> {
|
|||||||
export default function ChatView() {
|
export default function ChatView() {
|
||||||
const { state, dispatch } = useStore();
|
const { state, dispatch } = useStore();
|
||||||
const api = useNativeApi();
|
const api = useNativeApi();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const createWorktreeMutation = useMutation(gitCreateWorktreeMutationOptions({ api, queryClient }));
|
||||||
const [prompt, setPrompt] = useState("");
|
const [prompt, setPrompt] = useState("");
|
||||||
const [composerImages, setComposerImages] = useState<ComposerImageAttachment[]>([]);
|
const [composerImages, setComposerImages] = useState<ComposerImageAttachment[]>([]);
|
||||||
const [isDragOverComposer, setIsDragOverComposer] = useState(false);
|
const [isDragOverComposer, setIsDragOverComposer] = useState(false);
|
||||||
@@ -309,14 +314,20 @@ export default function ChatView() {
|
|||||||
const closeTerminal = useCallback(
|
const closeTerminal = useCallback(
|
||||||
(terminalId: string) => {
|
(terminalId: string) => {
|
||||||
if (!activeThreadId || !api) return;
|
if (!activeThreadId || !api) return;
|
||||||
|
const isFinalTerminal = (activeThread?.terminalIds.length ?? 0) <= 1;
|
||||||
const fallbackExitWrite = () =>
|
const fallbackExitWrite = () =>
|
||||||
api.terminal
|
api.terminal
|
||||||
.write({ threadId: activeThreadId, terminalId, data: "exit\n" })
|
.write({ threadId: activeThreadId, terminalId, data: "exit\n" })
|
||||||
.catch(() => undefined);
|
.catch(() => undefined);
|
||||||
if ("close" in api.terminal && typeof api.terminal.close === "function") {
|
if ("close" in api.terminal && typeof api.terminal.close === "function") {
|
||||||
void api.terminal
|
void (async () => {
|
||||||
.close({ threadId: activeThreadId, terminalId })
|
if (isFinalTerminal) {
|
||||||
.catch(() => fallbackExitWrite());
|
await api.terminal
|
||||||
|
.clear({ threadId: activeThreadId, terminalId })
|
||||||
|
.catch(() => undefined);
|
||||||
|
}
|
||||||
|
await api.terminal.close({ threadId: activeThreadId, terminalId, deleteHistory: true });
|
||||||
|
})().catch(() => fallbackExitWrite());
|
||||||
} else {
|
} else {
|
||||||
void fallbackExitWrite();
|
void fallbackExitWrite();
|
||||||
}
|
}
|
||||||
@@ -327,7 +338,7 @@ export default function ChatView() {
|
|||||||
});
|
});
|
||||||
setTerminalFocusRequestId((value) => value + 1);
|
setTerminalFocusRequestId((value) => value + 1);
|
||||||
},
|
},
|
||||||
[activeThreadId, api, dispatch],
|
[activeThread?.terminalIds.length, activeThreadId, api, dispatch],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleRuntimeModeChange = async (mode: "approval-required" | "full-access") => {
|
const handleRuntimeModeChange = async (mode: "approval-required" | "full-access") => {
|
||||||
@@ -663,7 +674,7 @@ export default function ChatView() {
|
|||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const newBranch = `codething/${crypto.randomUUID().slice(0, 8)}`;
|
const newBranch = `codething/${crypto.randomUUID().slice(0, 8)}`;
|
||||||
const result = await api.git.createWorktree({
|
const result = await createWorktreeMutation.mutateAsync({
|
||||||
cwd: activeProject.cwd,
|
cwd: activeProject.cwd,
|
||||||
branch: activeThread.branch,
|
branch: activeThread.branch,
|
||||||
newBranch,
|
newBranch,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { GitStatusResult } from "@t3tools/contracts";
|
import type { GitStatusResult } from "@t3tools/contracts";
|
||||||
import { assert, describe, it } from "vitest";
|
import { assert, describe, it } from "vitest";
|
||||||
import {
|
import {
|
||||||
|
buildGitActionProgressStages,
|
||||||
buildMenuItems,
|
buildMenuItems,
|
||||||
requiresDefaultBranchConfirmation,
|
requiresDefaultBranchConfirmation,
|
||||||
resolveQuickAction,
|
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", () => {
|
describe("summarizeGitResult", () => {
|
||||||
it("returns commit-focused toast for commit action", () => {
|
it("returns commit-focused toast for commit action", () => {
|
||||||
const result = summarizeGitResult({
|
const result = summarizeGitResult({
|
||||||
|
|||||||
@@ -43,6 +43,30 @@ function truncateText(
|
|||||||
return `${value.slice(0, Math.max(0, maxLength - 3)).trimEnd()}...`;
|
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): {
|
export function summarizeGitResult(result: GitRunStackedActionResult): {
|
||||||
title: string;
|
title: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
@@ -207,7 +231,7 @@ export function resolveQuickAction(
|
|||||||
label: "Commit",
|
label: "Commit",
|
||||||
disabled: true,
|
disabled: true,
|
||||||
kind: "show_hint",
|
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.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useCallback, useMemo, useState } from "react";
|
|||||||
import { ChevronDownIcon, CloudUploadIcon, GitCommitIcon, InfoIcon } from "lucide-react";
|
import { ChevronDownIcon, CloudUploadIcon, GitCommitIcon, InfoIcon } from "lucide-react";
|
||||||
import { GitHubIcon } from "./Icons";
|
import { GitHubIcon } from "./Icons";
|
||||||
import {
|
import {
|
||||||
|
buildGitActionProgressStages,
|
||||||
buildMenuItems,
|
buildMenuItems,
|
||||||
type GitActionIconName,
|
type GitActionIconName,
|
||||||
type GitActionMenuItem,
|
type GitActionMenuItem,
|
||||||
@@ -134,26 +135,6 @@ function GitQuickActionIcon({ quickAction }: { quickAction: GitQuickAction }) {
|
|||||||
return <InfoIcon className={iconClassName} />;
|
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) {
|
export default function GitActionsControl({ api, gitCwd }: GitActionsControlProps) {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [activeDialogAction, setActiveDialogAction] = useState<GitDialogAction | null>(null);
|
const [activeDialogAction, setActiveDialogAction] = useState<GitDialogAction | null>(null);
|
||||||
@@ -230,14 +211,28 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
|||||||
}, [api, gitStatus?.openPr?.url]);
|
}, [api, gitStatus?.openPr?.url]);
|
||||||
|
|
||||||
const runGitActionWithToast = useCallback(
|
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);
|
const confirmed = await maybeConfirmPushToDefaultBranch(action);
|
||||||
if (!confirmed) return;
|
if (!confirmed) return;
|
||||||
|
onConfirmed?.();
|
||||||
|
|
||||||
|
const pushTarget = gitStatus?.branch ? `origin/${gitStatus.branch}` : undefined;
|
||||||
const progressStages = buildGitActionProgressStages({
|
const progressStages = buildGitActionProgressStages({
|
||||||
action,
|
action,
|
||||||
hasCustomCommitMessage: !!commitMessage?.trim(),
|
hasCustomCommitMessage: !!commitMessage?.trim(),
|
||||||
hasWorkingTreeChanges: !!gitStatus?.hasWorkingTreeChanges,
|
hasWorkingTreeChanges: !!gitStatus?.hasWorkingTreeChanges,
|
||||||
|
forcePushOnly: forcePushOnlyProgress,
|
||||||
|
...(pushTarget ? { pushTarget } : {}),
|
||||||
});
|
});
|
||||||
const progressToastId = toastManager.add({
|
const progressToastId = toastManager.add({
|
||||||
type: "loading",
|
type: "loading",
|
||||||
@@ -272,9 +267,9 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
|||||||
const prUrl = result.pr.url ?? gitStatus?.openPr?.url;
|
const prUrl = result.pr.url ?? gitStatus?.openPr?.url;
|
||||||
const shouldOfferPushCta = action === "commit" && result.commit.status === "created";
|
const shouldOfferPushCta = action === "commit" && result.commit.status === "created";
|
||||||
const shouldOfferOpenPrCta =
|
const shouldOfferOpenPrCta =
|
||||||
(action === "commit_push" || action === "commit_push_pr") && !!prUrl;
|
(action === "commit_push" || action === "commit_push_pr") && !!prUrl && !isDefaultBranch;
|
||||||
const shouldOfferCreatePrCta =
|
const shouldOfferCreatePrCta =
|
||||||
action === "commit_push" && !prUrl && result.push.status === "pushed";
|
action === "commit_push" && !prUrl && result.push.status === "pushed" && !isDefaultBranch;
|
||||||
const closeResultToast = () => {
|
const closeResultToast = () => {
|
||||||
toastManager.close(progressToastId);
|
toastManager.close(progressToastId);
|
||||||
};
|
};
|
||||||
@@ -289,8 +284,11 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
|||||||
actionProps: {
|
actionProps: {
|
||||||
children: "Push",
|
children: "Push",
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
closeResultToast();
|
void runGitActionWithToast({
|
||||||
void runGitActionWithToast({ action: "commit_push" });
|
action: "commit_push",
|
||||||
|
forcePushOnlyProgress: true,
|
||||||
|
onConfirmed: closeResultToast,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -327,8 +325,10 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
|||||||
},
|
},
|
||||||
[
|
[
|
||||||
api,
|
api,
|
||||||
|
gitStatus?.branch,
|
||||||
gitStatus?.hasWorkingTreeChanges,
|
gitStatus?.hasWorkingTreeChanges,
|
||||||
gitStatus?.openPr?.url,
|
gitStatus?.openPr?.url,
|
||||||
|
isDefaultBranch,
|
||||||
maybeConfirmPushToDefaultBranch,
|
maybeConfirmPushToDefaultBranch,
|
||||||
runImmediateGitActionMutation,
|
runImmediateGitActionMutation,
|
||||||
setActiveDialogAction,
|
setActiveDialogAction,
|
||||||
@@ -380,7 +380,7 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (item.dialogAction === "push") {
|
if (item.dialogAction === "push") {
|
||||||
void runGitActionWithToast({ action: "commit_push" });
|
void runGitActionWithToast({ action: "commit_push", forcePushOnlyProgress: true });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (item.dialogAction) {
|
if (item.dialogAction) {
|
||||||
@@ -399,10 +399,12 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
|||||||
? "commit_push"
|
? "commit_push"
|
||||||
: "commit_push_pr";
|
: "commit_push_pr";
|
||||||
const commitMessage = activeDialogAction === "commit" ? dialogCommitMessage.trim() : "";
|
const commitMessage = activeDialogAction === "commit" ? dialogCommitMessage.trim() : "";
|
||||||
|
const forcePushOnlyProgress = activeDialogAction === "push";
|
||||||
setActiveDialogAction(null);
|
setActiveDialogAction(null);
|
||||||
void runGitActionWithToast({
|
void runGitActionWithToast({
|
||||||
action,
|
action,
|
||||||
...(commitMessage ? { commitMessage } : {}),
|
...(commitMessage ? { commitMessage } : {}),
|
||||||
|
...(forcePushOnlyProgress ? { forcePushOnlyProgress } : {}),
|
||||||
});
|
});
|
||||||
}, [activeDialogAction, dialogCommitMessage, runGitActionWithToast]);
|
}, [activeDialogAction, dialogCommitMessage, runGitActionWithToast]);
|
||||||
|
|
||||||
@@ -448,10 +450,10 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
|||||||
openOnHover
|
openOnHover
|
||||||
render={
|
render={
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
aria-disabled="true"
|
||||||
|
className="cursor-not-allowed rounded-e-none border-e-0 opacity-64 before:rounded-e-none"
|
||||||
size="xs"
|
size="xs"
|
||||||
disabled={isGitActionRunning || quickAction.disabled}
|
variant="outline"
|
||||||
className="cursor-not-allowed disabled:cursor-not-allowed disabled:pointer-events-auto"
|
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -485,7 +487,7 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
|||||||
>
|
>
|
||||||
<ChevronDownIcon aria-hidden="true" className="size-4" />
|
<ChevronDownIcon aria-hidden="true" className="size-4" />
|
||||||
</MenuTrigger>
|
</MenuTrigger>
|
||||||
<MenuPopup align="end" sideOffset={4}>
|
<MenuPopup align="end" className="w-full">
|
||||||
{gitActionMenuItems.map((item) => {
|
{gitActionMenuItems.map((item) => {
|
||||||
const disabledReason = getMenuActionDisabledReason(
|
const disabledReason = getMenuActionDisabledReason(
|
||||||
item,
|
item,
|
||||||
@@ -497,9 +499,10 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
|||||||
<Popover key={`${item.id}-${item.label}`}>
|
<Popover key={`${item.id}-${item.label}`}>
|
||||||
<PopoverTrigger
|
<PopoverTrigger
|
||||||
openOnHover
|
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} />
|
<GitActionItemIcon icon={item.icon} />
|
||||||
{item.label}
|
{item.label}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { MonitorIcon, MoonIcon, SunIcon, TerminalIcon } from "lucide-react";
|
import { MonitorIcon, MoonIcon, SunIcon, TerminalIcon } from "lucide-react";
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { isElectron } from "../env";
|
import { isElectron } from "../env";
|
||||||
import { useTheme } from "../hooks/useTheme";
|
import { useTheme } from "../hooks/useTheme";
|
||||||
import { DEFAULT_MODEL } from "../model-logic";
|
import { DEFAULT_MODEL } from "../model-logic";
|
||||||
@@ -12,6 +13,7 @@ import {
|
|||||||
type Thread,
|
type Thread,
|
||||||
} from "../types";
|
} from "../types";
|
||||||
import { useNativeApi } from "../hooks/useNativeApi";
|
import { useNativeApi } from "../hooks/useNativeApi";
|
||||||
|
import { gitRemoveWorktreeMutationOptions } from "../lib/gitReactQuery";
|
||||||
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup";
|
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup";
|
||||||
|
|
||||||
const THEME_CYCLE = { system: "light", light: "dark", dark: "system" } as const;
|
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() {
|
export default function Sidebar() {
|
||||||
const { state, dispatch } = useStore();
|
const { state, dispatch } = useStore();
|
||||||
const api = useNativeApi();
|
const api = useNativeApi();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const removeWorktreeMutation = useMutation(gitRemoveWorktreeMutationOptions({ api, queryClient }));
|
||||||
const { theme, setTheme } = useTheme();
|
const { theme, setTheme } = useTheme();
|
||||||
const [addingProject, setAddingProject] = useState(false);
|
const [addingProject, setAddingProject] = useState(false);
|
||||||
const [newCwd, setNewCwd] = useState("");
|
const [newCwd, setNewCwd] = useState("");
|
||||||
@@ -307,7 +311,7 @@ export default function Sidebar() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await api.git.removeWorktree({
|
await removeWorktreeMutation.mutateAsync({
|
||||||
cwd: threadProject.cwd,
|
cwd: threadProject.cwd,
|
||||||
path: orphanedWorktreePath,
|
path: orphanedWorktreePath,
|
||||||
});
|
});
|
||||||
@@ -315,7 +319,7 @@ export default function Sidebar() {
|
|||||||
// Worktree deletion is best-effort and should not block thread deletion.
|
// 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(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ export function gitRunStackedActionMutationOptions(input: {
|
|||||||
...(commitMessage ? { commitMessage } : {}),
|
...(commitMessage ? { commitMessage } : {}),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onSuccess: async () => {
|
onSettled: async () => {
|
||||||
await invalidateGitQueries(input.queryClient);
|
await invalidateGitQueries(input.queryClient);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -124,7 +124,49 @@ export function gitPullMutationOptions(input: {
|
|||||||
if (!input.api || !input.cwd) throw new Error("Git pull is unavailable.");
|
if (!input.api || !input.cwd) throw new Error("Git pull is unavailable.");
|
||||||
return input.api.git.pull({ cwd: input.cwd });
|
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);
|
await invalidateGitQueries(input.queryClient);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -269,6 +269,7 @@ function closeThreadTerminal(thread: Thread, terminalId: string): Thread {
|
|||||||
|
|
||||||
const remainingTerminalIds = thread.terminalIds.filter((id) => id !== terminalId);
|
const remainingTerminalIds = thread.terminalIds.filter((id) => id !== terminalId);
|
||||||
if (remainingTerminalIds.length === 0) {
|
if (remainingTerminalIds.length === 0) {
|
||||||
|
const nextTerminalGroupId = fallbackGroupId(DEFAULT_THREAD_TERMINAL_ID);
|
||||||
return normalizeThreadTerminals({
|
return normalizeThreadTerminals({
|
||||||
...thread,
|
...thread,
|
||||||
terminalOpen: false,
|
terminalOpen: false,
|
||||||
@@ -277,11 +278,11 @@ function closeThreadTerminal(thread: Thread, terminalId: string): Thread {
|
|||||||
activeTerminalId: DEFAULT_THREAD_TERMINAL_ID,
|
activeTerminalId: DEFAULT_THREAD_TERMINAL_ID,
|
||||||
terminalGroups: [
|
terminalGroups: [
|
||||||
{
|
{
|
||||||
id: fallbackGroupId(DEFAULT_THREAD_TERMINAL_ID),
|
id: nextTerminalGroupId,
|
||||||
terminalIds: [DEFAULT_THREAD_TERMINAL_ID],
|
terminalIds: [DEFAULT_THREAD_TERMINAL_ID],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
activeTerminalGroupId: fallbackGroupId(DEFAULT_THREAD_TERMINAL_ID),
|
activeTerminalGroupId: nextTerminalGroupId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user