Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

Show origin ref in branch trigger label (#4680)

Julius Marmingea2ffb122e204
diff --git a/apps/web/src/components/BranchToolbar.logic.test.ts b/apps/web/src/components/BranchToolbar.logic.test.ts
index e59ffc8f6..76336f1ef 100644
--- a/apps/web/src/components/BranchToolbar.logic.test.ts
+++ b/apps/web/src/components/BranchToolbar.logic.test.ts
@@ -9,6 +9,7 @@ import {
resolveDraftEnvModeAfterBranchChange,
resolveEffectiveEnvMode,
resolveEnvModeLabel,
+ resolveBranchTriggerLabel,
resolveBranchToolbarPrBranch,
resolveBranchToolbarValue,
resolveLockedWorkspaceLabel,
@@ -174,6 +175,101 @@ describe("resolveBranchToolbarValue", () => {
});
});
+describe("resolveBranchTriggerLabel", () => {
+ it("shows the origin ref when a new worktree will start from origin", () => {
+ expect(
+ resolveBranchTriggerLabel({
+ activeWorktreePath: null,
+ effectiveEnvMode: "worktree",
+ resolvedActiveBranch: "main",
+ resolvedActiveBranchIsRemote: false,
+ startFromOrigin: true,
+ }),
+ ).toBe("From origin/main");
+ });
+
+ it("shows the origin ref for local branch names that contain slashes", () => {
+ expect(
+ resolveBranchTriggerLabel({
+ activeWorktreePath: null,
+ effectiveEnvMode: "worktree",
+ resolvedActiveBranch: "feature/demo",
+ resolvedActiveBranchIsRemote: false,
+ startFromOrigin: true,
+ }),
+ ).toBe("From origin/feature/demo");
+ });
+
+ it("shows the local ref when start from origin is disabled", () => {
+ expect(
+ resolveBranchTriggerLabel({
+ activeWorktreePath: null,
+ effectiveEnvMode: "worktree",
+ resolvedActiveBranch: "main",
+ resolvedActiveBranchIsRemote: false,
+ startFromOrigin: false,
+ }),
+ ).toBe("From main");
+ });
+
+ it("does not duplicate the origin prefix for an explicit remote ref", () => {
+ expect(
+ resolveBranchTriggerLabel({
+ activeWorktreePath: null,
+ effectiveEnvMode: "worktree",
+ resolvedActiveBranch: "origin/feature/demo",
+ resolvedActiveBranchIsRemote: true,
+ startFromOrigin: true,
+ }),
+ ).toBe("From origin/feature/demo");
+ });
+
+ it("preserves an explicit ref from a non-origin remote", () => {
+ expect(
+ resolveBranchTriggerLabel({
+ activeWorktreePath: null,
+ effectiveEnvMode: "worktree",
+ resolvedActiveBranch: "upstream/feature/demo",
+ resolvedActiveBranchIsRemote: true,
+ startFromOrigin: true,
+ }),
+ ).toBe("From upstream/feature/demo");
+ });
+
+ it("keeps current-checkout labels and empty state unchanged", () => {
+ expect(
+ resolveBranchTriggerLabel({
+ activeWorktreePath: null,
+ effectiveEnvMode: "local",
+ resolvedActiveBranch: "main",
+ resolvedActiveBranchIsRemote: false,
+ startFromOrigin: true,
+ }),
+ ).toBe("main");
+ expect(
+ resolveBranchTriggerLabel({
+ activeWorktreePath: null,
+ effectiveEnvMode: "worktree",
+ resolvedActiveBranch: null,
+ resolvedActiveBranchIsRemote: null,
+ startFromOrigin: true,
+ }),
+ ).toBe("Select ref");
+ });
+
+ it("does not fabricate an origin ref while branch metadata is loading", () => {
+ expect(
+ resolveBranchTriggerLabel({
+ activeWorktreePath: null,
+ effectiveEnvMode: "worktree",
+ resolvedActiveBranch: "upstream/feature/demo",
+ resolvedActiveBranchIsRemote: null,
+ startFromOrigin: true,
+ }),
+ ).toBe("From upstream/feature/demo");
+ });
+});
+
describe("resolveBranchToolbarPrBranch", () => {
it("uses the explicit thread branch when it matches the displayed branch", () => {
expect(
diff --git a/apps/web/src/components/BranchToolbar.logic.ts b/apps/web/src/components/BranchToolbar.logic.ts
index 3549eff6e..d9737f17a 100644
--- a/apps/web/src/components/BranchToolbar.logic.ts
+++ b/apps/web/src/components/BranchToolbar.logic.ts
@@ -156,6 +156,33 @@ export function resolveBranchToolbarValue(input: {
return currentGitBranch ?? activeThreadBranch;
}
+export function resolveBranchTriggerLabel(input: {
+ activeWorktreePath: string | null;
+ effectiveEnvMode: EnvMode;
+ resolvedActiveBranch: string | null;
+ resolvedActiveBranchIsRemote: boolean | null;
+ startFromOrigin: boolean;
+}): string {
+ const {
+ activeWorktreePath,
+ effectiveEnvMode,
+ resolvedActiveBranch,
+ resolvedActiveBranchIsRemote,
+ startFromOrigin,
+ } = input;
+ if (!resolvedActiveBranch) {
+ return "Select ref";
+ }
+ if (effectiveEnvMode === "worktree" && !activeWorktreePath) {
+ const baseRef =
+ startFromOrigin && resolvedActiveBranchIsRemote === false
+ ? `origin/${resolvedActiveBranch}`
+ : resolvedActiveBranch;
+ return `From ${baseRef}`;
+ }
+ return resolvedActiveBranch;
+}
+
export function resolveBranchToolbarPrBranch(input: {
activeThreadBranch: string | null;
resolvedActiveBranch: string | null;
diff --git a/apps/web/src/components/BranchToolbarBranchSelector.tsx b/apps/web/src/components/BranchToolbarBranchSelector.tsx
index 74138fa52..c4ae50a9e 100644
--- a/apps/web/src/components/BranchToolbarBranchSelector.tsx
+++ b/apps/web/src/components/BranchToolbarBranchSelector.tsx
@@ -35,6 +35,7 @@ import { parsePullRequestReference } from "../pullRequestReference";
import { getSourceControlPresentation } from "../sourceControlPresentation";
import {
deriveLocalBranchNameFromRemoteRef,
+ resolveBranchTriggerLabel,
resolveBranchToolbarPrBranch,
resolveBranchSelectionTarget,
resolveBranchToolbarValue,
@@ -81,21 +82,6 @@ function toBranchActionErrorMessage(error: unknown): string {
return error instanceof Error ? error.message : "An error occurred.";
}
-function getBranchTriggerLabel(input: {
- activeWorktreePath: string | null;
- effectiveEnvMode: "local" | "worktree";
- resolvedActiveBranch: string | null;
-}): string {
- const { activeWorktreePath, effectiveEnvMode, resolvedActiveBranch } = input;
- if (!resolvedActiveBranch) {
- return "Select ref";
- }
- if (effectiveEnvMode === "worktree" && !activeWorktreePath) {
- return `From ${resolvedActiveBranch}`;
- }
- return resolvedActiveBranch;
-}
-
export function BranchToolbarBranchSelector({
className,
environmentId,
@@ -308,6 +294,29 @@ export function BranchToolbarBranchSelector({
canonicalActiveBranch,
(_currentBranch: string | null, optimisticBranch: string | null) => optimisticBranch,
);
+ const listedActiveBranch =
+ resolvedActiveBranch === null ? null : (branchByName.get(resolvedActiveBranch) ?? null);
+ const activeBranchRefQuery = useEnvironmentQuery(
+ branchCwd !== null && resolvedActiveBranch !== null
+ ? vcsEnvironment.listRefs({
+ environmentId,
+ input: {
+ cwd: branchCwd,
+ query: resolvedActiveBranch,
+ limit: 10,
+ },
+ })
+ : null,
+ );
+ const queriedActiveBranch = activeBranchRefQuery.data?.refs.find(
+ (refName) => refName.name === resolvedActiveBranch,
+ );
+ const resolvedActiveBranchIsRemote =
+ listedActiveBranch !== null
+ ? listedActiveBranch.isRemote === true
+ : queriedActiveBranch
+ ? queriedActiveBranch.isRemote === true
+ : null;
const [isBranchActionPending, startBranchActionTransition] = useTransition();
const totalBranchCount = branchRefState.data?.totalCount ?? 0;
const branchStatusText = isInitialBranchesLoadPending
@@ -584,10 +593,12 @@ export function BranchToolbarBranchSelector({
maybeFetchNextBranchPage();
}, [refs.length, maybeFetchNextBranchPage]);
- const triggerLabel = getBranchTriggerLabel({
+ const triggerLabel = resolveBranchTriggerLabel({
activeWorktreePath,
effectiveEnvMode,
resolvedActiveBranch,
+ resolvedActiveBranchIsRemote,
+ startFromOrigin,
});
// PR pill shown next to the branch selector when the active branch has one.