Rename branch UI to ref-aware VCS helpers
- Generalize branch toolbar logic and status state around refs - Add VCS query/status wrappers and keep legacy branch aliases - Update selector behavior, labels, and tests for remote refs Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
23355c1bdd
commit
e0314cf2b2
13 files changed
+571
-433
No files matched your search
@@ -301,11 +301,6 @@ export function matchesBranchHeadContext(
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (expectedHead.ownerLogin && pullRequestHead.ownerLogin) {
|
||||
if (expectedHead.ownerLogin !== pullRequestHead.ownerLogin) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (expectedHead.ownerLogin && pullRequestHead.ownerLogin) {
|
||||
|
||||
@@ -2,17 +2,17 @@ import { EnvironmentId, type VcsRef } from "@t3tools/contracts";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
dedupeRemoteBranchesWithLocalMatches,
|
||||
deriveLocalBranchNameFromRemoteRef,
|
||||
resolveEnvironmentOptionLabel,
|
||||
resolveBranchSelectionTarget,
|
||||
resolveCurrentWorkspaceLabel,
|
||||
resolveDraftEnvModeAfterBranchChange,
|
||||
resolveEffectiveEnvMode,
|
||||
resolveEnvModeLabel,
|
||||
resolveBranchToolbarValue,
|
||||
resolveLockedWorkspaceLabel,
|
||||
resolveLocalCheckoutBranchMismatch,
|
||||
shouldIncludeBranchPickerItem,
|
||||
resolveLocalCheckoutRefMismatch,
|
||||
resolveLocalRefNameFromRemoteRef,
|
||||
resolveRefSelectionTarget,
|
||||
resolveRefToolbarValue,
|
||||
shouldIncludeRefPickerItem,
|
||||
} from "./BranchToolbar.logic";
|
||||
|
||||
const localEnvironmentId = EnvironmentId.make("environment-local");
|
||||
@@ -50,85 +50,85 @@ describe("resolveDraftEnvModeAfterBranchChange", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveBranchToolbarValue", () => {
|
||||
it("defaults new-worktree mode to current git ref when no explicit base ref is set", () => {
|
||||
describe("resolveRefToolbarValue", () => {
|
||||
it("defaults new-worktree mode to current ref when no explicit base ref is set", () => {
|
||||
expect(
|
||||
resolveBranchToolbarValue({
|
||||
resolveRefToolbarValue({
|
||||
envMode: "worktree",
|
||||
activeWorktreePath: null,
|
||||
activeThreadBranch: null,
|
||||
currentGitBranch: "main",
|
||||
activeThreadRefName: null,
|
||||
currentRefName: "main",
|
||||
}),
|
||||
).toBe("main");
|
||||
});
|
||||
|
||||
it("keeps an explicitly selected worktree base ref", () => {
|
||||
expect(
|
||||
resolveBranchToolbarValue({
|
||||
resolveRefToolbarValue({
|
||||
envMode: "worktree",
|
||||
activeWorktreePath: null,
|
||||
activeThreadBranch: "feature/base",
|
||||
currentGitBranch: "main",
|
||||
activeThreadRefName: "feature/base",
|
||||
currentRefName: "main",
|
||||
}),
|
||||
).toBe("feature/base");
|
||||
});
|
||||
|
||||
it("shows the actual checked-out ref when not selecting a new worktree base", () => {
|
||||
expect(
|
||||
resolveBranchToolbarValue({
|
||||
resolveRefToolbarValue({
|
||||
envMode: "local",
|
||||
activeWorktreePath: null,
|
||||
activeThreadBranch: "feature/base",
|
||||
currentGitBranch: "main",
|
||||
activeThreadRefName: "feature/base",
|
||||
currentRefName: "main",
|
||||
}),
|
||||
).toBe("main");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveLocalCheckoutBranchMismatch", () => {
|
||||
it("detects when a local thread is associated with a different branch than the checkout", () => {
|
||||
describe("resolveLocalCheckoutRefMismatch", () => {
|
||||
it("detects when a local thread is associated with a different ref than the checkout", () => {
|
||||
expect(
|
||||
resolveLocalCheckoutBranchMismatch({
|
||||
resolveLocalCheckoutRefMismatch({
|
||||
effectiveEnvMode: "local",
|
||||
activeWorktreePath: null,
|
||||
activeThreadBranch: "feature/thread",
|
||||
currentGitBranch: "feature/current",
|
||||
activeThreadRefName: "feature/thread",
|
||||
currentRefName: "feature/current",
|
||||
}),
|
||||
).toEqual({
|
||||
threadBranch: "feature/thread",
|
||||
currentBranch: "feature/current",
|
||||
threadRefName: "feature/thread",
|
||||
currentRefName: "feature/current",
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores matching local checkout state", () => {
|
||||
expect(
|
||||
resolveLocalCheckoutBranchMismatch({
|
||||
resolveLocalCheckoutRefMismatch({
|
||||
effectiveEnvMode: "local",
|
||||
activeWorktreePath: null,
|
||||
activeThreadBranch: "feature/thread",
|
||||
currentGitBranch: "feature/thread",
|
||||
activeThreadRefName: "feature/thread",
|
||||
currentRefName: "feature/thread",
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("ignores dedicated worktrees because their checkout is already thread-scoped", () => {
|
||||
expect(
|
||||
resolveLocalCheckoutBranchMismatch({
|
||||
resolveLocalCheckoutRefMismatch({
|
||||
effectiveEnvMode: "worktree",
|
||||
activeWorktreePath: "/repo/.t3/worktrees/feature-thread",
|
||||
activeThreadBranch: "feature/thread",
|
||||
currentGitBranch: "feature/current",
|
||||
activeThreadRefName: "feature/thread",
|
||||
currentRefName: "feature/current",
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("ignores new-worktree base selection before a worktree exists", () => {
|
||||
expect(
|
||||
resolveLocalCheckoutBranchMismatch({
|
||||
resolveLocalCheckoutRefMismatch({
|
||||
effectiveEnvMode: "worktree",
|
||||
activeWorktreePath: null,
|
||||
activeThreadBranch: "feature/base",
|
||||
currentGitBranch: "main",
|
||||
activeThreadRefName: "feature/base",
|
||||
currentRefName: "main",
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
@@ -218,20 +218,46 @@ describe("resolveLockedWorkspaceLabel", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("deriveLocalBranchNameFromRemoteRef", () => {
|
||||
it("strips the remote prefix from a remote ref", () => {
|
||||
expect(deriveLocalBranchNameFromRemoteRef("origin/feature/demo")).toBe("feature/demo");
|
||||
describe("resolveLocalRefNameFromRemoteRef", () => {
|
||||
it("strips the remote prefix from a remote ref using structured metadata", () => {
|
||||
expect(
|
||||
resolveLocalRefNameFromRemoteRef({
|
||||
name: "origin/feature/demo",
|
||||
remoteName: "origin",
|
||||
}),
|
||||
).toBe("feature/demo");
|
||||
});
|
||||
|
||||
it("supports remote names that contain slashes", () => {
|
||||
expect(deriveLocalBranchNameFromRemoteRef("my-org/upstream/feature/demo")).toBe(
|
||||
"upstream/feature/demo",
|
||||
);
|
||||
it("supports remote names that contain slashes through the remoteName field", () => {
|
||||
expect(
|
||||
resolveLocalRefNameFromRemoteRef({
|
||||
name: "my-org/upstream/feature/demo",
|
||||
remoteName: "my-org/upstream",
|
||||
}),
|
||||
).toBe("feature/demo");
|
||||
});
|
||||
|
||||
it("returns the original name when ref is malformed", () => {
|
||||
expect(deriveLocalBranchNameFromRemoteRef("origin/")).toBe("origin/");
|
||||
expect(deriveLocalBranchNameFromRemoteRef("/feature/demo")).toBe("/feature/demo");
|
||||
it("returns the original name when remote metadata is unavailable", () => {
|
||||
expect(
|
||||
resolveLocalRefNameFromRemoteRef({
|
||||
name: "origin/feature/demo",
|
||||
}),
|
||||
).toBe("origin/feature/demo");
|
||||
});
|
||||
|
||||
it("returns the original name when the remote prefix is malformed", () => {
|
||||
expect(
|
||||
resolveLocalRefNameFromRemoteRef({
|
||||
name: "origin/",
|
||||
remoteName: "origin",
|
||||
}),
|
||||
).toBe("origin/");
|
||||
expect(
|
||||
resolveLocalRefNameFromRemoteRef({
|
||||
name: "/feature/demo",
|
||||
remoteName: "origin",
|
||||
}),
|
||||
).toBe("/feature/demo");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -341,13 +367,13 @@ describe("dedupeRemoteBranchesWithLocalMatches", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveBranchSelectionTarget", () => {
|
||||
describe("resolveRefSelectionTarget", () => {
|
||||
it("reuses an existing secondary worktree for the selected ref", () => {
|
||||
expect(
|
||||
resolveBranchSelectionTarget({
|
||||
resolveRefSelectionTarget({
|
||||
activeProjectCwd: "/repo",
|
||||
activeWorktreePath: "/repo/.t3/worktrees/feature-a",
|
||||
refName: {
|
||||
ref: {
|
||||
isDefault: false,
|
||||
worktreePath: "/repo/.t3/worktrees/feature-b",
|
||||
},
|
||||
@@ -361,10 +387,10 @@ describe("resolveBranchSelectionTarget", () => {
|
||||
|
||||
it("switches back to the main repo when the ref already lives there", () => {
|
||||
expect(
|
||||
resolveBranchSelectionTarget({
|
||||
resolveRefSelectionTarget({
|
||||
activeProjectCwd: "/repo",
|
||||
activeWorktreePath: "/repo/.t3/worktrees/feature-a",
|
||||
refName: {
|
||||
ref: {
|
||||
isDefault: true,
|
||||
worktreePath: "/repo",
|
||||
},
|
||||
@@ -378,10 +404,10 @@ describe("resolveBranchSelectionTarget", () => {
|
||||
|
||||
it("checks out the default ref in the main repo when leaving a secondary worktree", () => {
|
||||
expect(
|
||||
resolveBranchSelectionTarget({
|
||||
resolveRefSelectionTarget({
|
||||
activeProjectCwd: "/repo",
|
||||
activeWorktreePath: "/repo/.t3/worktrees/feature-a",
|
||||
refName: {
|
||||
ref: {
|
||||
isDefault: true,
|
||||
worktreePath: null,
|
||||
},
|
||||
@@ -395,10 +421,10 @@ describe("resolveBranchSelectionTarget", () => {
|
||||
|
||||
it("keeps checkout in the current worktree for non-default refs", () => {
|
||||
expect(
|
||||
resolveBranchSelectionTarget({
|
||||
resolveRefSelectionTarget({
|
||||
activeProjectCwd: "/repo",
|
||||
activeWorktreePath: "/repo/.t3/worktrees/feature-a",
|
||||
refName: {
|
||||
ref: {
|
||||
isDefault: false,
|
||||
worktreePath: null,
|
||||
},
|
||||
@@ -411,36 +437,36 @@ describe("resolveBranchSelectionTarget", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldIncludeBranchPickerItem", () => {
|
||||
it("keeps the synthetic checkout PR item visible for gh pr checkout input", () => {
|
||||
describe("shouldIncludeRefPickerItem", () => {
|
||||
it("keeps the synthetic checkout change request item visible for change request input", () => {
|
||||
expect(
|
||||
shouldIncludeBranchPickerItem({
|
||||
shouldIncludeRefPickerItem({
|
||||
itemValue: "__checkout_pull_request__:1359",
|
||||
normalizedQuery: "gh pr checkout 1359",
|
||||
createBranchItemValue: "__create_new_branch__:gh pr checkout 1359",
|
||||
checkoutPullRequestItemValue: "__checkout_pull_request__:1359",
|
||||
createRefItemValue: "__create_new_branch__:gh pr checkout 1359",
|
||||
checkoutChangeRequestItemValue: "__checkout_pull_request__:1359",
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps the synthetic create-ref item visible for arbitrary ref input", () => {
|
||||
expect(
|
||||
shouldIncludeBranchPickerItem({
|
||||
shouldIncludeRefPickerItem({
|
||||
itemValue: "__create_new_branch__:feature/demo",
|
||||
normalizedQuery: "feature/demo",
|
||||
createBranchItemValue: "__create_new_branch__:feature/demo",
|
||||
checkoutPullRequestItemValue: null,
|
||||
createRefItemValue: "__create_new_branch__:feature/demo",
|
||||
checkoutChangeRequestItemValue: null,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("still filters ordinary ref items by query text", () => {
|
||||
expect(
|
||||
shouldIncludeBranchPickerItem({
|
||||
shouldIncludeRefPickerItem({
|
||||
itemValue: "main",
|
||||
normalizedQuery: "gh pr checkout 1359",
|
||||
createBranchItemValue: "__create_new_branch__:gh pr checkout 1359",
|
||||
checkoutPullRequestItemValue: "__checkout_pull_request__:1359",
|
||||
createRefItemValue: "__create_new_branch__:gh pr checkout 1359",
|
||||
checkoutChangeRequestItemValue: "__checkout_pull_request__:1359",
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import type { EnvironmentId, VcsRef, ProjectId } from "@t3tools/contracts";
|
||||
import { Schema } from "effect";
|
||||
export {
|
||||
dedupeRemoteBranchesWithLocalMatches,
|
||||
deriveLocalBranchNameFromRemoteRef,
|
||||
} from "@t3tools/shared/git";
|
||||
export { dedupeRemoteBranchesWithLocalMatches } from "@t3tools/shared/git";
|
||||
|
||||
export interface EnvironmentOption {
|
||||
environmentId: EnvironmentId;
|
||||
@@ -84,56 +81,55 @@ export function resolveDraftEnvModeAfterBranchChange(input: {
|
||||
return "local";
|
||||
}
|
||||
|
||||
export function resolveBranchToolbarValue(input: {
|
||||
export function resolveRefToolbarValue(input: {
|
||||
envMode: EnvMode;
|
||||
activeWorktreePath: string | null;
|
||||
activeThreadBranch: string | null;
|
||||
currentGitBranch: string | null;
|
||||
activeThreadRefName: string | null;
|
||||
currentRefName: string | null;
|
||||
}): string | null {
|
||||
const { envMode, activeWorktreePath, activeThreadBranch, currentGitBranch } = input;
|
||||
const { envMode, activeWorktreePath, activeThreadRefName, currentRefName } = input;
|
||||
if (envMode === "worktree" && !activeWorktreePath) {
|
||||
return activeThreadBranch ?? currentGitBranch;
|
||||
return activeThreadRefName ?? currentRefName;
|
||||
}
|
||||
return currentGitBranch ?? activeThreadBranch;
|
||||
return currentRefName ?? activeThreadRefName;
|
||||
}
|
||||
|
||||
export function resolveLocalCheckoutBranchMismatch(input: {
|
||||
export function resolveLocalCheckoutRefMismatch(input: {
|
||||
effectiveEnvMode: EnvMode;
|
||||
activeWorktreePath: string | null;
|
||||
activeThreadBranch: string | null;
|
||||
currentGitBranch: string | null;
|
||||
}): { threadBranch: string; currentBranch: string } | null {
|
||||
const { effectiveEnvMode, activeWorktreePath, activeThreadBranch, currentGitBranch } = input;
|
||||
activeThreadRefName: string | null;
|
||||
currentRefName: string | null;
|
||||
}): { threadRefName: string; currentRefName: string } | null {
|
||||
const { effectiveEnvMode, activeWorktreePath, activeThreadRefName, currentRefName } = input;
|
||||
if (effectiveEnvMode !== "local" || activeWorktreePath !== null) {
|
||||
return null;
|
||||
}
|
||||
if (!activeThreadBranch || !currentGitBranch || activeThreadBranch === currentGitBranch) {
|
||||
if (!activeThreadRefName || !currentRefName || activeThreadRefName === currentRefName) {
|
||||
return null;
|
||||
}
|
||||
return { threadBranch: activeThreadBranch, currentBranch: currentGitBranch };
|
||||
return { threadRefName: activeThreadRefName, currentRefName };
|
||||
}
|
||||
|
||||
export function resolveBranchSelectionTarget(input: {
|
||||
export function resolveRefSelectionTarget(input: {
|
||||
activeProjectCwd: string;
|
||||
activeWorktreePath: string | null;
|
||||
refName: Pick<VcsRef, "isDefault" | "worktreePath">;
|
||||
ref: Pick<VcsRef, "isDefault" | "worktreePath">;
|
||||
}): {
|
||||
checkoutCwd: string;
|
||||
nextWorktreePath: string | null;
|
||||
reuseExistingWorktree: boolean;
|
||||
} {
|
||||
const { activeProjectCwd, activeWorktreePath, refName } = input;
|
||||
const { activeProjectCwd, activeWorktreePath, ref } = input;
|
||||
|
||||
if (refName.worktreePath) {
|
||||
if (ref.worktreePath) {
|
||||
return {
|
||||
checkoutCwd: refName.worktreePath,
|
||||
nextWorktreePath: refName.worktreePath === activeProjectCwd ? null : refName.worktreePath,
|
||||
checkoutCwd: ref.worktreePath,
|
||||
nextWorktreePath: ref.worktreePath === activeProjectCwd ? null : ref.worktreePath,
|
||||
reuseExistingWorktree: true,
|
||||
};
|
||||
}
|
||||
|
||||
const nextWorktreePath =
|
||||
activeWorktreePath !== null && refName.isDefault ? null : activeWorktreePath;
|
||||
const nextWorktreePath = activeWorktreePath !== null && ref.isDefault ? null : activeWorktreePath;
|
||||
|
||||
return {
|
||||
checkoutCwd: nextWorktreePath ?? activeProjectCwd,
|
||||
@@ -142,25 +138,91 @@ export function resolveBranchSelectionTarget(input: {
|
||||
};
|
||||
}
|
||||
|
||||
export function shouldIncludeBranchPickerItem(input: {
|
||||
export function shouldIncludeRefPickerItem(input: {
|
||||
itemValue: string;
|
||||
normalizedQuery: string;
|
||||
createBranchItemValue: string | null;
|
||||
checkoutPullRequestItemValue: string | null;
|
||||
createRefItemValue: string | null;
|
||||
checkoutChangeRequestItemValue: string | null;
|
||||
}): boolean {
|
||||
const { itemValue, normalizedQuery, createBranchItemValue, checkoutPullRequestItemValue } = input;
|
||||
const { itemValue, normalizedQuery, createRefItemValue, checkoutChangeRequestItemValue } = input;
|
||||
|
||||
if (normalizedQuery.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (createBranchItemValue && itemValue === createBranchItemValue) {
|
||||
if (createRefItemValue && itemValue === createRefItemValue) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (checkoutPullRequestItemValue && itemValue === checkoutPullRequestItemValue) {
|
||||
if (checkoutChangeRequestItemValue && itemValue === checkoutChangeRequestItemValue) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return itemValue.toLowerCase().includes(normalizedQuery);
|
||||
}
|
||||
|
||||
export function resolveLocalRefNameFromRemoteRef(ref: Pick<VcsRef, "name" | "remoteName">): string {
|
||||
const remotePrefix = ref.remoteName ? `${ref.remoteName}/` : "";
|
||||
if (remotePrefix.length > 0 && ref.name.startsWith(remotePrefix)) {
|
||||
const localName = ref.name.slice(remotePrefix.length);
|
||||
return localName.length > 0 ? localName : ref.name;
|
||||
}
|
||||
return ref.name;
|
||||
}
|
||||
|
||||
export const resolveBranchToolbarValue = (input: {
|
||||
envMode: EnvMode;
|
||||
activeWorktreePath: string | null;
|
||||
activeThreadBranch: string | null;
|
||||
currentGitBranch: string | null;
|
||||
}) =>
|
||||
resolveRefToolbarValue({
|
||||
envMode: input.envMode,
|
||||
activeWorktreePath: input.activeWorktreePath,
|
||||
activeThreadRefName: input.activeThreadBranch,
|
||||
currentRefName: input.currentGitBranch,
|
||||
});
|
||||
|
||||
export const resolveLocalCheckoutBranchMismatch = (input: {
|
||||
effectiveEnvMode: EnvMode;
|
||||
activeWorktreePath: string | null;
|
||||
activeThreadBranch: string | null;
|
||||
currentGitBranch: string | null;
|
||||
}) => {
|
||||
const mismatch = resolveLocalCheckoutRefMismatch({
|
||||
effectiveEnvMode: input.effectiveEnvMode,
|
||||
activeWorktreePath: input.activeWorktreePath,
|
||||
activeThreadRefName: input.activeThreadBranch,
|
||||
currentRefName: input.currentGitBranch,
|
||||
});
|
||||
return mismatch
|
||||
? {
|
||||
threadBranch: mismatch.threadRefName,
|
||||
currentBranch: mismatch.currentRefName,
|
||||
}
|
||||
: null;
|
||||
};
|
||||
|
||||
export const resolveBranchSelectionTarget = (input: {
|
||||
activeProjectCwd: string;
|
||||
activeWorktreePath: string | null;
|
||||
refName: Pick<VcsRef, "isDefault" | "worktreePath">;
|
||||
}) =>
|
||||
resolveRefSelectionTarget({
|
||||
activeProjectCwd: input.activeProjectCwd,
|
||||
activeWorktreePath: input.activeWorktreePath,
|
||||
ref: input.refName,
|
||||
});
|
||||
|
||||
export const shouldIncludeBranchPickerItem = (input: {
|
||||
itemValue: string;
|
||||
normalizedQuery: string;
|
||||
createBranchItemValue: string | null;
|
||||
checkoutPullRequestItemValue: string | null;
|
||||
}) =>
|
||||
shouldIncludeRefPickerItem({
|
||||
itemValue: input.itemValue,
|
||||
normalizedQuery: input.normalizedQuery,
|
||||
createRefItemValue: input.createBranchItemValue,
|
||||
checkoutChangeRequestItemValue: input.checkoutPullRequestItemValue,
|
||||
});
|
||||
@@ -16,21 +16,21 @@ import {
|
||||
|
||||
import { useComposerDraftStore, type DraftId } from "../composerDraftStore";
|
||||
import { readEnvironmentApi } from "../environmentApi";
|
||||
import { gitBranchSearchInfiniteQueryOptions, gitQueryKeys } from "../lib/gitReactQuery";
|
||||
import { refreshGitStatus, useGitStatus } from "../lib/gitStatusState";
|
||||
import { vcsQueryKeys, vcsRefSearchInfiniteQueryOptions } from "../lib/vcsReactQuery";
|
||||
import { refreshVcsStatus, useVcsStatus } from "../lib/vcsStatusState";
|
||||
import { cn, newCommandId } from "../lib/utils";
|
||||
import { parsePullRequestReference } from "../pullRequestReference";
|
||||
import { getSourceControlPresentation } from "../sourceControlPresentation";
|
||||
import { useStore } from "../store";
|
||||
import { createProjectSelectorByRef, createThreadSelectorByRef } from "../storeSelectors";
|
||||
import {
|
||||
deriveLocalBranchNameFromRemoteRef,
|
||||
resolveBranchSelectionTarget,
|
||||
resolveBranchToolbarValue,
|
||||
resolveDraftEnvModeAfterBranchChange,
|
||||
resolveEffectiveEnvMode,
|
||||
resolveLocalCheckoutBranchMismatch,
|
||||
shouldIncludeBranchPickerItem,
|
||||
resolveLocalCheckoutRefMismatch,
|
||||
resolveLocalRefNameFromRemoteRef,
|
||||
resolveRefSelectionTarget,
|
||||
resolveRefToolbarValue,
|
||||
shouldIncludeRefPickerItem,
|
||||
} from "./BranchToolbar.logic";
|
||||
import { Button } from "./ui/button";
|
||||
import {
|
||||
@@ -60,23 +60,23 @@ interface BranchToolbarBranchSelectorProps {
|
||||
onComposerFocusRequest?: () => void;
|
||||
}
|
||||
|
||||
function toBranchActionErrorMessage(error: unknown): string {
|
||||
function toRefActionErrorMessage(error: unknown): string {
|
||||
return error instanceof Error ? error.message : "An error occurred.";
|
||||
}
|
||||
|
||||
function getBranchTriggerLabel(input: {
|
||||
function getRefTriggerLabel(input: {
|
||||
activeWorktreePath: string | null;
|
||||
effectiveEnvMode: "local" | "worktree";
|
||||
resolvedActiveBranch: string | null;
|
||||
resolvedActiveRefName: string | null;
|
||||
}): string {
|
||||
const { activeWorktreePath, effectiveEnvMode, resolvedActiveBranch } = input;
|
||||
if (!resolvedActiveBranch) {
|
||||
const { activeWorktreePath, effectiveEnvMode, resolvedActiveRefName } = input;
|
||||
if (!resolvedActiveRefName) {
|
||||
return "Select ref";
|
||||
}
|
||||
if (effectiveEnvMode === "worktree" && !activeWorktreePath) {
|
||||
return `From ${resolvedActiveBranch}`;
|
||||
return `From ${resolvedActiveRefName}`;
|
||||
}
|
||||
return resolvedActiveBranch;
|
||||
return resolvedActiveRefName;
|
||||
}
|
||||
|
||||
export function BranchToolbarBranchSelector({
|
||||
@@ -125,7 +125,7 @@ export function BranchToolbarBranchSelector({
|
||||
: (serverThread?.branch ?? draftThread?.branch ?? null);
|
||||
const activeWorktreePath = serverThread?.worktreePath ?? draftThread?.worktreePath ?? null;
|
||||
const activeProjectCwd = activeProject?.cwd ?? null;
|
||||
const branchCwd = activeWorktreePath ?? activeProjectCwd;
|
||||
const refCwd = activeWorktreePath ?? activeProjectCwd;
|
||||
const hasServerThread = serverThread !== undefined;
|
||||
const effectiveEnvMode =
|
||||
effectiveEnvModeOverride ??
|
||||
@@ -136,7 +136,7 @@ export function BranchToolbarBranchSelector({
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Thread branch mutation (colocated — only this component calls it)
|
||||
// Thread ref metadata mutation (colocated — only this component calls it)
|
||||
// ---------------------------------------------------------------------------
|
||||
const setThreadBranch = useCallback(
|
||||
(branch: string | null, worktreePath: string | null) => {
|
||||
@@ -195,186 +195,184 @@ export function BranchToolbarBranchSelector({
|
||||
);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Git ref queries
|
||||
// VCS ref queries
|
||||
// ---------------------------------------------------------------------------
|
||||
const queryClient = useQueryClient();
|
||||
const [isBranchMenuOpen, setIsBranchMenuOpen] = useState(false);
|
||||
const [isRefMenuOpen, setIsRefMenuOpen] = useState(false);
|
||||
const [isMismatchPopoverOpen, setIsMismatchPopoverOpen] = useState(false);
|
||||
const [branchQuery, setBranchQuery] = useState("");
|
||||
const branchPickerAnchorRef = useRef<HTMLDivElement | null>(null);
|
||||
const deferredBranchQuery = useDeferredValue(branchQuery);
|
||||
const [refQuery, setRefQuery] = useState("");
|
||||
const refPickerAnchorRef = useRef<HTMLDivElement | null>(null);
|
||||
const deferredRefQuery = useDeferredValue(refQuery);
|
||||
|
||||
const branchStatusQuery = useGitStatus({ environmentId, cwd: branchCwd });
|
||||
const trimmedBranchQuery = branchQuery.trim();
|
||||
const deferredTrimmedBranchQuery = deferredBranchQuery.trim();
|
||||
const vcsStatusQuery = useVcsStatus({ environmentId, cwd: refCwd });
|
||||
const trimmedRefQuery = refQuery.trim();
|
||||
const deferredTrimmedRefQuery = deferredRefQuery.trim();
|
||||
|
||||
useEffect(() => {
|
||||
if (!branchCwd) return;
|
||||
if (!refCwd) return;
|
||||
void queryClient.prefetchInfiniteQuery(
|
||||
gitBranchSearchInfiniteQueryOptions({ environmentId, cwd: branchCwd, query: "" }),
|
||||
vcsRefSearchInfiniteQueryOptions({ environmentId, cwd: refCwd, query: "" }),
|
||||
);
|
||||
}, [branchCwd, environmentId, queryClient]);
|
||||
}, [refCwd, environmentId, queryClient]);
|
||||
|
||||
const {
|
||||
data: branchesSearchData,
|
||||
data: refsSearchData,
|
||||
fetchNextPage,
|
||||
hasNextPage,
|
||||
isFetchingNextPage,
|
||||
isPending: isBranchesSearchPending,
|
||||
isPending: isRefsSearchPending,
|
||||
} = useInfiniteQuery(
|
||||
gitBranchSearchInfiniteQueryOptions({
|
||||
vcsRefSearchInfiniteQueryOptions({
|
||||
environmentId,
|
||||
cwd: branchCwd,
|
||||
query: deferredTrimmedBranchQuery,
|
||||
cwd: refCwd,
|
||||
query: deferredTrimmedRefQuery,
|
||||
}),
|
||||
);
|
||||
const refs = useMemo(
|
||||
() => branchesSearchData?.pages.flatMap((page) => page.refs) ?? [],
|
||||
[branchesSearchData?.pages],
|
||||
() => refsSearchData?.pages.flatMap((page) => page.refs) ?? [],
|
||||
[refsSearchData?.pages],
|
||||
);
|
||||
const currentGitBranch =
|
||||
branchStatusQuery.data?.refName ?? refs.find((refName) => refName.current)?.name ?? null;
|
||||
const currentRefName =
|
||||
vcsStatusQuery.data?.refName ?? refs.find((refName) => refName.current)?.name ?? null;
|
||||
const sourceControlPresentation = useMemo(
|
||||
() => getSourceControlPresentation(branchStatusQuery.data?.sourceControlProvider),
|
||||
[branchStatusQuery.data?.sourceControlProvider],
|
||||
() => getSourceControlPresentation(vcsStatusQuery.data?.sourceControlProvider),
|
||||
[vcsStatusQuery.data?.sourceControlProvider],
|
||||
);
|
||||
const SourceControlIcon = sourceControlPresentation.Icon;
|
||||
const canonicalActiveBranch = resolveBranchToolbarValue({
|
||||
const canonicalActiveRefName = resolveRefToolbarValue({
|
||||
envMode: effectiveEnvMode,
|
||||
activeWorktreePath,
|
||||
activeThreadBranch,
|
||||
currentGitBranch,
|
||||
activeThreadRefName: activeThreadBranch,
|
||||
currentRefName,
|
||||
});
|
||||
const localCheckoutBranchMismatch = resolveLocalCheckoutBranchMismatch({
|
||||
const localCheckoutRefMismatch = resolveLocalCheckoutRefMismatch({
|
||||
effectiveEnvMode,
|
||||
activeWorktreePath,
|
||||
activeThreadBranch,
|
||||
currentGitBranch,
|
||||
activeThreadRefName: activeThreadBranch,
|
||||
currentRefName,
|
||||
});
|
||||
const branchNames = useMemo(() => refs.map((refName) => refName.name), [refs]);
|
||||
const branchByName = useMemo(
|
||||
const refNames = useMemo(() => refs.map((refName) => refName.name), [refs]);
|
||||
const refByName = useMemo(
|
||||
() => new Map(refs.map((refName) => [refName.name, refName] as const)),
|
||||
[refs],
|
||||
);
|
||||
const normalizedDeferredBranchQuery = deferredTrimmedBranchQuery.toLowerCase();
|
||||
const prReference = parsePullRequestReference(trimmedBranchQuery);
|
||||
const normalizedDeferredRefQuery = deferredTrimmedRefQuery.toLowerCase();
|
||||
const changeRequestReference = parsePullRequestReference(trimmedRefQuery);
|
||||
const isSelectingWorktreeBase =
|
||||
effectiveEnvMode === "worktree" && !envLocked && !activeWorktreePath;
|
||||
const checkoutPullRequestItemValue =
|
||||
prReference && onCheckoutPullRequestRequest ? `__checkout_pull_request__:${prReference}` : null;
|
||||
const canCreateBranch = !isSelectingWorktreeBase && trimmedBranchQuery.length > 0;
|
||||
const hasExactBranchMatch = branchByName.has(trimmedBranchQuery);
|
||||
const createBranchItemValue = canCreateBranch
|
||||
? `__create_new_branch__:${trimmedBranchQuery}`
|
||||
: null;
|
||||
const branchPickerItems = useMemo(() => {
|
||||
const items = [...branchNames];
|
||||
if (createBranchItemValue && !hasExactBranchMatch) {
|
||||
items.push(createBranchItemValue);
|
||||
const checkoutChangeRequestItemValue =
|
||||
changeRequestReference && onCheckoutPullRequestRequest
|
||||
? `__checkout_change_request__:${changeRequestReference}`
|
||||
: null;
|
||||
const canCreateRef = !isSelectingWorktreeBase && trimmedRefQuery.length > 0;
|
||||
const hasExactRefMatch = refByName.has(trimmedRefQuery);
|
||||
const createRefItemValue = canCreateRef ? `__create_new_ref__:${trimmedRefQuery}` : null;
|
||||
const refPickerItems = useMemo(() => {
|
||||
const items = [...refNames];
|
||||
if (createRefItemValue && !hasExactRefMatch) {
|
||||
items.push(createRefItemValue);
|
||||
}
|
||||
if (checkoutPullRequestItemValue) {
|
||||
items.unshift(checkoutPullRequestItemValue);
|
||||
if (checkoutChangeRequestItemValue) {
|
||||
items.unshift(checkoutChangeRequestItemValue);
|
||||
}
|
||||
return items;
|
||||
}, [branchNames, checkoutPullRequestItemValue, createBranchItemValue, hasExactBranchMatch]);
|
||||
const filteredBranchPickerItems = useMemo(
|
||||
}, [refNames, checkoutChangeRequestItemValue, createRefItemValue, hasExactRefMatch]);
|
||||
const filteredRefPickerItems = useMemo(
|
||||
() =>
|
||||
normalizedDeferredBranchQuery.length === 0
|
||||
? branchPickerItems
|
||||
: branchPickerItems.filter((itemValue) =>
|
||||
shouldIncludeBranchPickerItem({
|
||||
normalizedDeferredRefQuery.length === 0
|
||||
? refPickerItems
|
||||
: refPickerItems.filter((itemValue) =>
|
||||
shouldIncludeRefPickerItem({
|
||||
itemValue,
|
||||
normalizedQuery: normalizedDeferredBranchQuery,
|
||||
createBranchItemValue,
|
||||
checkoutPullRequestItemValue,
|
||||
normalizedQuery: normalizedDeferredRefQuery,
|
||||
createRefItemValue,
|
||||
checkoutChangeRequestItemValue,
|
||||
}),
|
||||
),
|
||||
[
|
||||
branchPickerItems,
|
||||
checkoutPullRequestItemValue,
|
||||
createBranchItemValue,
|
||||
normalizedDeferredBranchQuery,
|
||||
refPickerItems,
|
||||
checkoutChangeRequestItemValue,
|
||||
createRefItemValue,
|
||||
normalizedDeferredRefQuery,
|
||||
],
|
||||
);
|
||||
const [resolvedActiveBranch, setOptimisticBranch] = useOptimistic(
|
||||
canonicalActiveBranch,
|
||||
(_currentBranch: string | null, optimisticBranch: string | null) => optimisticBranch,
|
||||
const [resolvedActiveRefName, setOptimisticRefName] = useOptimistic(
|
||||
canonicalActiveRefName,
|
||||
(_currentRefName: string | null, optimisticRefName: string | null) => optimisticRefName,
|
||||
);
|
||||
const [isBranchActionPending, startBranchActionTransition] = useTransition();
|
||||
const shouldVirtualizeBranchList = filteredBranchPickerItems.length > 40;
|
||||
const totalBranchCount = branchesSearchData?.pages[0]?.totalCount ?? 0;
|
||||
const branchStatusText = isBranchesSearchPending
|
||||
const [isRefActionPending, startRefActionTransition] = useTransition();
|
||||
const shouldVirtualizeRefList = filteredRefPickerItems.length > 40;
|
||||
const totalRefCount = refsSearchData?.pages[0]?.totalCount ?? 0;
|
||||
const refStatusText = isRefsSearchPending
|
||||
? "Loading refs..."
|
||||
: isFetchingNextPage
|
||||
? "Loading more refs..."
|
||||
: hasNextPage
|
||||
? `Showing ${refs.length} of ${totalBranchCount} refs`
|
||||
? `Showing ${refs.length} of ${totalRefCount} refs`
|
||||
: null;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Branch actions
|
||||
// Ref actions
|
||||
// ---------------------------------------------------------------------------
|
||||
const runBranchAction = (action: () => Promise<void>) => {
|
||||
startBranchActionTransition(async () => {
|
||||
const runRefAction = (action: () => Promise<void>) => {
|
||||
startRefActionTransition(async () => {
|
||||
await action().catch(() => undefined);
|
||||
await queryClient
|
||||
.invalidateQueries({ queryKey: gitQueryKeys.refs(environmentId, branchCwd) })
|
||||
.invalidateQueries({ queryKey: vcsQueryKeys.refs(environmentId, refCwd) })
|
||||
.catch(() => undefined);
|
||||
await refreshGitStatus({ environmentId, cwd: branchCwd }).catch(() => undefined);
|
||||
await refreshVcsStatus({ environmentId, cwd: refCwd }).catch(() => undefined);
|
||||
});
|
||||
};
|
||||
|
||||
const selectBranch = (refName: VcsRef) => {
|
||||
const selectRef = (ref: VcsRef) => {
|
||||
const api = readEnvironmentApi(environmentId);
|
||||
if (!api || !branchCwd || !activeProjectCwd || isBranchActionPending) return;
|
||||
if (!api || !refCwd || !activeProjectCwd || isRefActionPending) return;
|
||||
|
||||
if (isSelectingWorktreeBase) {
|
||||
setThreadBranch(refName.name, null);
|
||||
setIsBranchMenuOpen(false);
|
||||
setThreadBranch(ref.name, null);
|
||||
setIsRefMenuOpen(false);
|
||||
onComposerFocusRequest?.();
|
||||
return;
|
||||
}
|
||||
|
||||
const selectionTarget = resolveBranchSelectionTarget({
|
||||
const selectionTarget = resolveRefSelectionTarget({
|
||||
activeProjectCwd,
|
||||
activeWorktreePath,
|
||||
refName,
|
||||
ref,
|
||||
});
|
||||
|
||||
if (selectionTarget.reuseExistingWorktree) {
|
||||
setThreadBranch(refName.name, selectionTarget.nextWorktreePath);
|
||||
setIsBranchMenuOpen(false);
|
||||
setThreadBranch(ref.name, selectionTarget.nextWorktreePath);
|
||||
setIsRefMenuOpen(false);
|
||||
onComposerFocusRequest?.();
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedBranchName = refName.isRemote
|
||||
? deriveLocalBranchNameFromRemoteRef(refName.name)
|
||||
: refName.name;
|
||||
const selectedRefName = ref.isRemote ? resolveLocalRefNameFromRemoteRef(ref) : ref.name;
|
||||
|
||||
setIsBranchMenuOpen(false);
|
||||
setIsRefMenuOpen(false);
|
||||
onComposerFocusRequest?.();
|
||||
|
||||
runBranchAction(async () => {
|
||||
const previousBranch = resolvedActiveBranch;
|
||||
setOptimisticBranch(selectedBranchName);
|
||||
runRefAction(async () => {
|
||||
const previousRefName = resolvedActiveRefName;
|
||||
setOptimisticRefName(selectedRefName);
|
||||
try {
|
||||
const checkoutResult = await api.vcs.switchRef({
|
||||
cwd: selectionTarget.checkoutCwd,
|
||||
refName: refName.name,
|
||||
refName: ref.name,
|
||||
});
|
||||
const nextBranchName = refName.isRemote
|
||||
? (checkoutResult.refName ?? selectedBranchName)
|
||||
: selectedBranchName;
|
||||
setOptimisticBranch(nextBranchName);
|
||||
setThreadBranch(nextBranchName, selectionTarget.nextWorktreePath);
|
||||
const nextRefName = ref.isRemote
|
||||
? (checkoutResult.refName ?? selectedRefName)
|
||||
: selectedRefName;
|
||||
setOptimisticRefName(nextRefName);
|
||||
setThreadBranch(nextRefName, selectionTarget.nextWorktreePath);
|
||||
} catch (error) {
|
||||
setOptimisticBranch(previousBranch);
|
||||
setOptimisticRefName(previousRefName);
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "error",
|
||||
title: "Failed to switch ref.",
|
||||
description: toBranchActionErrorMessage(error),
|
||||
description: toRefActionErrorMessage(error),
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -384,29 +382,29 @@ export function BranchToolbarBranchSelector({
|
||||
const createRef = (rawName: string) => {
|
||||
const name = rawName.trim();
|
||||
const api = readEnvironmentApi(environmentId);
|
||||
if (!api || !branchCwd || !name || isBranchActionPending) return;
|
||||
if (!api || !refCwd || !name || isRefActionPending) return;
|
||||
|
||||
setIsBranchMenuOpen(false);
|
||||
setIsRefMenuOpen(false);
|
||||
onComposerFocusRequest?.();
|
||||
|
||||
runBranchAction(async () => {
|
||||
const previousBranch = resolvedActiveBranch;
|
||||
setOptimisticBranch(name);
|
||||
runRefAction(async () => {
|
||||
const previousRefName = resolvedActiveRefName;
|
||||
setOptimisticRefName(name);
|
||||
try {
|
||||
const createBranchResult = await api.vcs.createRef({
|
||||
cwd: branchCwd,
|
||||
const createRefResult = await api.vcs.createRef({
|
||||
cwd: refCwd,
|
||||
refName: name,
|
||||
switchRef: true,
|
||||
});
|
||||
setOptimisticBranch(createBranchResult.refName);
|
||||
setThreadBranch(createBranchResult.refName, activeWorktreePath);
|
||||
setOptimisticRefName(createRefResult.refName);
|
||||
setThreadBranch(createRefResult.refName, activeWorktreePath);
|
||||
} catch (error) {
|
||||
setOptimisticBranch(previousBranch);
|
||||
setOptimisticRefName(previousRefName);
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "error",
|
||||
title: "Failed to create and switch ref.",
|
||||
description: toBranchActionErrorMessage(error),
|
||||
description: toRefActionErrorMessage(error),
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -415,28 +413,28 @@ export function BranchToolbarBranchSelector({
|
||||
|
||||
const switchCheckoutToThreadBranch = () => {
|
||||
const api = readEnvironmentApi(environmentId);
|
||||
if (!api || !activeProjectCwd || !localCheckoutBranchMismatch || isBranchActionPending) {
|
||||
if (!api || !activeProjectCwd || !localCheckoutRefMismatch || isRefActionPending) {
|
||||
return;
|
||||
}
|
||||
|
||||
runBranchAction(async () => {
|
||||
const previousBranch = resolvedActiveBranch;
|
||||
setOptimisticBranch(localCheckoutBranchMismatch.threadBranch);
|
||||
runRefAction(async () => {
|
||||
const previousRefName = resolvedActiveRefName;
|
||||
setOptimisticRefName(localCheckoutRefMismatch.threadRefName);
|
||||
try {
|
||||
const switchResult = await api.vcs.switchRef({
|
||||
cwd: activeProjectCwd,
|
||||
refName: localCheckoutBranchMismatch.threadBranch,
|
||||
refName: localCheckoutRefMismatch.threadRefName,
|
||||
});
|
||||
setOptimisticBranch(switchResult.refName ?? localCheckoutBranchMismatch.threadBranch);
|
||||
setOptimisticRefName(switchResult.refName ?? localCheckoutRefMismatch.threadRefName);
|
||||
setIsMismatchPopoverOpen(false);
|
||||
onComposerFocusRequest?.();
|
||||
} catch (error) {
|
||||
setOptimisticBranch(previousBranch);
|
||||
setOptimisticRefName(previousRefName);
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "error",
|
||||
title: "Failed to switch checkout.",
|
||||
description: toBranchActionErrorMessage(error),
|
||||
description: toRefActionErrorMessage(error),
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -444,11 +442,11 @@ export function BranchToolbarBranchSelector({
|
||||
};
|
||||
|
||||
const useCurrentCheckoutForThread = () => {
|
||||
if (!localCheckoutBranchMismatch || isBranchActionPending) {
|
||||
if (!localCheckoutRefMismatch || isRefActionPending) {
|
||||
return;
|
||||
}
|
||||
|
||||
setThreadBranch(localCheckoutBranchMismatch.currentBranch, null);
|
||||
setThreadBranch(localCheckoutRefMismatch.currentRefName, null);
|
||||
setIsMismatchPopoverOpen(false);
|
||||
onComposerFocusRequest?.();
|
||||
};
|
||||
@@ -458,37 +456,37 @@ export function BranchToolbarBranchSelector({
|
||||
effectiveEnvMode !== "worktree" ||
|
||||
activeWorktreePath ||
|
||||
activeThreadBranch ||
|
||||
!currentGitBranch
|
||||
!currentRefName
|
||||
) {
|
||||
return;
|
||||
}
|
||||
setThreadBranch(currentGitBranch, null);
|
||||
}, [activeThreadBranch, activeWorktreePath, currentGitBranch, effectiveEnvMode, setThreadBranch]);
|
||||
setThreadBranch(currentRefName, null);
|
||||
}, [activeThreadBranch, activeWorktreePath, currentRefName, effectiveEnvMode, setThreadBranch]);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Combobox / list plumbing
|
||||
// ---------------------------------------------------------------------------
|
||||
const handleOpenChange = useCallback(
|
||||
(open: boolean) => {
|
||||
setIsBranchMenuOpen(open);
|
||||
setIsRefMenuOpen(open);
|
||||
if (!open) {
|
||||
setBranchQuery("");
|
||||
setRefQuery("");
|
||||
return;
|
||||
}
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: gitQueryKeys.refs(environmentId, branchCwd),
|
||||
queryKey: vcsQueryKeys.refs(environmentId, refCwd),
|
||||
});
|
||||
},
|
||||
[branchCwd, environmentId, queryClient],
|
||||
[refCwd, environmentId, queryClient],
|
||||
);
|
||||
|
||||
const branchListScrollElementRef = useRef<HTMLDivElement | null>(null);
|
||||
const maybeFetchNextBranchPage = useCallback(() => {
|
||||
if (!isBranchMenuOpen || !hasNextPage || isFetchingNextPage) {
|
||||
const refListScrollElementRef = useRef<HTMLDivElement | null>(null);
|
||||
const maybeFetchNextRefPage = useCallback(() => {
|
||||
if (!isRefMenuOpen || !hasNextPage || isFetchingNextPage) {
|
||||
return;
|
||||
}
|
||||
|
||||
const scrollElement = branchListScrollElementRef.current;
|
||||
const scrollElement = refListScrollElementRef.current;
|
||||
if (!scrollElement) {
|
||||
return;
|
||||
}
|
||||
@@ -500,32 +498,32 @@ export function BranchToolbarBranchSelector({
|
||||
}
|
||||
|
||||
void fetchNextPage().catch(() => undefined);
|
||||
}, [fetchNextPage, hasNextPage, isBranchMenuOpen, isFetchingNextPage]);
|
||||
const branchListRef = useRef<LegendListRef | null>(null);
|
||||
const setBranchListRef = useCallback((element: HTMLDivElement | null) => {
|
||||
branchListScrollElementRef.current = (element?.parentElement as HTMLDivElement | null) ?? null;
|
||||
}, [fetchNextPage, hasNextPage, isRefMenuOpen, isFetchingNextPage]);
|
||||
const refListRef = useRef<LegendListRef | null>(null);
|
||||
const setRefListRef = useCallback((element: HTMLDivElement | null) => {
|
||||
refListScrollElementRef.current = (element?.parentElement as HTMLDivElement | null) ?? null;
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isBranchMenuOpen) {
|
||||
if (!isRefMenuOpen) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldVirtualizeBranchList) {
|
||||
branchListRef.current?.scrollToOffset?.({ offset: 0, animated: false });
|
||||
if (shouldVirtualizeRefList) {
|
||||
refListRef.current?.scrollToOffset?.({ offset: 0, animated: false });
|
||||
} else {
|
||||
branchListScrollElementRef.current?.scrollTo({ top: 0 });
|
||||
refListScrollElementRef.current?.scrollTo({ top: 0 });
|
||||
}
|
||||
}, [deferredTrimmedBranchQuery, isBranchMenuOpen, shouldVirtualizeBranchList]);
|
||||
}, [deferredTrimmedRefQuery, isRefMenuOpen, shouldVirtualizeRefList]);
|
||||
|
||||
useEffect(() => {
|
||||
const scrollElement = branchListScrollElementRef.current;
|
||||
if (!scrollElement || !isBranchMenuOpen) {
|
||||
const scrollElement = refListScrollElementRef.current;
|
||||
if (!scrollElement || !isRefMenuOpen) {
|
||||
return;
|
||||
}
|
||||
|
||||
const handleScroll = () => {
|
||||
maybeFetchNextBranchPage();
|
||||
maybeFetchNextRefPage();
|
||||
};
|
||||
|
||||
scrollElement.addEventListener("scroll", handleScroll, { passive: true });
|
||||
@@ -533,21 +531,21 @@ export function BranchToolbarBranchSelector({
|
||||
return () => {
|
||||
scrollElement.removeEventListener("scroll", handleScroll);
|
||||
};
|
||||
}, [isBranchMenuOpen, maybeFetchNextBranchPage]);
|
||||
}, [isRefMenuOpen, maybeFetchNextRefPage]);
|
||||
|
||||
useEffect(() => {
|
||||
if (shouldVirtualizeBranchList) return;
|
||||
maybeFetchNextBranchPage();
|
||||
}, [refs.length, maybeFetchNextBranchPage, shouldVirtualizeBranchList]);
|
||||
if (shouldVirtualizeRefList) return;
|
||||
maybeFetchNextRefPage();
|
||||
}, [refs.length, maybeFetchNextRefPage, shouldVirtualizeRefList]);
|
||||
|
||||
const triggerLabel = getBranchTriggerLabel({
|
||||
const triggerLabel = getRefTriggerLabel({
|
||||
activeWorktreePath,
|
||||
effectiveEnvMode,
|
||||
resolvedActiveBranch,
|
||||
resolvedActiveRefName,
|
||||
});
|
||||
|
||||
function renderPickerItem(itemValue: string, index: number) {
|
||||
if (checkoutPullRequestItemValue && itemValue === checkoutPullRequestItemValue) {
|
||||
if (checkoutChangeRequestItemValue && itemValue === checkoutChangeRequestItemValue) {
|
||||
return (
|
||||
<ComboboxItem
|
||||
hideIndicator
|
||||
@@ -555,13 +553,13 @@ export function BranchToolbarBranchSelector({
|
||||
index={index}
|
||||
value={itemValue}
|
||||
onClick={() => {
|
||||
if (!prReference || !onCheckoutPullRequestRequest) {
|
||||
if (!changeRequestReference || !onCheckoutPullRequestRequest) {
|
||||
return;
|
||||
}
|
||||
setIsBranchMenuOpen(false);
|
||||
setBranchQuery("");
|
||||
setIsRefMenuOpen(false);
|
||||
setRefQuery("");
|
||||
onComposerFocusRequest?.();
|
||||
onCheckoutPullRequestRequest(prReference);
|
||||
onCheckoutPullRequestRequest(changeRequestReference);
|
||||
}}
|
||||
>
|
||||
<div className="flex min-w-0 items-center gap-2 py-1">
|
||||
@@ -570,38 +568,40 @@ export function BranchToolbarBranchSelector({
|
||||
<span className="truncate font-medium">
|
||||
Checkout {sourceControlPresentation.terminology.singular}
|
||||
</span>
|
||||
<span className="truncate text-muted-foreground text-xs">{prReference}</span>
|
||||
<span className="truncate text-muted-foreground text-xs">
|
||||
{changeRequestReference}
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</ComboboxItem>
|
||||
);
|
||||
}
|
||||
if (createBranchItemValue && itemValue === createBranchItemValue) {
|
||||
if (createRefItemValue && itemValue === createRefItemValue) {
|
||||
return (
|
||||
<ComboboxItem
|
||||
hideIndicator
|
||||
key={itemValue}
|
||||
index={index}
|
||||
value={itemValue}
|
||||
onClick={() => createRef(trimmedBranchQuery)}
|
||||
onClick={() => createRef(trimmedRefQuery)}
|
||||
>
|
||||
<span className="truncate">Create new ref "{trimmedBranchQuery}"</span>
|
||||
<span className="truncate">Create new ref "{trimmedRefQuery}"</span>
|
||||
</ComboboxItem>
|
||||
);
|
||||
}
|
||||
|
||||
const refName = branchByName.get(itemValue);
|
||||
if (!refName) return null;
|
||||
const ref = refByName.get(itemValue);
|
||||
if (!ref) return null;
|
||||
|
||||
const hasSecondaryWorktree =
|
||||
refName.worktreePath && activeProjectCwd && refName.worktreePath !== activeProjectCwd;
|
||||
const badge = refName.current
|
||||
ref.worktreePath && activeProjectCwd && ref.worktreePath !== activeProjectCwd;
|
||||
const badge = ref.current
|
||||
? "current"
|
||||
: hasSecondaryWorktree
|
||||
? "worktree"
|
||||
: refName.isRemote
|
||||
: ref.isRemote
|
||||
? "remote"
|
||||
: refName.isDefault
|
||||
: ref.isDefault
|
||||
? "default"
|
||||
: null;
|
||||
return (
|
||||
@@ -610,7 +610,7 @@ export function BranchToolbarBranchSelector({
|
||||
key={itemValue}
|
||||
index={index}
|
||||
value={itemValue}
|
||||
onClick={() => selectBranch(refName)}
|
||||
onClick={() => selectRef(ref)}
|
||||
>
|
||||
<div className="flex w-full items-center justify-between gap-2">
|
||||
<span className="truncate">{itemValue}</span>
|
||||
@@ -621,8 +621,11 @@ export function BranchToolbarBranchSelector({
|
||||
}
|
||||
|
||||
return (
|
||||
<div ref={branchPickerAnchorRef} className="relative flex min-w-0 items-center justify-end">
|
||||
{localCheckoutBranchMismatch ? (
|
||||
<div
|
||||
ref={refPickerAnchorRef}
|
||||
className={cn("relative flex min-w-0 items-center justify-end", className)}
|
||||
>
|
||||
{localCheckoutRefMismatch ? (
|
||||
<Popover open={isMismatchPopoverOpen} onOpenChange={setIsMismatchPopoverOpen}>
|
||||
<PopoverTrigger
|
||||
openOnHover
|
||||
@@ -643,23 +646,23 @@ export function BranchToolbarBranchSelector({
|
||||
side="top"
|
||||
align="center"
|
||||
sideOffset={8}
|
||||
anchor={branchPickerAnchorRef}
|
||||
anchor={refPickerAnchorRef}
|
||||
className="w-[28rem] max-w-[calc(100vw-2rem)] px-2 py-2"
|
||||
>
|
||||
<div className="chat-markdown space-y-2.5 text-xs leading-snug">
|
||||
<div className="grid grid-cols-[5.25rem_minmax(0,1fr)] gap-x-2.5 gap-y-1.5">
|
||||
<span className="text-muted-foreground">Thread</span>
|
||||
<code className="max-w-full justify-self-start">
|
||||
{localCheckoutBranchMismatch.threadBranch}
|
||||
{localCheckoutRefMismatch.threadRefName}
|
||||
</code>
|
||||
<span className="text-muted-foreground">Checkout</span>
|
||||
<code className="max-w-full justify-self-start">
|
||||
{localCheckoutBranchMismatch.currentBranch}
|
||||
{localCheckoutRefMismatch.currentRefName}
|
||||
</code>
|
||||
</div>
|
||||
<p className="!my-0 border-border/70 border-t pt-2 text-muted-foreground">
|
||||
This thread was last associated with{" "}
|
||||
<code>{localCheckoutBranchMismatch.threadBranch}</code>, but your checkout is on
|
||||
<code>{localCheckoutRefMismatch.threadRefName}</code>, but your checkout is on
|
||||
another ref. Switch to keep working there, or use current to update the thread to
|
||||
this checkout.
|
||||
</p>
|
||||
@@ -668,8 +671,8 @@ export function BranchToolbarBranchSelector({
|
||||
variant="ghost"
|
||||
size="xs"
|
||||
className="h-6 px-1.5 text-[11px] text-muted-foreground hover:text-foreground"
|
||||
disabled={isBranchActionPending}
|
||||
title={`Associate this thread with ${localCheckoutBranchMismatch.currentBranch}`}
|
||||
disabled={isRefActionPending}
|
||||
title={`Associate this thread with ${localCheckoutRefMismatch.currentRefName}`}
|
||||
onClick={useCurrentCheckoutForThread}
|
||||
>
|
||||
Use current
|
||||
@@ -678,8 +681,8 @@ export function BranchToolbarBranchSelector({
|
||||
variant="outline"
|
||||
size="xs"
|
||||
className="h-6 px-1.5 text-[11px]"
|
||||
disabled={isBranchActionPending}
|
||||
title={`Switch to ${localCheckoutBranchMismatch.threadBranch}`}
|
||||
disabled={isRefActionPending}
|
||||
title={`Switch to ${localCheckoutRefMismatch.threadRefName}`}
|
||||
onClick={switchCheckoutToThreadBranch}
|
||||
>
|
||||
Switch
|
||||
@@ -690,32 +693,31 @@ export function BranchToolbarBranchSelector({
|
||||
</Popover>
|
||||
) : null}
|
||||
<Combobox
|
||||
items={branchPickerItems}
|
||||
filteredItems={filteredBranchPickerItems}
|
||||
items={refPickerItems}
|
||||
filteredItems={filteredRefPickerItems}
|
||||
autoHighlight
|
||||
virtualized={shouldVirtualizeBranchList}
|
||||
virtualized={shouldVirtualizeRefList}
|
||||
onItemHighlighted={(_value, eventDetails) => {
|
||||
if (!isBranchMenuOpen || eventDetails.index < 0 || eventDetails.reason !== "keyboard") {
|
||||
if (!isRefMenuOpen || eventDetails.index < 0 || eventDetails.reason !== "keyboard") {
|
||||
return;
|
||||
}
|
||||
branchListRef.current?.scrollIndexIntoView?.({
|
||||
refListRef.current?.scrollIndexIntoView?.({
|
||||
index: eventDetails.index,
|
||||
animated: false,
|
||||
});
|
||||
}}
|
||||
onOpenChange={handleOpenChange}
|
||||
open={isBranchMenuOpen}
|
||||
value={resolvedActiveBranch}
|
||||
open={isRefMenuOpen}
|
||||
value={resolvedActiveRefName}
|
||||
>
|
||||
<ComboboxTrigger
|
||||
render={<Button variant="ghost" size="xs" />}
|
||||
className={cn(
|
||||
"min-w-0 text-muted-foreground/70 hover:text-foreground/80",
|
||||
localCheckoutBranchMismatch &&
|
||||
localCheckoutRefMismatch &&
|
||||
"border-warning/35 bg-warning/10 pl-7 text-warning hover:bg-warning/15 hover:text-warning",
|
||||
className,
|
||||
)}
|
||||
disabled={(isBranchesSearchPending && refs.length === 0) || isBranchActionPending}
|
||||
disabled={(isRefsSearchPending && refs.length === 0) || isRefActionPending}
|
||||
>
|
||||
<span className="min-w-0 max-w-[240px] truncate">{triggerLabel}</span>
|
||||
<ChevronDownIcon className="shrink-0" />
|
||||
@@ -728,17 +730,17 @@ export function BranchToolbarBranchSelector({
|
||||
placeholder="Search refs..."
|
||||
showTrigger={false}
|
||||
size="sm"
|
||||
value={branchQuery}
|
||||
onChange={(event) => setBranchQuery(event.target.value)}
|
||||
value={refQuery}
|
||||
onChange={(event) => setRefQuery(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<ComboboxEmpty>No refs found.</ComboboxEmpty>
|
||||
|
||||
{shouldVirtualizeBranchList ? (
|
||||
{shouldVirtualizeRefList ? (
|
||||
<ComboboxListVirtualized>
|
||||
<LegendList<string>
|
||||
ref={branchListRef}
|
||||
data={filteredBranchPickerItems}
|
||||
ref={refListRef}
|
||||
data={filteredRefPickerItems}
|
||||
keyExtractor={(item) => item}
|
||||
renderItem={({ item, index }) => renderPickerItem(item, index)}
|
||||
estimatedItemSize={28}
|
||||
@@ -752,13 +754,11 @@ export function BranchToolbarBranchSelector({
|
||||
/>
|
||||
</ComboboxListVirtualized>
|
||||
) : (
|
||||
<ComboboxList ref={setBranchListRef} className="max-h-56">
|
||||
{filteredBranchPickerItems.map((itemValue, index) =>
|
||||
renderPickerItem(itemValue, index),
|
||||
)}
|
||||
<ComboboxList ref={setRefListRef} className="max-h-56">
|
||||
{filteredRefPickerItems.map((itemValue, index) => renderPickerItem(itemValue, index))}
|
||||
</ComboboxList>
|
||||
)}
|
||||
{branchStatusText ? <ComboboxStatus>{branchStatusText}</ComboboxStatus> : null}
|
||||
{refStatusText ? <ComboboxStatus>{refStatusText}</ComboboxStatus> : null}
|
||||
</ComboboxPopup>
|
||||
</Combobox>
|
||||
</div>
|
||||
|
||||
@@ -136,6 +136,43 @@ vi.mock("~/lib/gitStatusState", () => ({
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock("~/lib/vcsStatusState", () => ({
|
||||
refreshVcsStatus: refreshGitStatusSpy,
|
||||
resetVcsStatusStateForTests: () => undefined,
|
||||
useVcsStatus: vi.fn(() => ({
|
||||
data: {
|
||||
isRepo: true,
|
||||
sourceControlProvider: {
|
||||
kind: "github",
|
||||
name: "GitHub",
|
||||
baseUrl: "https://github.com",
|
||||
},
|
||||
hasPrimaryRemote: true,
|
||||
isDefaultRef: false,
|
||||
refName: BRANCH_NAME,
|
||||
hasWorkingTreeChanges: false,
|
||||
hasUpstream: true,
|
||||
aheadCount: 1,
|
||||
behindCount: 0,
|
||||
aheadOfDefaultCount: 1,
|
||||
workingTree: {
|
||||
files: [
|
||||
{
|
||||
path: "src/example.ts",
|
||||
insertions: 1,
|
||||
deletions: 0,
|
||||
},
|
||||
],
|
||||
insertions: 1,
|
||||
deletions: 0,
|
||||
},
|
||||
pr: null,
|
||||
},
|
||||
error: null,
|
||||
isPending: false,
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock("~/localApi", () => ({
|
||||
ensureLocalApi: vi.fn(() => {
|
||||
throw new Error("ensureLocalApi not implemented in browser test");
|
||||
|
||||
@@ -45,7 +45,7 @@ import {
|
||||
gitPullMutationOptions,
|
||||
gitRunStackedActionMutationOptions,
|
||||
} from "~/lib/gitReactQuery";
|
||||
import { refreshGitStatus, useGitStatus } from "~/lib/gitStatusState";
|
||||
import { refreshVcsStatus, useVcsStatus } from "~/lib/vcsStatusState";
|
||||
import { newCommandId, randomUUID } from "~/lib/utils";
|
||||
import { resolvePathLinkTarget } from "~/terminal-links";
|
||||
import { type DraftId, useComposerDraftStore } from "~/composerDraftStore";
|
||||
@@ -331,7 +331,7 @@ export default function GitActionsControl({
|
||||
[persistThreadBranchSync],
|
||||
);
|
||||
|
||||
const { data: gitStatus = null, error: gitStatusError } = useGitStatus({
|
||||
const { data: gitStatus = null, error: gitStatusError } = useVcsStatus({
|
||||
environmentId: activeEnvironmentId,
|
||||
cwd: gitCwd,
|
||||
});
|
||||
@@ -451,7 +451,7 @@ export default function GitActionsControl({
|
||||
}
|
||||
refreshTimeout = window.setTimeout(() => {
|
||||
refreshTimeout = null;
|
||||
void refreshGitStatus({ environmentId: activeEnvironmentId, cwd: gitCwd }).catch(
|
||||
void refreshVcsStatus({ environmentId: activeEnvironmentId, cwd: gitCwd }).catch(
|
||||
() => undefined,
|
||||
);
|
||||
}, GIT_STATUS_WINDOW_REFRESH_DEBOUNCE_MS);
|
||||
@@ -939,7 +939,7 @@ export default function GitActionsControl({
|
||||
<Menu
|
||||
onOpenChange={(open) => {
|
||||
if (open) {
|
||||
void refreshGitStatus({
|
||||
void refreshVcsStatus({
|
||||
environmentId: activeEnvironmentId,
|
||||
cwd: gitCwd,
|
||||
}).catch(() => undefined);
|
||||
|
||||
@@ -83,7 +83,7 @@ import {
|
||||
} from "../keybindings";
|
||||
import { useModelPickerOpen } from "../modelPickerOpenState";
|
||||
import { useShortcutModifierState } from "../shortcutModifierState";
|
||||
import { useGitStatus } from "../lib/gitStatusState";
|
||||
import { useVcsStatus } from "../lib/vcsStatusState";
|
||||
import { readLocalApi } from "../localApi";
|
||||
import { useComposerDraftStore } from "../composerDraftStore";
|
||||
import { useNewThreadHandler } from "../hooks/useHandleNewThread";
|
||||
@@ -343,8 +343,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
|
||||
? (remoteEnvLabel ?? remoteEnvSavedLabel ?? "Remote")
|
||||
: null;
|
||||
// For grouped projects, the thread may belong to a different environment
|
||||
// than the representative project. Look up the thread's own project cwd
|
||||
// so git status (and thus PR detection) queries the correct path.
|
||||
// than the representative project. Look up the thread's own project cwd
|
||||
// so VCS status (and thus change request detection) queries the correct path.
|
||||
const threadProjectCwd = useStore(
|
||||
useMemo(
|
||||
() => (state: import("../store").AppState) =>
|
||||
@@ -354,7 +354,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
|
||||
),
|
||||
);
|
||||
const gitCwd = thread.worktreePath ?? threadProjectCwd ?? props.projectCwd;
|
||||
const gitStatus = useGitStatus({
|
||||
const vcsStatus = useVcsStatus({
|
||||
environmentId: thread.environmentId,
|
||||
cwd: thread.branch != null || thread.worktreePath !== null ? gitCwd : null,
|
||||
});
|
||||
@@ -369,10 +369,10 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
|
||||
});
|
||||
const pr = resolveThreadPr({
|
||||
threadBranch: thread.branch,
|
||||
gitStatus: gitStatus.data,
|
||||
vcsStatus: vcsStatus.data,
|
||||
hasDedicatedWorktree: thread.worktreePath !== null,
|
||||
});
|
||||
const prStatus = prStatusIndicator(pr, gitStatus.data?.sourceControlProvider);
|
||||
const prStatus = prStatusIndicator(pr, vcsStatus.data?.sourceControlProvider);
|
||||
const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds);
|
||||
const isConfirmingArchive = confirmingArchiveThreadKey === threadKey && !isThreadRunning;
|
||||
const threadMetaClassName = isConfirmingArchive
|
||||
|
||||
@@ -31,34 +31,34 @@ describe("resolveThreadPr", () => {
|
||||
expect(
|
||||
resolveThreadPr({
|
||||
threadBranch: "feature/other",
|
||||
gitStatus: status(),
|
||||
vcsStatus: status(),
|
||||
hasDedicatedWorktree: false,
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("shows PR indicators for dedicated worktree threads even when branch metadata is stale", () => {
|
||||
const gitStatus = status();
|
||||
const vcsStatus = status();
|
||||
|
||||
expect(
|
||||
resolveThreadPr({
|
||||
threadBranch: "feature/old-name",
|
||||
gitStatus,
|
||||
vcsStatus,
|
||||
hasDedicatedWorktree: true,
|
||||
}),
|
||||
).toBe(gitStatus.pr);
|
||||
).toBe(vcsStatus.pr);
|
||||
});
|
||||
|
||||
it("shows PR indicators for dedicated worktree threads even when branch metadata is missing", () => {
|
||||
const gitStatus = status();
|
||||
const vcsStatus = status();
|
||||
|
||||
expect(
|
||||
resolveThreadPr({
|
||||
threadBranch: null,
|
||||
gitStatus,
|
||||
vcsStatus,
|
||||
hasDedicatedWorktree: true,
|
||||
}),
|
||||
).toBe(gitStatus.pr);
|
||||
).toBe(vcsStatus.pr);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
useSavedEnvironmentRegistryStore,
|
||||
useSavedEnvironmentRuntimeStore,
|
||||
} from "../environments/runtime";
|
||||
import { useGitStatus } from "../lib/gitStatusState";
|
||||
import { useVcsStatus } from "../lib/vcsStatusState";
|
||||
import { type AppState, selectProjectByRef, useStore } from "../store";
|
||||
import { selectThreadTerminalState, useTerminalStateStore } from "../terminalStateStore";
|
||||
import { useUiStateStore } from "../uiStateStore";
|
||||
@@ -96,23 +96,23 @@ export function PrStatusTooltipContent({ status }: { status: PrStatusIndicator }
|
||||
|
||||
export function resolveThreadPr(input: {
|
||||
threadBranch: string | null;
|
||||
gitStatus: VcsStatusResult | null;
|
||||
vcsStatus: VcsStatusResult | null;
|
||||
hasDedicatedWorktree: boolean;
|
||||
}): ThreadPr | null {
|
||||
const { threadBranch, gitStatus, hasDedicatedWorktree } = input;
|
||||
if (gitStatus === null) {
|
||||
const { threadBranch, vcsStatus, hasDedicatedWorktree } = input;
|
||||
if (vcsStatus === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (hasDedicatedWorktree) {
|
||||
return gitStatus.pr ?? null;
|
||||
return vcsStatus.pr ?? null;
|
||||
}
|
||||
|
||||
if (threadBranch === null || gitStatus.refName !== threadBranch) {
|
||||
if (threadBranch === null || vcsStatus.refName !== threadBranch) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return gitStatus.pr ?? null;
|
||||
return vcsStatus.pr ?? null;
|
||||
}
|
||||
|
||||
export function ChangeRequestStatusIcon({ className }: { className?: string }) {
|
||||
@@ -189,16 +189,16 @@ export function ThreadRowLeadingStatus({ thread }: { thread: SidebarThreadSummar
|
||||
),
|
||||
);
|
||||
const gitCwd = thread.worktreePath ?? threadProjectCwd;
|
||||
const gitStatus = useGitStatus({
|
||||
const vcsStatus = useVcsStatus({
|
||||
environmentId: thread.environmentId,
|
||||
cwd: thread.branch != null || thread.worktreePath !== null ? gitCwd : null,
|
||||
});
|
||||
const pr = resolveThreadPr({
|
||||
threadBranch: thread.branch,
|
||||
gitStatus: gitStatus.data,
|
||||
vcsStatus: vcsStatus.data,
|
||||
hasDedicatedWorktree: thread.worktreePath !== null,
|
||||
});
|
||||
const prStatus = prStatusIndicator(pr, gitStatus.data?.sourceControlProvider);
|
||||
const prStatus = prStatusIndicator(pr, vcsStatus.data?.sourceControlProvider);
|
||||
const threadStatus = resolveThreadStatusPill({
|
||||
thread: {
|
||||
...thread,
|
||||
|
||||
@@ -13,16 +13,21 @@ import {
|
||||
import { ensureEnvironmentApi } from "../environmentApi";
|
||||
import { requireEnvironmentConnection } from "../environments/runtime";
|
||||
|
||||
const GIT_BRANCHES_STALE_TIME_MS = 15_000;
|
||||
const GIT_BRANCHES_REFETCH_INTERVAL_MS = 60_000;
|
||||
const GIT_BRANCHES_PAGE_SIZE = 100;
|
||||
const VCS_REFS_STALE_TIME_MS = 15_000;
|
||||
const VCS_REFS_REFETCH_INTERVAL_MS = 60_000;
|
||||
const VCS_REFS_PAGE_SIZE = 100;
|
||||
|
||||
export const vcsQueryKeys = {
|
||||
all: ["vcs"] as const,
|
||||
refs: (environmentId: EnvironmentId | null, cwd: string | null) =>
|
||||
["vcs", "refs", environmentId ?? null, cwd] as const,
|
||||
refSearch: (environmentId: EnvironmentId | null, cwd: string | null, query: string) =>
|
||||
["vcs", "refs", environmentId ?? null, cwd, "search", query] as const,
|
||||
};
|
||||
|
||||
export const gitQueryKeys = {
|
||||
all: ["git"] as const,
|
||||
refs: (environmentId: EnvironmentId | null, cwd: string | null) =>
|
||||
["git", "refs", environmentId ?? null, cwd] as const,
|
||||
branchSearch: (environmentId: EnvironmentId | null, cwd: string | null, query: string) =>
|
||||
["git", "refs", environmentId ?? null, cwd, "search", query] as const,
|
||||
...vcsQueryKeys,
|
||||
branchSearch: vcsQueryKeys.refSearch,
|
||||
};
|
||||
|
||||
export const gitMutationKeys = {
|
||||
@@ -45,13 +50,13 @@ export function invalidateGitQueries(
|
||||
const environmentId = input?.environmentId ?? null;
|
||||
const cwd = input?.cwd ?? null;
|
||||
if (cwd !== null) {
|
||||
return queryClient.invalidateQueries({ queryKey: gitQueryKeys.refs(environmentId, cwd) });
|
||||
return queryClient.invalidateQueries({ queryKey: vcsQueryKeys.refs(environmentId, cwd) });
|
||||
}
|
||||
|
||||
return queryClient.invalidateQueries({ queryKey: gitQueryKeys.all });
|
||||
return queryClient.invalidateQueries({ queryKey: vcsQueryKeys.all });
|
||||
}
|
||||
|
||||
function invalidateGitBranchQueries(
|
||||
function invalidateVcsRefQueries(
|
||||
queryClient: QueryClient,
|
||||
environmentId: EnvironmentId | null,
|
||||
cwd: string | null,
|
||||
@@ -60,13 +65,10 @@ function invalidateGitBranchQueries(
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return queryClient.invalidateQueries({ queryKey: gitQueryKeys.refs(environmentId, cwd) });
|
||||
return queryClient.invalidateQueries({ queryKey: vcsQueryKeys.refs(environmentId, cwd) });
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use a VCS-named query helper once the UI naming migration lands.
|
||||
*/
|
||||
export function gitBranchSearchInfiniteQueryOptions(input: {
|
||||
export function vcsRefSearchInfiniteQueryOptions(input: {
|
||||
environmentId: EnvironmentId | null;
|
||||
cwd: string | null;
|
||||
query: string;
|
||||
@@ -75,28 +77,30 @@ export function gitBranchSearchInfiniteQueryOptions(input: {
|
||||
const normalizedQuery = input.query.trim();
|
||||
|
||||
return infiniteQueryOptions({
|
||||
queryKey: gitQueryKeys.branchSearch(input.environmentId, input.cwd, normalizedQuery),
|
||||
queryKey: vcsQueryKeys.refSearch(input.environmentId, input.cwd, normalizedQuery),
|
||||
initialPageParam: 0,
|
||||
queryFn: async ({ pageParam }) => {
|
||||
if (!input.cwd) throw new Error("Git refs are unavailable.");
|
||||
if (!input.environmentId) throw new Error("Git refs are unavailable.");
|
||||
if (!input.cwd) throw new Error("VCS refs are unavailable.");
|
||||
if (!input.environmentId) throw new Error("VCS refs are unavailable.");
|
||||
const api = ensureEnvironmentApi(input.environmentId);
|
||||
return api.vcs.listRefs({
|
||||
cwd: input.cwd,
|
||||
...(normalizedQuery.length > 0 ? { query: normalizedQuery } : {}),
|
||||
cursor: pageParam,
|
||||
limit: GIT_BRANCHES_PAGE_SIZE,
|
||||
limit: VCS_REFS_PAGE_SIZE,
|
||||
});
|
||||
},
|
||||
getNextPageParam: (lastPage) => lastPage.nextCursor ?? undefined,
|
||||
enabled: input.cwd !== null && (input.enabled ?? true),
|
||||
staleTime: GIT_BRANCHES_STALE_TIME_MS,
|
||||
staleTime: VCS_REFS_STALE_TIME_MS,
|
||||
refetchOnWindowFocus: true,
|
||||
refetchOnReconnect: true,
|
||||
refetchInterval: GIT_BRANCHES_REFETCH_INTERVAL_MS,
|
||||
refetchInterval: VCS_REFS_REFETCH_INTERVAL_MS,
|
||||
});
|
||||
}
|
||||
|
||||
export const gitBranchSearchInfiniteQueryOptions = vcsRefSearchInfiniteQueryOptions;
|
||||
|
||||
export function gitResolvePullRequestQueryOptions(input: {
|
||||
environmentId: EnvironmentId | null;
|
||||
cwd: string | null;
|
||||
@@ -140,7 +144,7 @@ export function gitInitMutationOptions(input: {
|
||||
return api.vcs.init({ cwd: input.cwd });
|
||||
},
|
||||
onSettled: async () => {
|
||||
await invalidateGitBranchQueries(input.queryClient, input.environmentId, input.cwd);
|
||||
await invalidateVcsRefQueries(input.queryClient, input.environmentId, input.cwd);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -161,7 +165,7 @@ export function gitCheckoutMutationOptions(input: {
|
||||
return api.vcs.switchRef({ cwd: input.cwd, refName });
|
||||
},
|
||||
onSettled: async () => {
|
||||
await invalidateGitBranchQueries(input.queryClient, input.environmentId, input.cwd);
|
||||
await invalidateVcsRefQueries(input.queryClient, input.environmentId, input.cwd);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -202,7 +206,7 @@ export function gitRunStackedActionMutationOptions(input: {
|
||||
);
|
||||
},
|
||||
onSuccess: async () => {
|
||||
await invalidateGitBranchQueries(input.queryClient, input.environmentId, input.cwd);
|
||||
await invalidateVcsRefQueries(input.queryClient, input.environmentId, input.cwd);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -223,7 +227,7 @@ export function gitPullMutationOptions(input: {
|
||||
return api.vcs.pull({ cwd: input.cwd });
|
||||
},
|
||||
onSuccess: async () => {
|
||||
await invalidateGitBranchQueries(input.queryClient, input.environmentId, input.cwd);
|
||||
await invalidateVcsRefQueries(input.queryClient, input.environmentId, input.cwd);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -298,7 +302,7 @@ export function gitPreparePullRequestThreadMutationOptions(input: {
|
||||
});
|
||||
},
|
||||
onSuccess: async () => {
|
||||
await invalidateGitBranchQueries(input.queryClient, input.environmentId, input.cwd);
|
||||
await invalidateVcsRefQueries(input.queryClient, input.environmentId, input.cwd);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -15,61 +15,61 @@ import {
|
||||
} from "../environments/runtime";
|
||||
import type { WsRpcClient } from "~/rpc/wsRpcClient";
|
||||
|
||||
interface GitStatusState {
|
||||
interface VcsStatusState {
|
||||
readonly data: VcsStatusResult | null;
|
||||
readonly error: GitManagerServiceError | null;
|
||||
readonly cause: Cause.Cause<GitManagerServiceError> | null;
|
||||
readonly isPending: boolean;
|
||||
}
|
||||
|
||||
type GitStatusClient = Pick<WsRpcClient["vcs"], "onStatus" | "refreshStatus">;
|
||||
interface ResolvedGitStatusClient {
|
||||
type VcsStatusClient = Pick<WsRpcClient["vcs"], "onStatus" | "refreshStatus">;
|
||||
interface ResolvedVcsStatusClient {
|
||||
readonly clientIdentity: string;
|
||||
readonly client: GitStatusClient;
|
||||
readonly client: VcsStatusClient;
|
||||
}
|
||||
|
||||
interface WatchedGitStatus {
|
||||
interface WatchedVcsStatus {
|
||||
refCount: number;
|
||||
unsubscribe: () => void;
|
||||
}
|
||||
|
||||
interface GitStatusTarget {
|
||||
interface VcsStatusTarget {
|
||||
readonly environmentId: EnvironmentId | null;
|
||||
readonly cwd: string | null;
|
||||
}
|
||||
|
||||
const EMPTY_GIT_STATUS_STATE = Object.freeze<GitStatusState>({
|
||||
const EMPTY_VCS_STATUS_STATE = Object.freeze<VcsStatusState>({
|
||||
data: null,
|
||||
error: null,
|
||||
cause: null,
|
||||
isPending: false,
|
||||
});
|
||||
const INITIAL_GIT_STATUS_STATE = Object.freeze<GitStatusState>({
|
||||
...EMPTY_GIT_STATUS_STATE,
|
||||
const INITIAL_VCS_STATUS_STATE = Object.freeze<VcsStatusState>({
|
||||
...EMPTY_VCS_STATUS_STATE,
|
||||
isPending: true,
|
||||
});
|
||||
const EMPTY_GIT_STATUS_ATOM = Atom.make(EMPTY_GIT_STATUS_STATE).pipe(
|
||||
const EMPTY_VCS_STATUS_ATOM = Atom.make(EMPTY_VCS_STATUS_STATE).pipe(
|
||||
Atom.keepAlive,
|
||||
Atom.withLabel("git-status:null"),
|
||||
Atom.withLabel("vcs-status:null"),
|
||||
);
|
||||
|
||||
const NOOP: () => void = () => undefined;
|
||||
const watchedGitStatuses = new Map<string, WatchedGitStatus>();
|
||||
const knownGitStatusKeys = new Set<string>();
|
||||
const gitStatusRefreshInFlight = new Map<string, Promise<VcsStatusResult>>();
|
||||
const gitStatusLastRefreshAtByKey = new Map<string, number>();
|
||||
const watchedVcsStatuses = new Map<string, WatchedVcsStatus>();
|
||||
const knownVcsStatusKeys = new Set<string>();
|
||||
const vcsStatusRefreshInFlight = new Map<string, Promise<VcsStatusResult>>();
|
||||
const vcsStatusLastRefreshAtByKey = new Map<string, number>();
|
||||
|
||||
const GIT_STATUS_REFRESH_DEBOUNCE_MS = 1_000;
|
||||
const VCS_STATUS_REFRESH_DEBOUNCE_MS = 1_000;
|
||||
|
||||
const gitStatusStateAtom = Atom.family((key: string) => {
|
||||
knownGitStatusKeys.add(key);
|
||||
return Atom.make(INITIAL_GIT_STATUS_STATE).pipe(
|
||||
const vcsStatusStateAtom = Atom.family((key: string) => {
|
||||
knownVcsStatusKeys.add(key);
|
||||
return Atom.make(INITIAL_VCS_STATUS_STATE).pipe(
|
||||
Atom.keepAlive,
|
||||
Atom.withLabel(`git-status:${key}`),
|
||||
Atom.withLabel(`vcs-status:${key}`),
|
||||
);
|
||||
});
|
||||
|
||||
function getGitStatusTargetKey(target: GitStatusTarget): string | null {
|
||||
function getVcsStatusTargetKey(target: VcsStatusTarget): string | null {
|
||||
if (target.environmentId === null || target.cwd === null) {
|
||||
return null;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ function getGitStatusTargetKey(target: GitStatusTarget): string | null {
|
||||
return `${target.environmentId}:${target.cwd}`;
|
||||
}
|
||||
|
||||
function readResolvedGitStatusClient(target: GitStatusTarget): ResolvedGitStatusClient | null {
|
||||
function readResolvedVcsStatusClient(target: VcsStatusTarget): ResolvedVcsStatusClient | null {
|
||||
if (target.environmentId === null) {
|
||||
return null;
|
||||
}
|
||||
@@ -87,96 +87,96 @@ function readResolvedGitStatusClient(target: GitStatusTarget): ResolvedGitStatus
|
||||
: null;
|
||||
}
|
||||
|
||||
export function getGitStatusSnapshot(target: GitStatusTarget): GitStatusState {
|
||||
const targetKey = getGitStatusTargetKey(target);
|
||||
export function getVcsStatusSnapshot(target: VcsStatusTarget): VcsStatusState {
|
||||
const targetKey = getVcsStatusTargetKey(target);
|
||||
if (targetKey === null) {
|
||||
return EMPTY_GIT_STATUS_STATE;
|
||||
return EMPTY_VCS_STATUS_STATE;
|
||||
}
|
||||
|
||||
return appAtomRegistry.get(gitStatusStateAtom(targetKey));
|
||||
return appAtomRegistry.get(vcsStatusStateAtom(targetKey));
|
||||
}
|
||||
|
||||
export function watchGitStatus(target: GitStatusTarget, client?: GitStatusClient): () => void {
|
||||
const targetKey = getGitStatusTargetKey(target);
|
||||
export function watchVcsStatus(target: VcsStatusTarget, client?: VcsStatusClient): () => void {
|
||||
const targetKey = getVcsStatusTargetKey(target);
|
||||
if (targetKey === null) {
|
||||
return NOOP;
|
||||
}
|
||||
|
||||
const watched = watchedGitStatuses.get(targetKey);
|
||||
const watched = watchedVcsStatuses.get(targetKey);
|
||||
if (watched) {
|
||||
watched.refCount += 1;
|
||||
return () => unwatchGitStatus(targetKey);
|
||||
return () => unwatchVcsStatus(targetKey);
|
||||
}
|
||||
|
||||
watchedGitStatuses.set(targetKey, {
|
||||
watchedVcsStatuses.set(targetKey, {
|
||||
refCount: 1,
|
||||
unsubscribe: subscribeToGitStatusTarget(targetKey, target, client),
|
||||
unsubscribe: subscribeToVcsStatusTarget(targetKey, target, client),
|
||||
});
|
||||
|
||||
return () => unwatchGitStatus(targetKey);
|
||||
return () => unwatchVcsStatus(targetKey);
|
||||
}
|
||||
|
||||
export function refreshGitStatus(
|
||||
target: GitStatusTarget,
|
||||
client?: GitStatusClient,
|
||||
export function refreshVcsStatus(
|
||||
target: VcsStatusTarget,
|
||||
client?: VcsStatusClient,
|
||||
): Promise<VcsStatusResult | null> {
|
||||
const targetKey = getGitStatusTargetKey(target);
|
||||
const targetKey = getVcsStatusTargetKey(target);
|
||||
if (targetKey === null || target.cwd === null) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
const resolvedClient = client ?? readResolvedGitStatusClient(target)?.client;
|
||||
const resolvedClient = client ?? readResolvedVcsStatusClient(target)?.client;
|
||||
if (!resolvedClient) {
|
||||
return Promise.resolve(getGitStatusSnapshot(target).data);
|
||||
return Promise.resolve(getVcsStatusSnapshot(target).data);
|
||||
}
|
||||
|
||||
const currentInFlight = gitStatusRefreshInFlight.get(targetKey);
|
||||
const currentInFlight = vcsStatusRefreshInFlight.get(targetKey);
|
||||
if (currentInFlight) {
|
||||
return currentInFlight;
|
||||
}
|
||||
|
||||
const lastRequestedAt = gitStatusLastRefreshAtByKey.get(targetKey) ?? 0;
|
||||
if (Date.now() - lastRequestedAt < GIT_STATUS_REFRESH_DEBOUNCE_MS) {
|
||||
return Promise.resolve(getGitStatusSnapshot(target).data);
|
||||
const lastRequestedAt = vcsStatusLastRefreshAtByKey.get(targetKey) ?? 0;
|
||||
if (Date.now() - lastRequestedAt < VCS_STATUS_REFRESH_DEBOUNCE_MS) {
|
||||
return Promise.resolve(getVcsStatusSnapshot(target).data);
|
||||
}
|
||||
|
||||
gitStatusLastRefreshAtByKey.set(targetKey, Date.now());
|
||||
vcsStatusLastRefreshAtByKey.set(targetKey, Date.now());
|
||||
const refreshPromise = resolvedClient.refreshStatus({ cwd: target.cwd }).finally(() => {
|
||||
gitStatusRefreshInFlight.delete(targetKey);
|
||||
vcsStatusRefreshInFlight.delete(targetKey);
|
||||
});
|
||||
gitStatusRefreshInFlight.set(targetKey, refreshPromise);
|
||||
vcsStatusRefreshInFlight.set(targetKey, refreshPromise);
|
||||
return refreshPromise;
|
||||
}
|
||||
|
||||
export function resetGitStatusStateForTests(): void {
|
||||
for (const watched of watchedGitStatuses.values()) {
|
||||
export function resetVcsStatusStateForTests(): void {
|
||||
for (const watched of watchedVcsStatuses.values()) {
|
||||
watched.unsubscribe();
|
||||
}
|
||||
watchedGitStatuses.clear();
|
||||
gitStatusRefreshInFlight.clear();
|
||||
gitStatusLastRefreshAtByKey.clear();
|
||||
watchedVcsStatuses.clear();
|
||||
vcsStatusRefreshInFlight.clear();
|
||||
vcsStatusLastRefreshAtByKey.clear();
|
||||
|
||||
for (const key of knownGitStatusKeys) {
|
||||
appAtomRegistry.set(gitStatusStateAtom(key), INITIAL_GIT_STATUS_STATE);
|
||||
for (const key of knownVcsStatusKeys) {
|
||||
appAtomRegistry.set(vcsStatusStateAtom(key), INITIAL_VCS_STATUS_STATE);
|
||||
}
|
||||
knownGitStatusKeys.clear();
|
||||
knownVcsStatusKeys.clear();
|
||||
}
|
||||
|
||||
export function useGitStatus(target: GitStatusTarget): GitStatusState {
|
||||
const targetKey = getGitStatusTargetKey(target);
|
||||
export function useVcsStatus(target: VcsStatusTarget): VcsStatusState {
|
||||
const targetKey = getVcsStatusTargetKey(target);
|
||||
useEffect(
|
||||
() => watchGitStatus({ environmentId: target.environmentId, cwd: target.cwd }),
|
||||
() => watchVcsStatus({ environmentId: target.environmentId, cwd: target.cwd }),
|
||||
[target.environmentId, target.cwd],
|
||||
);
|
||||
|
||||
const state = useAtomValue(
|
||||
targetKey !== null ? gitStatusStateAtom(targetKey) : EMPTY_GIT_STATUS_ATOM,
|
||||
targetKey !== null ? vcsStatusStateAtom(targetKey) : EMPTY_VCS_STATUS_ATOM,
|
||||
);
|
||||
return targetKey === null ? EMPTY_GIT_STATUS_STATE : state;
|
||||
return targetKey === null ? EMPTY_VCS_STATUS_STATE : state;
|
||||
}
|
||||
|
||||
function unwatchGitStatus(targetKey: string): void {
|
||||
const watched = watchedGitStatuses.get(targetKey);
|
||||
function unwatchVcsStatus(targetKey: string): void {
|
||||
const watched = watchedVcsStatuses.get(targetKey);
|
||||
if (!watched) {
|
||||
return;
|
||||
}
|
||||
@@ -187,13 +187,13 @@ function unwatchGitStatus(targetKey: string): void {
|
||||
}
|
||||
|
||||
watched.unsubscribe();
|
||||
watchedGitStatuses.delete(targetKey);
|
||||
watchedVcsStatuses.delete(targetKey);
|
||||
}
|
||||
|
||||
function subscribeToGitStatusTarget(
|
||||
function subscribeToVcsStatusTarget(
|
||||
targetKey: string,
|
||||
target: GitStatusTarget,
|
||||
providedClient?: GitStatusClient,
|
||||
target: VcsStatusTarget,
|
||||
providedClient?: VcsStatusClient,
|
||||
): () => void {
|
||||
if (target.cwd === null) {
|
||||
return NOOP;
|
||||
@@ -209,7 +209,7 @@ function subscribeToGitStatusTarget(
|
||||
clientIdentity: `provided:${targetKey}`,
|
||||
client: providedClient,
|
||||
}
|
||||
: readResolvedGitStatusClient(target);
|
||||
: readResolvedVcsStatusClient(target);
|
||||
|
||||
if (!resolved) {
|
||||
if (currentClientIdentity !== null) {
|
||||
@@ -217,7 +217,7 @@ function subscribeToGitStatusTarget(
|
||||
currentUnsubscribe = NOOP;
|
||||
currentClientIdentity = null;
|
||||
}
|
||||
markGitStatusPending(targetKey);
|
||||
markVcsStatusPending(targetKey);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ function subscribeToGitStatusTarget(
|
||||
|
||||
currentUnsubscribe();
|
||||
currentClientIdentity = resolved.clientIdentity;
|
||||
currentUnsubscribe = subscribeToGitStatus(targetKey, cwd, resolved.client);
|
||||
currentUnsubscribe = subscribeToVcsStatus(targetKey, cwd, resolved.client);
|
||||
};
|
||||
|
||||
const unsubscribeRegistry = providedClient
|
||||
@@ -241,12 +241,12 @@ function subscribeToGitStatusTarget(
|
||||
};
|
||||
}
|
||||
|
||||
function subscribeToGitStatus(targetKey: string, cwd: string, client: GitStatusClient): () => void {
|
||||
markGitStatusPending(targetKey);
|
||||
function subscribeToVcsStatus(targetKey: string, cwd: string, client: VcsStatusClient): () => void {
|
||||
markVcsStatusPending(targetKey);
|
||||
return client.onStatus(
|
||||
{ cwd },
|
||||
(status: VcsStatusResult) => {
|
||||
appAtomRegistry.set(gitStatusStateAtom(targetKey), {
|
||||
appAtomRegistry.set(vcsStatusStateAtom(targetKey), {
|
||||
data: status,
|
||||
error: null,
|
||||
cause: null,
|
||||
@@ -255,18 +255,18 @@ function subscribeToGitStatus(targetKey: string, cwd: string, client: GitStatusC
|
||||
},
|
||||
{
|
||||
onResubscribe: () => {
|
||||
markGitStatusPending(targetKey);
|
||||
markVcsStatusPending(targetKey);
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function markGitStatusPending(targetKey: string): void {
|
||||
const atom = gitStatusStateAtom(targetKey);
|
||||
function markVcsStatusPending(targetKey: string): void {
|
||||
const atom = vcsStatusStateAtom(targetKey);
|
||||
const current = appAtomRegistry.get(atom);
|
||||
const next =
|
||||
current.data === null
|
||||
? INITIAL_GIT_STATUS_STATE
|
||||
? INITIAL_VCS_STATUS_STATE
|
||||
: {
|
||||
...current,
|
||||
error: null,
|
||||
@@ -285,3 +285,9 @@ function markGitStatusPending(targetKey: string): void {
|
||||
|
||||
appAtomRegistry.set(atom, next);
|
||||
}
|
||||
|
||||
export const getGitStatusSnapshot = getVcsStatusSnapshot;
|
||||
export const watchGitStatus = watchVcsStatus;
|
||||
export const refreshGitStatus = refreshVcsStatus;
|
||||
export const resetGitStatusStateForTests = resetVcsStatusStateForTests;
|
||||
export const useGitStatus = useVcsStatus;
|
||||
@@ -0,0 +1 @@
|
||||
export { vcsQueryKeys, vcsRefSearchInfiniteQueryOptions } from "./gitReactQuery";
|
||||
@@ -0,0 +1,7 @@
|
||||
export {
|
||||
getVcsStatusSnapshot,
|
||||
refreshVcsStatus,
|
||||
resetVcsStatusStateForTests,
|
||||
useVcsStatus,
|
||||
watchVcsStatus,
|
||||
} from "./gitStatusState";
|
||||
Reference in new issue
Block a user