This commit is contained in:
Julius Marminge authored and Julius Marminge committed 2026-03-03 10:01:18 -08:00
1 parent fabb3e0734
commit 93af851dc5
3 files changed
+27 -11

No files matched your search

@@ -1,10 +1,12 @@
import type { GitBranch } from "@t3tools/contracts";
export type EnvMode = "local" | "worktree";
export function resolveDraftEnvModeAfterBranchChange(input: {
nextWorktreePath: string | null;
currentWorktreePath: string | null;
effectiveEnvMode: "local" | "worktree";
}): "local" | "worktree" {
effectiveEnvMode: EnvMode;
}): EnvMode {
const { nextWorktreePath, currentWorktreePath, effectiveEnvMode } = input;
if (nextWorktreePath) {
return "worktree";
@@ -16,7 +18,7 @@ export function resolveDraftEnvModeAfterBranchChange(input: {
}
export function resolveBranchToolbarValue(input: {
envMode: "local" | "worktree";
envMode: EnvMode;
activeWorktreePath: string | null;
activeThreadBranch: string | null;
currentGitBranch: string | null;
+4 -4
View File
@@ -5,14 +5,14 @@ import { newCommandId } from "../lib/utils";
import { readNativeApi } from "../nativeApi";
import { useComposerDraftStore } from "../composerDraftStore";
import { useStore } from "../store";
import { resolveDraftEnvModeAfterBranchChange } from "./BranchToolbar.logic";
import { EnvMode, resolveDraftEnvModeAfterBranchChange } from "./BranchToolbar.logic";
import { BranchToolbarBranchSelector } from "./BranchToolbarBranchSelector";
import { Button } from "./ui/button";
interface BranchToolbarProps {
threadId: ThreadId;
envMode: "local" | "worktree";
onEnvModeChange: (mode: "local" | "worktree") => void;
envMode: EnvMode;
onEnvModeChange: (mode: EnvMode) => void;
envLocked: boolean;
onComposerFocusRequest?: () => void;
}
@@ -38,7 +38,7 @@ export default function BranchToolbar({
const activeWorktreePath = serverThread?.worktreePath ?? draftThread?.worktreePath ?? null;
const branchCwd = activeWorktreePath ?? activeProject?.cwd ?? null;
const hasServerThread = serverThread !== undefined;
const effectiveEnvMode: "local" | "worktree" =
const effectiveEnvMode: EnvMode =
activeWorktreePath || (!hasServerThread && draftThread?.envMode === "worktree")
? "worktree"
: envMode;
@@ -2,13 +2,22 @@ import type { GitBranch } from "@t3tools/contracts";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { useVirtualizer } from "@tanstack/react-virtual";
import { ChevronDownIcon } from "lucide-react";
import { useCallback, useEffect, useMemo, useOptimistic, useRef, useState, useTransition } from "react";
import {
useCallback,
useEffect,
useMemo,
useOptimistic,
useRef,
useState,
useTransition,
} from "react";
import { gitBranchesQueryOptions, gitQueryKeys, invalidateGitQueries } from "../lib/gitReactQuery";
import { readNativeApi } from "../nativeApi";
import {
dedupeRemoteBranchesWithLocalMatches,
deriveLocalBranchNameFromRemoteRef,
EnvMode,
resolveBranchToolbarValue,
} from "./BranchToolbar.logic";
import { Button } from "./ui/button";
@@ -28,7 +37,7 @@ interface BranchToolbarBranchSelectorProps {
activeThreadBranch: string | null;
activeWorktreePath: string | null;
branchCwd: string | null;
effectiveEnvMode: "local" | "worktree";
effectiveEnvMode: EnvMode;
envLocked: boolean;
onSetThreadBranch: (branch: string | null, worktreePath: string | null) => void;
onComposerFocusRequest?: () => void;
@@ -40,7 +49,7 @@ function toBranchActionErrorMessage(error: unknown): string {
function getBranchTriggerLabel(input: {
activeWorktreePath: string | null;
effectiveEnvMode: "local" | "worktree";
effectiveEnvMode: EnvMode;
resolvedActiveBranch: string | null;
}): string {
const { activeWorktreePath, effectiveEnvMode, resolvedActiveBranch } = input;
@@ -215,7 +224,12 @@ export function BranchToolbarBranchSelector({
};
useEffect(() => {
if (effectiveEnvMode !== "worktree" || activeWorktreePath || activeThreadBranch || !currentGitBranch) {
if (
effectiveEnvMode !== "worktree" ||
activeWorktreePath ||
activeThreadBranch ||
!currentGitBranch
) {
return;
}
onSetThreadBranch(currentGitBranch, null);